X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-service-adaptation%2Fservices%2Fbt-request-handler.c;h=2d7b1ddcfde6a1d1d7c662a64996178180e7bbe9;hb=34389ab8d8f647d553404f074e2e93e62480e1f4;hp=1236e48a8e38694d943c7f0f9995a2ee8265b8aa;hpb=fc276a46cb7ce081a1a6322df3a358b2ab56c0aa;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-service-adaptation/services/bt-request-handler.c b/bt-service-adaptation/services/bt-request-handler.c index 1236e48..2d7b1dd 100644 --- a/bt-service-adaptation/services/bt-request-handler.c +++ b/bt-service-adaptation/services/bt-request-handler.c @@ -248,7 +248,6 @@ void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result, char *sender, int service_function, gpointer invocation_data) { - BT_DBG("Saving the invocation context: service_function [%d]", service_function); invocation_info_t *info; info = g_malloc0(sizeof(invocation_info_t)); info->context = invocation; @@ -260,6 +259,24 @@ void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result, } +static int __bt_service_get_sender_pid(const char *unique_name, pid_t *pid) +{ + int ret; + char err_msg[256] = {0, }; + + retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL); + + ret = cynara_creds_gdbus_get_pid(bt_service_conn, unique_name, pid); + if (ret != CYNARA_API_SUCCESS) { + cynara_strerror(ret, err_msg, sizeof(err_msg)); + BT_ERR("Fail to get user credential: %s", err_msg); + + return BLUETOOTH_ERROR_INTERNAL; + } + + return BLUETOOTH_ERROR_NONE; +} + static int __bt_bm_request_data(_bt_battery_data_t *latest) { int ret = _bt_bm_read_data(latest); @@ -375,8 +392,8 @@ static void __bt_service_method(GDBusConnection *connection, if (request_type == BT_ASYNC_REQ || __bt_is_sync_function(service_function)) { - BT_DBG("Do not send reply to bt-api over dbus," - " Invocation context is already saved in service_function"); + /* Do not send reply to bt-api over dbus, + Invocation context is already saved in service_function */ goto done; } @@ -483,6 +500,9 @@ int __bt_bluez_request(int function_name, dbus_data.session_end_time = data->session_end_time; dbus_data.session_scan_time = data->session_scan_time; dbus_data.session_connected_time = data->session_connected_time; + dbus_data.tx_time = data->tx_time; + dbus_data.rx_time = data->rx_time; + dbus_data.idle_time = data->idle_time; /*Populating app data*/ int n = 0; @@ -493,7 +513,7 @@ int __bt_bluez_request(int function_name, } dbus_data.num_app = n; g_array_append_vals(*out_param1, &dbus_data, sizeof(bt_battery_dbus_data_t)); - g_slist_free(data->atm_list); + g_slist_free_full(data->atm_list, g_free); g_free(data); data = NULL; break; @@ -518,6 +538,7 @@ int __bt_bluez_request(int function_name, unsigned short max_response; unsigned short discovery_duration; unsigned int classOfDeviceMask; + uid_t uid; __bt_service_get_parameters(in_param1, &max_response, sizeof(unsigned short)); @@ -525,8 +546,22 @@ int __bt_bluez_request(int function_name, &discovery_duration, sizeof(unsigned short)); __bt_service_get_parameters(in_param3, &classOfDeviceMask, sizeof(unsigned int)); + __bt_service_get_parameters(in_param4, &uid, sizeof(uid_t)); result = _bt_start_discovery(max_response, discovery_duration, classOfDeviceMask); + + if (result == BLUETOOTH_ERROR_NONE) { + pid_t pid; + + sender = (char*)g_dbus_method_invocation_get_sender(context); + + if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE) + BT_ERR("Fail to get the sender pid"); + + BT_DBG("Remeber pid / uid for the scan operation"); + _bt_bm_add_scan_app(SCAN_REGACY, uid, pid); + } + break; } case BT_START_CUSTOM_DISCOVERY: { @@ -712,7 +747,6 @@ int __bt_bluez_request(int function_name, if (result == BLUETOOTH_ERROR_NONE) { char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE); _bt_convert_addr_type_to_string(addr, address.addr); - BT_DBG("_bt_bond_device scheduled successfully! save invocation context"); sender = (char*)g_dbus_method_invocation_get_sender(context); _bt_save_invocation_context(context, result, sender, function_name, (gpointer)addr); @@ -741,7 +775,6 @@ int __bt_bluez_request(int function_name, if (result == BLUETOOTH_ERROR_NONE) { char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE); _bt_convert_addr_type_to_string(addr, address.addr); - BT_DBG("_bt_bond_device_by_type invoked successfully! save invocation context"); sender = (char*)g_dbus_method_invocation_get_sender(context); _bt_save_invocation_context(context, result, sender, function_name, (gpointer)addr); @@ -767,7 +800,6 @@ int __bt_bluez_request(int function_name, if (result == BLUETOOTH_ERROR_NONE) { char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE); _bt_convert_addr_type_to_string(addr, address.addr); - BT_DBG("_bt_unbond_device scheduled successfully! save invocation context"); sender = (char*)g_dbus_method_invocation_get_sender(context); _bt_save_invocation_context(context, result, sender, function_name, (gpointer)addr); @@ -790,7 +822,6 @@ int __bt_bluez_request(int function_name, if (result == BLUETOOTH_ERROR_NONE) { char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE); _bt_convert_addr_type_to_string(addr, address.addr); - BT_DBG("BT Device Service Search Request scheduled successfully! save invocation context"); sender = (char*)g_dbus_method_invocation_get_sender(context); _bt_save_invocation_context(context, result, sender, function_name, (gpointer)addr); @@ -1419,7 +1450,6 @@ int __bt_bluez_request(int function_name, sizeof(bluetooth_rfcomm_connection_t)); } else { char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE); - BT_ERR("BT_RFCOMM_CLIENT_CONNECT success, save context"); _bt_convert_addr_type_to_string(addr, address.addr); sender = (char*)g_dbus_method_invocation_get_sender(context); _bt_save_invocation_context(context, result, sender, function_name, addr); @@ -1459,8 +1489,6 @@ int __bt_bluez_request(int function_name, result = _bt_rfcomm_socket_listen(sender, uuid, true); if (result > 0) { - BT_ERR("BT_RFCOMM_LISTEN_AND_ACCEPT success, save context"); - result = BLUETOOTH_ERROR_NONE; _bt_save_invocation_context(context, result, sender, function_name, NULL); @@ -1478,8 +1506,6 @@ int __bt_bluez_request(int function_name, result = _bt_rfcomm_socket_listen(sender, uuid, false); if (result > 0) { - BT_ERR("BT_RFCOMM_LISTEN success, save context"); - result = BLUETOOTH_ERROR_NONE; _bt_save_invocation_context(context, result, sender, function_name, NULL); @@ -1516,7 +1542,7 @@ int __bt_bluez_request(int function_name, int size; __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t)); __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t)); - __bt_service_get_parameters(in_param3, &size, sizeof(int)); + __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int)); BT_DBG("Sending details to bluetooth battery monitor: %ld, %ld, %d", (long int)uid, (long int)pid, size); _bt_bm_add_transaction_details(uid, pid, size, RX_DATA); break; @@ -1527,11 +1553,29 @@ int __bt_bluez_request(int function_name, int size; __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t)); __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t)); - __bt_service_get_parameters(in_param3, &size, sizeof(int)); + __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int)); BT_DBG("Sending details to bluetooth battery monitor: %ld, %ld, %d", (long int)uid, (long int)pid, size); _bt_bm_add_transaction_details(uid, pid, size, TX_DATA); break; - } + } + case BT_RFCOMM_UPDATE_CONNECTION_INFO: { + gboolean connected = FALSE; + int socket_fd = -1; + int role = RFCOMM_ROLE_SERVER; + + sender = (char *)g_dbus_method_invocation_get_sender(context); + + __bt_service_get_parameters(in_param1, &role, sizeof(int)); + __bt_service_get_parameters(in_param2, &connected, sizeof(gboolean)); + __bt_service_get_parameters(in_param3, &socket_fd, sizeof(int)); + + if (connected == TRUE) + result = _bt_rfcomm_conn_added(sender, role, socket_fd); + else + result = _bt_rfcomm_conn_removed(sender, role, socket_fd); + + break; + } case BT_AUDIO_SELECT_ROLE: { bluetooth_audio_role_t role; @@ -2329,14 +2373,13 @@ int __bt_bluez_request(int function_name, char *app; app = (char *)g_dbus_method_invocation_get_sender(context); - BT_INFO("GATT Server Unique Name [%s]", app); + BT_DBG("GATT Server Unique Name [%s]", app); /* No ADV handle: Set 0 */ result = _bt_register_server_instance(app, 0); - BT_INFO("GATT Server: Register Server result [%d]", result); if (result != BLUETOOTH_ERROR_NONE) { - BT_ERR("GATT Server registration failed!!"); + BT_ERR("GATT Server registration failed. result %d", result); } else { _bt_save_invocation_context(context, result, app, function_name, NULL); @@ -2369,15 +2412,12 @@ int __bt_bluez_request(int function_name, __bt_service_get_parameters(in_param4, &instance_id, sizeof(int)); - BT_INFO("GATT Server Service UUID [%s]", svc_uuid); result = _bt_gatt_server_add_service(app, service_type, num_handles, svc_uuid, instance_id); if (result != BLUETOOTH_ERROR_NONE) { BT_ERR("GATT Server Add Service failed!!"); } else { tmp_inst_id = g_malloc0(sizeof(int)); *tmp_inst_id = instance_id; - BT_INFO("GATT Server: Save Instance ID in request Inst id [%d] request_id [%d]", - *tmp_inst_id, instance_id); _bt_save_invocation_context(context, result, app, function_name, (gpointer)tmp_inst_id); } @@ -2397,16 +2437,13 @@ int __bt_bluez_request(int function_name, sizeof(bluetooth_gatt_server_attribute_params_t)); char_uuid = (char *)g_variant_get_data(in_param2); - BT_INFO("GATT Server Characteristic UUID [%s]", char_uuid); - result = _bt_gatt_server_add_characteristic(app, char_uuid, ¶m); if (result != BLUETOOTH_ERROR_NONE) { BT_ERR("GATT Server Add Service failed!!"); } else { tmp_inst_id = g_malloc0(sizeof(int)); *tmp_inst_id = param.instance_id; - BT_INFO("GATT Server: Save Instance ID in request Inst id [%d] request_id [%d]", - *tmp_inst_id, param.instance_id); + _bt_save_invocation_context(context, result, app, function_name, (gpointer)tmp_inst_id); } @@ -2432,16 +2469,12 @@ int __bt_bluez_request(int function_name, __bt_service_get_parameters(in_param3, &perm, sizeof(bt_gatt_permission_t)); - BT_INFO("GATT Server Descriptor UUID [%s]", desc_uuid); - result = _bt_gatt_server_add_descriptor(app, desc_uuid, &perm, service_handle, instance_id); if (result != BLUETOOTH_ERROR_NONE) { BT_ERR("GATT Server Add Service failed!!"); } else { tmp_inst_id = g_malloc0(sizeof(int)); *tmp_inst_id = instance_id; - BT_INFO("GATT Server: Save Instance ID in request Inst id [%d] request_id [%d]", - *tmp_inst_id, instance_id); _bt_save_invocation_context(context, result, app, function_name, (gpointer)tmp_inst_id); } @@ -2465,8 +2498,6 @@ int __bt_bluez_request(int function_name, if (BLUETOOTH_ERROR_NONE == result) { tmp_inst_id = g_malloc0(sizeof(int)); *tmp_inst_id = instance_id; - BT_INFO("GATT Server: Save Instance ID in request Inst id [%d] request_id [%d]", - *tmp_inst_id, instance_id); _bt_save_invocation_context(context, result, app, function_name, (gpointer)tmp_inst_id); } @@ -2489,8 +2520,6 @@ int __bt_bluez_request(int function_name, if (BLUETOOTH_ERROR_NONE == result) { tmp_inst_id = g_malloc0(sizeof(int)); *tmp_inst_id = instance_id; - BT_INFO("GATT Server: Save Instance ID in request Inst id [%d] request_id [%d]", - *tmp_inst_id, instance_id); _bt_save_invocation_context(context, result, app, function_name, (gpointer)tmp_inst_id); } @@ -2513,8 +2542,6 @@ int __bt_bluez_request(int function_name, if (BLUETOOTH_ERROR_NONE == result) { tmp_inst_id = g_malloc0(sizeof(int)); *tmp_inst_id = instance_id; - BT_INFO("GATT Server: Save Instance ID in request Inst id [%d] request_id [%d]", - *tmp_inst_id, instance_id); _bt_save_invocation_context(context, result, app, function_name, (gpointer)tmp_inst_id); } @@ -2675,7 +2702,6 @@ int __bt_bluez_request(int function_name, result = _bt_request_att_mtu(&address, mtu); if (BLUETOOTH_ERROR_NONE == result) { addr = g_malloc0(BT_ADDRESS_STRING_SIZE); - BT_INFO("GATT Client: Save Invocation data for BT_REQ_ATT_MTU [%s]", sender); _bt_convert_addr_type_to_string(addr, address.addr); @@ -2729,7 +2755,6 @@ int __bt_bluez_request(int function_name, addr = g_malloc0(BT_ADDRESS_STRING_SIZE); _bt_convert_addr_type_to_string(addr, address.addr); - BT_INFO("GATT Client: Save Invocation data GATT CLient Register app[%s] address [%s]", sender, addr); /* Save the informations to invocation */ _bt_save_invocation_context(context, result, sender, @@ -2841,7 +2866,6 @@ int __bt_bluez_request(int function_name, result = _bt_disconnect_le_device(&address, client_id); if (BLUETOOTH_ERROR_NONE == result) { addr = g_malloc0(BT_ADDRESS_STRING_SIZE); - BT_INFO("GATT Client: Save Invocation data DisConnect LE app[%s]", sender); _bt_convert_addr_type_to_string(addr, address.addr); @@ -2854,6 +2878,46 @@ int __bt_bluez_request(int function_name, } break; } + /* Sync */ + case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS: { + guint available_packets = 0; + + result = _bt_gatt_get_data_batching_available_packets(&available_packets); + BT_DBG("LE batching available packets %u", available_packets); + if (result == BLUETOOTH_ERROR_NONE) { + g_array_append_vals(*out_param1, &available_packets, + sizeof(guint)); + } + + break; + } + /* Sync */ + case BT_ENABLE_GATT_DATA_BATCHING: { + bluetooth_device_address_t address = { {0} }; + int packet_threshold; + int timeout; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + __bt_service_get_parameters(in_param2, + &packet_threshold, sizeof(int)); + __bt_service_get_parameters(in_param3, + &timeout, sizeof(int)); + result = _bt_gatt_enable_data_batching(&address, packet_threshold, timeout); + + break; + } + /* Sync */ + case BT_DISABLE_GATT_DATA_BATCHING: { + bluetooth_device_address_t address = { {0} }; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + result = _bt_gatt_disable_data_batching(&address); + + break; + } + case BT_GATT_GET_PRIMARY_SERVICES: { char *addr; @@ -2868,8 +2932,6 @@ int __bt_bluez_request(int function_name, result = _bt_gatt_get_primary_services(addr); if (BLUETOOTH_ERROR_NONE == result) { - BT_INFO("GATT Client: Save Remote GATT Server address addr [%s] app[%s]", - addr, sender); _bt_save_invocation_context(context, result, sender, function_name, (gpointer)addr); } else @@ -2888,8 +2950,6 @@ int __bt_bluez_request(int function_name, result = _bt_gatt_get_all_characteristic(¶m); if (BLUETOOTH_ERROR_NONE == result) { - BT_INFO("GATT Client: Save Invocation data for Service props app[%s]", sender); - /* Save the informations to invocation */ _bt_save_invocation_context(context, result, sender, function_name, @@ -2908,8 +2968,6 @@ int __bt_bluez_request(int function_name, result = _bt_gatt_get_all_characteristic_properties(¶m); if (BLUETOOTH_ERROR_NONE == result) { - BT_INFO("GATT Client: Save Invocation data for characteristic props app[%s]", sender); - /* Save the informations to invocation */ _bt_save_invocation_context(context, result, sender, function_name, @@ -2929,8 +2987,6 @@ int __bt_bluez_request(int function_name, result = _bt_gatt_read_characteristic_value(¶m); if (BLUETOOTH_ERROR_NONE == result) { - BT_INFO("GATT Client: Save Invocation data for characteristic props app[%s]", sender); - /* Save the informations to invocation */ _bt_save_invocation_context(context, result, sender, function_name, @@ -2950,8 +3006,6 @@ int __bt_bluez_request(int function_name, result = _bt_gatt_read_descriptor_value(¶m); if (BLUETOOTH_ERROR_NONE == result) { - BT_INFO("GATT Client: Save Invocation data for Descriptor's props app[%s]", sender); - /* Save the informations to invocation */ _bt_save_invocation_context(context, result, sender, function_name, @@ -2979,8 +3033,6 @@ int __bt_bluez_request(int function_name, result = _bt_gatt_write_characteristic_value_by_type(¶m , &data, write_type); if (BLUETOOTH_ERROR_NONE == result) { - BT_INFO("GATT Client: Save Invocation data for characteristic props app[%s]", sender); - /* Save the informations to invocation */ _bt_save_invocation_context(context, result, sender, function_name, @@ -3007,8 +3059,6 @@ int __bt_bluez_request(int function_name, result = _bt_gatt_write_descriptor_value_by_type(¶m, &data, write_type); if (BLUETOOTH_ERROR_NONE == result) { - BT_INFO("GATT Client: Save Invocation data for descriptor props app[%s]", sender); - /* Save the informations to invocation */ _bt_save_invocation_context(context, result, sender, function_name, @@ -3046,7 +3096,7 @@ int __bt_bluez_request(int function_name, if (is_indicate == false) { result = _bt_gatt_acquire_notify(¶m , &fd, &mtu); if (BLUETOOTH_ERROR_NONE == result && fd > -1) { - BT_INFO("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd); + BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd); GUnixFDList *fd_list = NULL; GError *error = NULL; @@ -3068,8 +3118,6 @@ int __bt_bluez_request(int function_name, normal: result = _bt_gatt_watch_characteristic(¶m , client_id, is_notify); if (BLUETOOTH_ERROR_NONE == result) { - BT_INFO("GATT Client: Save Invocation data for characteristic props app[%s]", sender); - /* Save the informations to invocation */ _bt_save_invocation_context(context, result, sender, function_name, (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t))); @@ -3114,21 +3162,46 @@ normal: } #endif case BT_START_LE_DISCOVERY: { + uid_t uid = 0; + pid_t pid = 0; + + __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t)); + sender = (char *)g_dbus_method_invocation_get_sender(context); - result = _bt_start_le_scan(sender); + + if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE) + BT_ERR("Fail to get the sender pid"); + + result = _bt_start_le_scan(sender, uid, pid); if (result == BLUETOOTH_ERROR_NONE) { _bt_save_invocation_context(context, result, sender, function_name, NULL); + + BT_DBG("Remeber pid / uid for the scan operation"); + _bt_bm_add_scan_app(SCAN_LE, uid, pid); } break; } case BT_STOP_LE_DISCOVERY: { + uid_t uid = 0; + pid_t pid = 0; + + __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t)); + sender = (char *)g_dbus_method_invocation_get_sender(context); + + if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE) + BT_ERR("Fail to get the sender pid"); + result = _bt_stop_le_scan(sender); if (result == BLUETOOTH_ERROR_NONE) { _bt_save_invocation_context(context, result, sender, function_name, NULL); } + + BT_DBG("Remove pid / uid for the scan operation"); + _bt_bm_remove_scan_app(SCAN_LE, uid, pid); + break; } case BT_IS_LE_DISCOVERYING: { @@ -3735,13 +3808,15 @@ int __bt_agent_request(int function_name, char *uuid; char *path; int fd; + char *sender; + sender = (char *)g_dbus_method_invocation_get_sender(context); __bt_service_get_parameters(in_param1, &type, sizeof(int)); uuid = (char *)g_variant_get_data(in_param2); path = (char *)g_variant_get_data(in_param3); __bt_service_get_parameters(in_param4, &fd, sizeof(int)); - result = _bt_register_osp_server_in_agent(type, uuid, path, fd); + result = _bt_register_osp_server_in_agent(sender, type, uuid, path, fd); break; } case BT_UNSET_AUTHORIZATION: { @@ -3935,6 +4010,9 @@ gboolean __bt_service_check_privilege(int function_name, case BT_RFCOMM_SOCKET_WRITE: case BT_RFCOMM_CREATE_SOCKET: case BT_RFCOMM_REMOVE_SOCKET: + case BT_RFCOMM_SEND_RX_DETAILS: + case BT_RFCOMM_SEND_TX_DETAILS: + case BT_RFCOMM_UPDATE_CONNECTION_INFO: case BT_OPP_PUSH_FILES: case BT_OPP_CANCEL_PUSH: @@ -4114,8 +4192,6 @@ gboolean __bt_service_check_privilege(int function_name, } break; - case BT_RFCOMM_SEND_RX_DETAILS: - case BT_RFCOMM_SEND_TX_DETAILS: case BT_ENABLE_ADAPTER: case BT_DISABLE_ADAPTER: case BT_RESET_ADAPTER: @@ -4159,6 +4235,10 @@ gboolean __bt_service_check_privilege(int function_name, case BT_LE_OOB_READ_LOCAL_DATA: case BT_LE_OOB_ADD_REMOTE_DATA: + case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS: + case BT_ENABLE_GATT_DATA_BATCHING: + case BT_DISABLE_GATT_DATA_BATCHING: + case BT_LE_IPSP_INIT: case BT_LE_IPSP_DEINIT: case BT_LE_IPSP_CONNECT: @@ -4338,6 +4418,9 @@ static void __name_owner_changed(GDBusConnection *connection, /* Check if le_scanning app is terminated */ _bt_check_le_scanner_app_termination(name); + + /* Check if RFCOMM app is terminated */ + _bt_rfcomm_check_termination(name); } static void __bt_service_bus_acquired_handler(GDBusConnection *connection,