Apply tizen 3.0 based product patchsets
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-request-handler.c
index 08cb882..38ec417 100644 (file)
@@ -46,6 +46,7 @@
 #include "bt-service-agent.h"
 #include "bt-service-proximity.h"
 #include "bt-service-tds.h"
+#include "bt-service-otp.h"
 
 static GDBusConnection *bt_service_conn;
 static guint owner_id = 0;
@@ -72,7 +73,7 @@ static const gchar bt_service_introspection_xml[] =
 "      </interface>"
 "</node>";
 
-GDBusNodeInfo *node_info = NULL;
+static gboolean name_acquired = FALSE;
 
 static char *current_sender_playing = NULL;
 
@@ -714,15 +715,19 @@ int __bt_bluez_request(int function_name,
                break;
        }
        case BT_LE_CONN_UPDATE: {
+               char *sender = NULL;
                bluetooth_device_address_t local_address = { {0} };
                bluetooth_le_connection_param_t parameters = {0};
 
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
+
                __bt_service_get_parameters(in_param1, &local_address,
                                sizeof(bluetooth_device_address_t));
                __bt_service_get_parameters(in_param2, &parameters,
                                sizeof(bluetooth_le_connection_param_t));
 
-               result =  _bt_le_conn_update(local_address.addr,
+               result =  _bt_le_conn_update(sender,
+                                       local_address.addr,
                                        parameters.interval_min,
                                        parameters.interval_max,
                                        parameters.latency,
@@ -967,6 +972,7 @@ int __bt_bluez_request(int function_name,
                break;
        }
        case BT_UPDATE_LE_CONNECTION_MODE: {
+               char *sender = NULL;
                bluetooth_device_address_t remote_address = { { 0 } };
                bluetooth_le_connection_param_t param = { 0 };
                bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED;
@@ -980,7 +986,10 @@ int __bt_bluez_request(int function_name,
                if (result != BLUETOOTH_ERROR_NONE)
                        break;
 
-               result = _bt_le_conn_update(remote_address.addr,
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
+
+               result = _bt_le_conn_update(sender,
+                               remote_address.addr,
                                param.interval_min,
                                param.interval_max,
                                param.latency,
@@ -1297,14 +1306,17 @@ int __bt_bluez_request(int function_name,
        }
        case BT_OOB_ADD_REMOTE_DATA: {
                bluetooth_device_address_t address = { {0} };
+               unsigned short address_type;
                bt_oob_data_t remote_oob_data;
 
                __bt_service_get_parameters(in_param1,
                                &address, sizeof(bluetooth_device_address_t));
                __bt_service_get_parameters(in_param2,
+                               &address_type, sizeof(unsigned short));
+               __bt_service_get_parameters(in_param3,
                                &remote_oob_data, sizeof(bt_oob_data_t));
 
-               result = _bt_oob_add_remote_data(&address, &remote_oob_data);
+               result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
 
                break;
        }
@@ -1418,6 +1430,19 @@ int __bt_bluez_request(int function_name,
 
                break;
        }
+       case BT_AVRCP_TRANSPORT_SET_PROPERTY: {
+               int type;
+               unsigned int value;
+
+               __bt_service_get_parameters(in_param1,
+                               &type, sizeof(int));
+               __bt_service_get_parameters(in_param2,
+                               &value, sizeof(unsigned int));
+
+               result = _bt_avrcp_transport_set_property(type, value);
+
+               break;
+       }
        case BT_AVRCP_GET_TRACK_INFO: {
                media_metadata_t meta_data;
                media_metadata_attributes_t metadata;
@@ -2345,6 +2370,114 @@ int __bt_bluez_request(int function_name,
                        g_free(handle);
                break;
        }
+       case BT_OTP_SERVER_INIT: {
+               const char *directory;
+               directory = (const char *)g_variant_get_data(in_param1);
+               result = bt_otp_server_init(request_id, directory);
+               break;
+       }
+       case BT_OTP_SERVER_DEINIT: {
+               result = bt_otp_server_deinit(request_id);
+               break;
+       }
+       case BT_OTP_READ_VALUE: {
+               char *handle;
+               char *data = NULL;
+               guint data_len = 0;
+
+               char *sender = NULL;
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
+
+               data_len = g_variant_get_size(in_param1);
+               data = (char *)g_variant_get_data(in_param1);
+
+               handle = g_strndup(data, data_len);
+               BT_DBG("Read OTP Characteristic Value [%s]", handle);
+
+               result = _bt_otp_read_characteristic_value(request_id, sender, handle);
+
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("Reading OTP Characteristic Value failed result [%d]", result);
+                       g_array_append_vals(*out_param1, handle, data_len);
+               }
+               if (handle)
+                       g_free(handle);
+               break;
+       }
+       case BT_OTP_ENABLE_NOTIFICATION: {
+               char *handle;
+               char *data = NULL;
+               guint data_len = 0;
+
+               char *sender = NULL;
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
+
+               data_len = g_variant_get_size(in_param1);
+               data = (char *)g_variant_get_data(in_param1);
+
+               handle = g_strndup(data, data_len);
+               BT_DBG("OTP Control point CCCD handle [%s]", handle);
+
+               result = _bt_otp_enable_notification(request_id, sender, handle);
+
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("Enabling OTP CCCD failed result [%d]", result);
+                       g_array_append_vals(*out_param1, handle, data_len);
+               }
+               if (handle)
+                       g_free(handle);
+               break;
+       }
+       case BT_OTP_WRITE_VALUE: {
+               char *handle;
+               char *data = NULL;
+               guint data_len = 0;
+               char *sender = NULL;
+               bluetooth_otp_charc_data_t otp_charc_data;
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
+
+               data_len = g_variant_get_size(in_param1);
+               data = (char *)g_variant_get_data(in_param1);
+
+               handle = g_strndup(data, data_len);
+               BT_DBG("OTP Write Characteristic value [%s]", handle);
+
+               __bt_service_get_parameters(in_param2,
+                       &otp_charc_data, sizeof(bluetooth_otp_charc_data_t));
+
+               int i;
+               for (i = 0; i < otp_charc_data.length; i++)
+                       BT_DBG("Value[%d] = %u", i, otp_charc_data.data[i]);
+
+               result = _bt_otp_write_characteristic_value(request_id, sender, handle,
+                                                               otp_charc_data.data, otp_charc_data.length);
+
+               if (result != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("OTP Write Characteristic failed result [%d]", result);
+                       g_array_append_vals(*out_param1, handle, data_len);
+               }
+               if (handle)
+                       g_free(handle);
+               break;
+       }
+       case BT_LE_OTC_CONNECT: {
+               BT_DBG("OTC Connect");
+               bluetooth_device_address_t address = { {0} };
+               __bt_service_get_parameters(in_param1, &address,
+                               sizeof(bluetooth_device_address_t));
+
+               result = _bt_otp_connect_otc(request_id, &address);
+               break;
+       }
+       case BT_LE_OTC_DISCONNECT: {
+               BT_DBG("OTC Disconnect");
+               bluetooth_device_address_t address = { {0} };
+
+               __bt_service_get_parameters(in_param1, &address,
+                                               sizeof(bluetooth_device_address_t));
+               result = _bt_otp_disconnect_otc(&address);
+               break;
+       }
        default:
                result = BLUETOOTH_ERROR_INTERNAL;
                break;
@@ -3149,6 +3282,8 @@ gboolean __bt_service_check_privilege(int function_name,
 
        case BT_AVRCP_CONTROL_GET_PROPERTY:
        case BT_AVRCP_GET_TRACK_INFO:
+       case BT_AVRCP_TRANSPORT_SET_PROPERTY:
+
 
        case BT_SET_CONTENT_PROTECT:
        case BT_BOND_DEVICE_BY_TYPE:
@@ -3188,6 +3323,15 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_TDS_ENABLE_CONTROL_POINT:
        case BT_TDS_ACTIVATE_CONTROL_POINT:
 
+       /* OTP Server */
+       case BT_OTP_SERVER_INIT:
+       case BT_OTP_SERVER_DEINIT:
+       case BT_OTP_READ_VALUE:
+       case BT_OTP_ENABLE_NOTIFICATION:
+       case BT_OTP_WRITE_VALUE:
+       case BT_LE_OTC_CONNECT:
+       case BT_LE_OTC_DISCONNECT:
+
        case BT_MAP_CREATE_SESSION:
        case BT_MAP_DESTROY_SESSION:
        case BT_MAP_SET_FOLDER:
@@ -3310,39 +3454,64 @@ int __bt_service_register_object(GDBusConnection *conn,
        return 0;
 }
 
+static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
+               const gchar *name, gpointer user_data)
+{
+       GDBusNodeInfo *node_info = NULL;
+
+       BT_INFO("bus acquired");
+
+       ret_if(connection == NULL);
+
+       node_info = __bt_service_create_method_node_info(
+                       bt_service_introspection_xml);
+       ret_if(node_info == NULL);
+
+       __bt_service_register_object(connection, node_info, TRUE);
+       g_dbus_node_info_unref(node_info);
+
+       bt_service_conn = connection;
+}
+
+static void __bt_service_name_acquired_handler(GDBusConnection *connection,
+               const gchar *name, gpointer user_data)
+{
+       BT_INFO("name acquired");
+       name_acquired = TRUE;
+}
+
+static void __bt_service_name_lost_handler(GDBusConnection *connection,
+               const gchar *name, gpointer user_data)
+{
+       BT_INFO("name lost");
+       name_acquired = FALSE;
+}
+
+gboolean _is_name_acquired(void)
+{
+       return name_acquired;
+}
+
 int _bt_service_register(void)
 {
        GDBusConnection *conn;
        GError *err = NULL;
-       int result;
 
        conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+       bt_service_conn = conn;
 
        owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
                                BT_SERVICE_NAME,
                                G_BUS_NAME_OWNER_FLAGS_NONE,
-                               NULL, NULL, NULL,
+                               __bt_service_bus_acquired_handler,
+                               __bt_service_name_acquired_handler,
+                               __bt_service_name_lost_handler,
                                NULL, NULL);
        BT_DBG("owner_id is [%d]", owner_id);
        if (owner_id == 0)
                goto fail;
 
-       node_info = __bt_service_create_method_node_info(
-                       bt_service_introspection_xml);
-
-       if (node_info == NULL)
-               goto fail;
-
-       result = __bt_service_register_object(conn, node_info, TRUE);
-       g_dbus_node_info_unref(node_info);
-       node_info = NULL;
-
-       if (result != BLUETOOTH_ERROR_NONE)
-               goto fail;
-
-       bt_service_conn = conn;
-
        return BLUETOOTH_ERROR_NONE;
 
 fail:
@@ -3362,10 +3531,6 @@ void _bt_service_unregister(void)
                        g_object_unref(bt_service_conn);
                        bt_service_conn = NULL;
                }
-               if (node_info) {
-                       g_dbus_node_info_unref(node_info);
-                       node_info = NULL;
-               }
                if (owner_id > 0) {
                        g_bus_unown_name(owner_id);
                        owner_id = 0;