[GATT Client] Delivery ATT error code to higher layer
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-gatt-service.c
index a9b670f..e483da5 100644 (file)
@@ -1,10 +1,5 @@
 /*
- * Bluetooth-frwk low energy
- *
- * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hocheol Seo <hocheol.seo@samsung.com>
- *                 Chanyeol Park <chanyeol.park@samsung.com>
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include<stdlib.h>
 #include<unistd.h>
 #include<stdint.h>
+#include<stdbool.h>
 
 #include "bt-common.h"
+#include "bt-internal-types.h"
 
 #define NUMBER_OF_FLAGS        10
 
@@ -37,15 +34,23 @@ guint manager_id;
 static gboolean new_service = FALSE;
 static gboolean new_char = FALSE;
 static int serv_id = 1;
+static int register_pending_cnt = 0;
+static bool is_server_started = false;
 
 /* Introspection data for the service we are exporting */
 static const gchar service_introspection_xml[] =
 "<node name='/'>"
-"  <interface name='org.bluez.GattService1'>"
+"  <interface name='org.freedesktop.DBus.Properties'>"
 "    <property type='s' name='UUID' access='read'>"
 "    </property>"
-"    <property type='s' name='Includes' access='read'>"
-"    </property>"
+"       <property type='b' name='primary' access='read'>"
+"       </property>"
+"       <property type='o' name='Device' access='read'>"
+"       </property>"
+"       <property type='ao' name='Characteristics' access='read'>"
+"       </property>"
+"       <property type='s' name='Includes' access='read'>"
+"       </property>"
 "  </interface>"
 "</node>";
 
@@ -53,14 +58,43 @@ static const gchar service_introspection_xml[] =
 static const gchar characteristics_introspection_xml[] =
 "<node name='/'>"
 "  <interface name='org.bluez.GattCharacteristic1'>"
+"       <method name='ReadValue'>"
+"              <arg type='s' name='address' direction='in'/>"
+"              <arg type='u' name='id' direction='in'/>"
+"              <arg type='q' name='offset' direction='in'/>"
+"              <arg type='ay' name='Value' direction='out'/>"
+"       </method>"
+"       <method name='WriteValue'>"
+"              <arg type='s' name='address' direction='in'/>"
+"              <arg type='u' name='id' direction='in'/>"
+"              <arg type='q' name='offset' direction='in'/>"
+"              <arg type='b' name='response_needed' direction='in'/>"
+"              <arg type='ay' name='value' direction='in'/>"
+"       </method>"
+"       <method name='StartNotify'>"
+"       </method>"
+"       <method name='StopNotify'>"
+"       </method>"
+"       <method name='IndicateConfirm'>"
+"              <arg type='s' name='address' direction='in'/>"
+"              <arg type='b' name='complete' direction='in'/>"
+"       </method>"
+"  </interface>"
+"  <interface name='org.freedesktop.DBus.Properties'>"
 "    <property type='s' name='UUID' access='read'>"
 "    </property>"
 "    <property type='o' name='Service' access='read'>"
 "    </property>"
 "    <property type='ay' name='Value' access='readwrite'>"
 "    </property>"
+"       <property type='b' name='Notifying' access='read'>"
+"       </property>"
 "    <property type='as' name='Flags' access='read'>"
 "    </property>"
+"    <property type='s' name='Unicast' access='read'>"
+"    </property>"
+"       <property type='ao' name='Descriptors' access='read'>"
+"       </property>"
 "  </interface>"
 "</node>";
 
@@ -68,13 +102,28 @@ static const gchar characteristics_introspection_xml[] =
 static const gchar descriptor_introspection_xml[] =
 "<node name='/'>"
 "  <interface name='org.bluez.GattDescriptor1'>"
+"       <method name='ReadValue'>"
+"              <arg type='s' name='address' direction='in'/>"
+"              <arg type='u' name='id' direction='in'/>"
+"              <arg type='q' name='offset' direction='in'/>"
+"              <arg type='ay' name='Value' direction='out'/>"
+"       </method>"
+"       <method name='WriteValue'>"
+"              <arg type='s' name='address' direction='in'/>"
+"              <arg type='u' name='id' direction='in'/>"
+"              <arg type='q' name='offset' direction='in'/>"
+"              <arg type='b' name='response_needed' direction='in'/>"
+"              <arg type='ay' name='value' direction='in'/>"
+"       </method>"
+"  </interface>"
+"  <interface name='org.freedesktop.DBus.Properties'>"
 "    <property type='s' name='UUID' access='read'>"
 "    </property>"
 "    <property type='o' name='Characteristic' access='read'>"
 "    </property>"
-"    <property type='ay' name='Value' access='readwrite'>"
+"    <property type='ay' name='Value' access='read'>"
 "    </property>"
-"    <property type='s' name='Permissions' access='read'>"
+"    <property type='as' name='Flags' access='read'>"
 "    </property>"
 "  </interface>"
 "</node>";
@@ -88,17 +137,6 @@ static const gchar manager_introspection_xml[] =
 "  </interface>"
 "</node>";
 
-static const gchar properties_introspection_xml[] =
-"<node name='/'>"
-"  <interface name='org.freedesktop.DBus.Properties'>"
-"       <method name='Set'>"
-"              <arg type='s' name='interface' direction='in'/>"
-"              <arg type='s' name='name' direction='in'/>"
-"              <arg type='v' name='value' direction='in'/>"
-"       </method>"
-"  </interface>"
-"</node>";
-
 struct gatt_service_info {
        gchar *serv_path;
        guint serv_id;
@@ -107,6 +145,7 @@ struct gatt_service_info {
        guint prop_id;
        GSList *char_data;
        gboolean is_svc_registered;
+       gboolean is_svc_primary;
 };
 
 struct gatt_char_info {
@@ -125,10 +164,22 @@ struct gatt_desc_info {
        guint desc_id;
        gchar *desc_uuid;
        gchar *desc_value;
+       gchar *desc_flags[NUMBER_OF_FLAGS];
        int value_length;
+       int flags_length;
+};
+
+struct gatt_req_info {
+       gchar *attr_path;
+       gchar *svc_path;
+       guint  request_id;
+       guint  offset;
+       GDBusMethodInvocation *context;
 };
 
 static GSList *gatt_services = NULL;
+static GSList *gatt_requests = NULL;
+static gchar *app_path = NULL;
 
 #define BT_GATT_SERVICE_NAME   "org.frwk.gatt_service"
 #define BT_GATT_SERVICE_PATH "/org/frwk/gatt_service"
@@ -140,8 +191,184 @@ static GSList *gatt_services = NULL;
 #define GATT_CHAR_INTERFACE            "org.bluez.GattCharacteristic1"
 #define GATT_DESC_INTERFACE            "org.bluez.GattDescriptor1"
 
+#ifdef TIZEN_FEATURE_BT_HPS
+#define BT_HPS_OBJECT_PATH "/org/projectx/httpproxy"
+#define BT_HPS_INTERFACE_NAME "org.projectx.httpproxy_service"
+#define PROPERTIES_CHANGED "PropertiesChanged"
+#define BT_HPS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
+#endif
+
+#ifdef TIZEN_FEATURE_BT_OTP
+#define BT_OTP_OBJECT_PATH             "/org/projectx/otp"
+#define BT_OTP_INTERFACE_NAME          "org.projectx.otp_service"
+#define PROPERTIES_CHANGED             "PropertiesChanged"
+#define BT_OTP_PROPERTIES_INTERFACE    "org.freedesktop.DBus.Properties"
+#endif
+
 static GDBusProxy *manager_gproxy = NULL;
 
+static struct gatt_char_info *__bt_gatt_find_gatt_char_info(
+                       const char *service_path, const char *char_path);
+static struct gatt_desc_info *__bt_gatt_find_gatt_desc_info(
+                       const char *serv_path, const char *char_path,
+                       const char *desc_path);
+
+static struct gatt_req_info *__bt_gatt_find_request_info(guint request_id);
+
+static void __bt_gatt_close_gdbus_connection(void)
+{
+       GError *err = NULL;
+
+       BT_DBG("+");
+
+       ret_if(g_conn == NULL);
+
+       if (!g_dbus_connection_flush_sync(g_conn, NULL, &err)) {
+               BT_ERR("Fail to flush the connection: %s", err->message);
+               g_error_free(err);
+               err = NULL;
+       }
+
+       if (!g_dbus_connection_close_sync(g_conn, NULL, &err)) {
+               if (err) {
+                       BT_ERR("Fail to close the dbus connection: %s", err->message);
+                       g_error_free(err);
+               }
+       }
+
+       g_object_unref(g_conn);
+
+       g_conn = NULL;
+
+       BT_DBG("-");
+}
+
+#ifdef TIZEN_FEATURE_BT_HPS
+static int __bt_send_event_to_hps(int event, GVariant *var)
+{
+       GError *error = NULL;
+       GVariant *parameters;
+       GDBusMessage *msg = NULL;
+
+       BT_DBG(" ");
+
+       retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       if (event == BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED) {
+               GVariantBuilder *inner_builder;
+               GVariantBuilder *invalidated_builder;
+
+               BT_DBG("BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED");
+               inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+               g_variant_builder_add(inner_builder, "{sv}", "WriteValue", var);
+
+               invalidated_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+
+               parameters = g_variant_new("(a{sv}as)", inner_builder, invalidated_builder);
+               g_variant_builder_unref(invalidated_builder);
+               g_variant_builder_unref(inner_builder);
+       } else if (BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED) {
+               GVariantBuilder *inner_builder;
+               GVariantBuilder *invalidated_builder;
+
+               BT_DBG("BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED");
+               inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+               g_variant_builder_add(inner_builder, "{sv}", "ReadValue", var);
+
+               invalidated_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+
+               parameters = g_variant_new("(a{sv}as)", inner_builder, invalidated_builder);
+               g_variant_builder_unref(invalidated_builder);
+               g_variant_builder_unref(inner_builder);
+       }
+
+       msg = g_dbus_message_new_signal(BT_HPS_OBJECT_PATH, BT_HPS_INTERFACE_NAME, PROPERTIES_CHANGED);
+       g_dbus_message_set_body(msg, parameters);
+       if (!g_dbus_connection_send_message(g_conn, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 0, NULL)) {
+               if (error != NULL) {
+                       BT_ERR("D-Bus API failure: errCode[%x], \
+                                       message[%s]",
+                                       error->code, error->message);
+                       g_clear_error(&error);
+               }
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+       return BLUETOOTH_ERROR_NONE;
+}
+#endif
+
+#ifdef TIZEN_FEATURE_BT_OTP
+static int __bt_send_event_to_otp(int event, GVariant *var)
+{
+       GError *error = NULL;
+       GVariant *parameters = NULL;
+       GDBusMessage *msg = NULL;
+
+       BT_DBG(" ");
+
+       retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       if (event == BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED) {
+               GVariantBuilder *inner_builder;
+               GVariantBuilder *invalidated_builder;
+
+               BT_DBG("BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED");
+               inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+               g_variant_builder_add(inner_builder, "{sv}", "WriteValue", var);
+
+               invalidated_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+
+               parameters = g_variant_new("(a{sv}as)", inner_builder, invalidated_builder);
+               g_variant_builder_unref(invalidated_builder);
+               g_variant_builder_unref(inner_builder);
+       } else if (event == BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED) {
+               GVariantBuilder *inner_builder;
+               GVariantBuilder *invalidated_builder;
+
+               BT_DBG("BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED");
+               inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+               g_variant_builder_add(inner_builder, "{sv}", "ReadValue", var);
+
+               invalidated_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+
+               parameters = g_variant_new("(a{sv}as)", inner_builder, invalidated_builder);
+               g_variant_builder_unref(invalidated_builder);
+               g_variant_builder_unref(inner_builder);
+       } else if (event == BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED) {
+               GVariantBuilder *inner_builder;
+               GVariantBuilder *invalidated_builder;
+
+               BT_DBG("BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED");
+               inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+               g_variant_builder_add(inner_builder, "{sv}", "NotificationStateChanged", var);
+
+               invalidated_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+
+               parameters = g_variant_new("(a{sv}as)", inner_builder, invalidated_builder);
+               g_variant_builder_unref(invalidated_builder);
+               g_variant_builder_unref(inner_builder);
+       }
+
+       msg = g_dbus_message_new_signal(BT_OTP_OBJECT_PATH, BT_OTP_INTERFACE_NAME, PROPERTIES_CHANGED);
+       g_dbus_message_set_body(msg, parameters);
+       if (!g_dbus_connection_send_message(g_conn, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 0, NULL)) {
+               if (error != NULL) {
+                       BT_ERR("D-Bus API failure: errCode[%x], \
+                                       message[%s]",
+                                       error->code, error->message);
+                       g_clear_error(&error);
+               }
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+       return BLUETOOTH_ERROR_NONE;
+}
+#endif
+
 static void __bt_gatt_manager_method_call(GDBusConnection *connection,
                                        const gchar *sender,
                                        const gchar *object_path,
@@ -151,189 +378,276 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
                                        GDBusMethodInvocation *invocation,
                                        gpointer user_data)
 {
-       if (g_strcmp0(method_name, "GetManagedObjects") == 0) {
+       GSList *l1 = NULL;
+       int len = 0;
+       int i = 0;
 
+       if (g_strcmp0(method_name, "GetManagedObjects") == 0) {
                BT_DBG("Getting values for service, chars and descriptors");
+
                GVariantBuilder *builder;
+               GVariantBuilder *inner_builder1 = NULL;
+               GVariant *svc_char = NULL;
+               GSList *l4;
                /*Main Builder */
                builder = g_variant_builder_new(
                                G_VARIANT_TYPE("a{oa{sa{sv}}}"));
 
                /* Prepare inner builder for GattService1 interface */
 
-               GVariantBuilder *svc_builder = NULL;
-               GVariantBuilder *inner_builder = NULL;
+               len = g_slist_length(gatt_services);
 
-               GSList *l1 = g_slist_last(gatt_services);
-               struct gatt_service_info *serv_info = l1->data;
-               if (serv_info == NULL) {
-                       BT_ERR("service info value is NULL");
-                       g_dbus_method_invocation_return_value(invocation, NULL);
-                       return;
-               }
-
-               /* Prepare inner builder for GattService1 interface */
-               BT_DBG("Creating builder for service");
-               svc_builder = g_variant_builder_new(
-                                       G_VARIANT_TYPE("a{sa{sv}}"));
-               inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
-
-               g_variant_builder_add(inner_builder, "{sv}", "UUID",
-                               g_variant_new_string(serv_info->service_uuid));
-
-               g_variant_builder_add(svc_builder, "{sa{sv}}",
-                                                       GATT_SERV_INTERFACE,
-                                                       inner_builder);
-
-               g_variant_builder_add(builder, "{oa{sa{sv}}}",
-                                                       serv_info->serv_path,
-                                                       svc_builder);
-
-               /* Prepare inner builder for GattCharacteristic1 interface */
-
-               GSList *l2 = serv_info->char_data;
-               BT_DBG("Creating builder for characteristics \n");
+               for (i = 0; i <= len; i++) {
+                       GVariantBuilder *svc_builder = NULL;
+                       GVariantBuilder *inner_builder = NULL;
 
-               if (l2 == NULL)
-                       BT_DBG("characteristic data is NULL");
+                       if (register_pending_cnt > 1)
+                               l1 = g_slist_nth(gatt_services, len - register_pending_cnt);
+                       else
+                               l1 = g_slist_last(gatt_services);
 
-               for (l2 = serv_info->char_data; l2 != NULL; l2 = l2->next) {
+                       register_pending_cnt--;
 
-                       GVariantBuilder *char_builder = NULL;
-                       GVariantBuilder *inner_builder = NULL;
-                       GVariantBuilder *builder1 = NULL;
-                       GVariantBuilder *builder2 = NULL;
-                       GVariant *char_val = NULL;
-                       GVariant *flags_val = NULL;
-                       int i = 0;
-
-                       char_builder = g_variant_builder_new(
-                                                       G_VARIANT_TYPE(
-                                                               "a{sa{sv}}"));
-                       inner_builder = g_variant_builder_new(
-                                                       G_VARIANT_TYPE(
-                                                               "a{sv}"));
+                       if (l1 == NULL) {
+                               BT_ERR("gatt service list is NULL");
+                               g_dbus_method_invocation_return_value(invocation, NULL);
+                               return;
+                       }
 
-                       struct gatt_char_info *char_info = l2->data;
-                       if (char_info == NULL) {
-                               BT_ERR("char_info is NULL");
-                               continue;
+                       struct gatt_service_info *serv_info = l1->data;
+                       if (serv_info == NULL) {
+                               BT_ERR("service info value is NULL");
+                               g_dbus_method_invocation_return_value(invocation, NULL);
+                               return;
                        }
 
-                       /*Uuid*/
+                       /* Prepare inner builder for GattService1 interface */
+                       BT_DBG("Creating builder for service");
+                       svc_builder = g_variant_builder_new(
+                                               G_VARIANT_TYPE("a{sa{sv}}"));
+                       inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
                        g_variant_builder_add(inner_builder, "{sv}", "UUID",
-                               g_variant_new_string(char_info->char_uuid));
-                       /*Service*/
-                       g_variant_builder_add(inner_builder, "{sv}", "Service",
-                               g_variant_new("o", serv_info->serv_path));
-                       /*Value*/
-                       builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
-
-                       if(char_info->char_value != NULL) {
-                               for (i = 0; i < char_info->value_length; i++) {
-                                       g_variant_builder_add(builder1, "y",
-                                               char_info->char_value[i]);
-                               }
-                               char_val = g_variant_new("ay", builder1);
-                               g_variant_builder_add(inner_builder, "{sv}",
-                                               "Value", char_val);
+                                       g_variant_new_string(serv_info->service_uuid));
+
+                       g_variant_builder_add(inner_builder, "{sv}", "Primary",
+                                       g_variant_new_boolean(serv_info->is_svc_primary));
+
+                       /*Characteristics*/
+                       inner_builder1 = g_variant_builder_new(G_VARIANT_TYPE("ao"));
+                       BT_DBG("Adding Charatarisitcs list");
+                       for (l4 = serv_info->char_data; l4 != NULL; l4 = l4->next) {
+                               struct gatt_char_info *char_info = l4->data;
+                                       g_variant_builder_add(inner_builder1, "o",
+                                               char_info->char_path);
+                                       BT_DBG("%s", char_info->char_path);
                        }
-                       /*Flags*/
-                       builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
 
-                       for (i = 0; i < char_info->flags_length; i++) {
-                               g_variant_builder_add(builder2, "s",
-                                       char_info->char_flags[i]);
-                       }
+                       svc_char = g_variant_new("ao", inner_builder1);
+                       g_variant_builder_add(inner_builder, "{sv}", "Characteristics",
+                                               svc_char);
 
-                       flags_val = g_variant_new("as", builder2);
-                       g_variant_builder_add(inner_builder, "{sv}", "Flags",
-                                               flags_val);
+                       g_variant_builder_add(svc_builder, "{sa{sv}}",
+                                                               GATT_SERV_INTERFACE,
+                                                               inner_builder);
 
-                       g_variant_builder_add(char_builder, "{sa{sv}}",
-                                       GATT_CHAR_INTERFACE , inner_builder);
                        g_variant_builder_add(builder, "{oa{sa{sv}}}",
-                                       char_info->char_path, char_builder);
+                                                               serv_info->serv_path,
+                                                               svc_builder);
 
-                       /*Prepare inner builder for GattDescriptor1 interface*/
+                       g_variant_builder_unref(inner_builder1);
 
-                       GSList *l3 = char_info->desc_data;
+                       /* Prepare inner builder for GattCharacteristic1 interface */
 
-                       if (l3 == NULL)
-                               BT_DBG("descriptor data is NULL");
+                       GSList *l2 = serv_info->char_data;
+                       BT_DBG("Creating builder for characteristics \n");
 
-                       for (l3 = char_info->desc_data; l3 != NULL; l3 = l3->next) {
+                       if (l2 == NULL)
+                               BT_DBG("characteristic data is NULL");
 
-                               BT_DBG("Creating builder for descriptor \n");
+                       for (l2 = serv_info->char_data; l2 != NULL; l2 = l2->next) {
 
-                               GVariantBuilder *desc_builder = NULL;
+                               GVariantBuilder *char_builder = NULL;
                                GVariantBuilder *inner_builder = NULL;
                                GVariantBuilder *builder1 = NULL;
-                               GVariant *desc_val = NULL;
-
-                               desc_builder = g_variant_builder_new(
-                                                       G_VARIANT_TYPE(
-                                                       "a{sa{sv}}"));
+                               GVariantBuilder *builder2 = NULL;
+                               GVariantBuilder *builder3 = NULL;
+                               GVariant *char_val = NULL;
+                               GVariant *flags_val = NULL;
+                               GVariant *char_desc = NULL;
+                               char *unicast = NULL;
+                               gboolean notify = FALSE;
+                               int i = 0;
+
+                               char_builder = g_variant_builder_new(
+                                                               G_VARIANT_TYPE(
+                                                                       "a{sa{sv}}"));
                                inner_builder = g_variant_builder_new(
-                                                       G_VARIANT_TYPE(
-                                                       "a{sv}"));
+                                                               G_VARIANT_TYPE(
+                                                                       "a{sv}"));
 
-                               struct gatt_desc_info *desc_info = l3->data;
-                               if (desc_info == NULL) {
-                                       BT_ERR("desc_info is NULL");
+                               struct gatt_char_info *char_info = l2->data;
+                               if (char_info == NULL) {
+                                       BT_ERR("char_info is NULL");
                                        continue;
                                }
 
                                /*Uuid*/
-                               g_variant_builder_add(inner_builder,
-                                       "{sv}", "UUID",
-                                       g_variant_new_string(
-                                               desc_info->desc_uuid));
-
-                               /*Characteristic*/
-                               g_variant_builder_add(inner_builder, "{sv}",
-                                       "Characteristic",
-                                       g_variant_new("o",
-                                               char_info->char_path));
-
+                               g_variant_builder_add(inner_builder, "{sv}", "UUID",
+                                       g_variant_new_string(char_info->char_uuid));
+                               /*Service*/
+                               g_variant_builder_add(inner_builder, "{sv}", "Service",
+                                       g_variant_new("o", serv_info->serv_path));
                                /*Value*/
                                builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
 
-                               if(desc_info->desc_value != NULL) {
-                                       for (i = 0; i < desc_info->value_length; i++) {
+                               if (char_info->char_value != NULL) {
+                                       for (i = 0; i < char_info->value_length; i++) {
                                                g_variant_builder_add(builder1, "y",
-                                                       desc_info->desc_value[i]);
+                                                       char_info->char_value[i]);
                                        }
-                                       desc_val = g_variant_new("ay", builder1);
+                                       char_val = g_variant_new("ay", builder1);
                                        g_variant_builder_add(inner_builder, "{sv}",
-                                                       "Value", desc_val);
+                                                       "Value", char_val);
+                               }
+                               /*Flags*/
+                               builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
+
+                               for (i = 0; i < char_info->flags_length; i++) {
+                                       g_variant_builder_add(builder2, "s",
+                                               char_info->char_flags[i]);
+                               }
+
+                               flags_val = g_variant_new("as", builder2);
+                               g_variant_builder_add(inner_builder, "{sv}", "Flags",
+                                                       flags_val);
+
+                               /* Notifying */
+                               g_variant_builder_add(inner_builder, "{sv}", "Notifying",
+                                                       g_variant_new("b", notify));
+
+                               /* Unicast */
+                               unicast = g_strdup("00:00:00:00:00:00");
+                               g_variant_builder_add(inner_builder, "{sv}", "Unicast",
+                                                       g_variant_new("s", unicast));
+
+                               /*Descriptors*/
+                               builder3 = g_variant_builder_new(G_VARIANT_TYPE("ao"));
+                               BT_DBG("Adding Descriptors list");
+
+                               for (l4 = char_info->desc_data; l4 != NULL; l4 = l4->next) {
+                                       struct gatt_desc_info *desc_info = l4->data;
+                                               g_variant_builder_add(builder3, "o",
+                                                       desc_info->desc_path);
+                                               BT_DBG("%s", desc_info->desc_path);
                                }
 
-                               g_variant_builder_add(desc_builder, "{sa{sv}}",
-                                               GATT_DESC_INTERFACE,
-                                               inner_builder);
+                               char_desc = g_variant_new("ao", builder3);
+                               g_variant_builder_add(inner_builder, "{sv}", "Descriptors",
+                                                       char_desc);
 
+                               g_variant_builder_add(char_builder, "{sa{sv}}",
+                                               GATT_CHAR_INTERFACE , inner_builder);
                                g_variant_builder_add(builder, "{oa{sa{sv}}}",
-                                               desc_info->desc_path,
-                                               desc_builder);
+                                               char_info->char_path, char_builder);
+
+                               /*Prepare inner builder for GattDescriptor1 interface*/
+
+                               GSList *l3 = char_info->desc_data;
+
+                               if (l3 == NULL)
+                                       BT_DBG("descriptor data is NULL");
+
+                               for (l3 = char_info->desc_data; l3 != NULL; l3 = l3->next) {
+
+                                       BT_DBG("Creating builder for descriptor \n");
+
+                                       GVariantBuilder *desc_builder = NULL;
+                                       GVariantBuilder *inner_builder = NULL;
+                                       GVariantBuilder *builder1 = NULL;
+                                       GVariantBuilder *builder2 = NULL;
+                                       GVariant *desc_val = NULL;
+
+                                       desc_builder = g_variant_builder_new(
+                                                               G_VARIANT_TYPE(
+                                                               "a{sa{sv}}"));
+                                       inner_builder = g_variant_builder_new(
+                                                               G_VARIANT_TYPE(
+                                                               "a{sv}"));
 
-                               /*unref descriptor builder pointers*/
+                                       struct gatt_desc_info *desc_info = l3->data;
+                                       if (desc_info == NULL) {
+                                               BT_ERR("desc_info is NULL");
+                                               continue;
+                                       }
+
+                                       /*Uuid*/
+                                       g_variant_builder_add(inner_builder,
+                                               "{sv}", "UUID",
+                                               g_variant_new_string(
+                                                       desc_info->desc_uuid));
+
+                                       /*Characteristic*/
+                                       g_variant_builder_add(inner_builder, "{sv}",
+                                               "Characteristic",
+                                               g_variant_new("o",
+                                                       char_info->char_path));
+
+                                       /*Value*/
+                                       builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
+
+                                       if (desc_info->desc_value != NULL) {
+                                               for (i = 0; i < desc_info->value_length; i++) {
+                                                       g_variant_builder_add(builder1, "y",
+                                                               desc_info->desc_value[i]);
+                                               }
+                                               desc_val = g_variant_new("ay", builder1);
+                                               g_variant_builder_add(inner_builder, "{sv}",
+                                                               "Value", desc_val);
+                                       }
+
+                                       /*Flags*/
+                                       builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
+
+                                       for (i = 0; i < desc_info->flags_length; i++) {
+                                               g_variant_builder_add(builder2, "s",
+                                                       desc_info->desc_flags[i]);
+                                       }
+
+                                       flags_val = g_variant_new("as", builder2);
+                                       g_variant_builder_add(inner_builder, "{sv}", "Flags",
+                                                               flags_val);
+
+                                       g_variant_builder_add(desc_builder, "{sa{sv}}",
+                                                       GATT_DESC_INTERFACE,
+                                                       inner_builder);
+
+                                       g_variant_builder_add(builder, "{oa{sa{sv}}}",
+                                                       desc_info->desc_path,
+                                                       desc_builder);
+
+                                       /*unref descriptor builder pointers*/
+                                       g_variant_builder_unref(builder1);
+                                       g_variant_builder_unref(builder2);
+                                       g_variant_builder_unref(inner_builder);
+                                       g_variant_builder_unref(desc_builder);
+                               }
+
+                               if (unicast)
+                                       g_free(unicast);
+                               /*unref char builder pointers*/
                                g_variant_builder_unref(builder1);
+                               g_variant_builder_unref(builder2);
+                               g_variant_builder_unref(builder3);
                                g_variant_builder_unref(inner_builder);
-                               g_variant_builder_unref(desc_builder);
+                               g_variant_builder_unref(char_builder);
                        }
 
-                       /*unref char builder pointers*/
-                       g_variant_builder_unref(builder1);
-                       g_variant_builder_unref(builder2);
+                       /*unref service builder pointers*/
                        g_variant_builder_unref(inner_builder);
-                       g_variant_builder_unref(char_builder);
+                       g_variant_builder_unref(svc_builder);
                }
 
-               /*unref service builder pointers*/
-               g_variant_builder_unref(inner_builder);
-               g_variant_builder_unref(svc_builder);
-
                /* Return builder as method reply */
                BT_DBG("Sending gatt service builder values to Bluez");
                g_dbus_method_invocation_return_value(invocation,
@@ -343,7 +657,49 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
        }
 }
 
-static void __bt_gatt_prop_method_call(GDBusConnection *connection,
+static struct gatt_service_info *__bt_gatt_find_gatt_service_from_char(const char *char_path)
+{
+       GSList *l1, *l2;
+
+       for (l1 = gatt_services; l1 != NULL; l1 = l1->next) {
+               struct gatt_service_info *serv_info = l1->data;
+
+               for (l2 = serv_info->char_data; l2 != NULL; l2 = l2->next) {
+                       struct gatt_char_info *char_info = l2->data;
+
+                       if (g_strcmp0(char_info->char_path, char_path)
+                                               == 0)
+                               return serv_info;
+               }
+       }
+       BT_ERR("Gatt service not found");
+       return NULL;
+}
+
+static struct gatt_service_info *__bt_gatt_find_gatt_service_from_desc(const char *desc_path)
+{
+       GSList *l1, *l2, *l3;
+
+       for (l1 = gatt_services; l1 != NULL; l1 = l1->next) {
+               struct gatt_service_info *serv_info = l1->data;
+
+               for (l2 = serv_info->char_data; l2 != NULL; l2 = l2->next) {
+                       struct gatt_char_info *char_info = l2->data;
+
+                       for (l3 = char_info->desc_data; l3 != NULL; l3 = l3->next) {
+                               struct gatt_desc_info *desc_info = l3->data;
+
+                               if (g_strcmp0(desc_info->desc_path, desc_path)
+                                                       == 0)
+                                       return serv_info;
+                       }
+               }
+       }
+       BT_ERR("Gatt service not found");
+       return NULL;
+}
+
+static void __bt_gatt_char_method_call(GDBusConnection *connection,
                                        const gchar *sender,
                                        const gchar *object_path,
                                        const gchar *interface_name,
@@ -352,9 +708,414 @@ static void __bt_gatt_prop_method_call(GDBusConnection *connection,
                                        GDBusMethodInvocation *invocation,
                                        gpointer user_data)
 {
+
+       if (g_strcmp0(method_name, "ReadValue") == 0) {
+               gchar *addr = NULL;
+               guint req_id = 0;
+               guint16 offset = 0;
+               bt_gatt_read_req_t read_req = {0, };
+               bt_user_info_t *user_info = NULL;
+               struct gatt_req_info *req_info = NULL;
+               struct gatt_service_info *svc_info = NULL;
+#if defined(TIZEN_FEATURE_BT_HPS) || defined(TIZEN_FEATURE_BT_OTP)
+               GVariant *param = NULL;
+#endif
+
+               BT_DBG("Application path = %s", object_path);
+               BT_DBG("Sender = %s", sender);
+
+               user_info = _bt_get_user_data(BT_COMMON);
+               if (user_info == NULL) {
+                       BT_INFO("No callback is set for %s", object_path);
+                       g_dbus_method_invocation_return_value(invocation, NULL);
+                       return;
+               }
+
+               svc_info = __bt_gatt_find_gatt_service_from_char(object_path);
+               if (svc_info == NULL) {
+                       BT_ERR("Coudn't find service for %s", object_path);
+                       g_dbus_method_invocation_return_value(invocation, NULL);
+                       return;
+               }
+
+               g_variant_get(parameters, "(&suq)", &addr, &req_id, &offset);
+               BT_DBG("Request id = %u, Offset = %u", req_id, offset);
+
+               read_req.att_handle = (char *)object_path;
+               read_req.address = addr;
+               read_req.req_id = req_id;
+               read_req.offset = offset;
+               read_req.service_handle = svc_info->serv_path;
+
+               /* Store requets information */
+               req_info = g_new0(struct gatt_req_info, 1);
+               req_info->attr_path = g_strdup(object_path);
+               req_info->svc_path = g_strdup(read_req.service_handle);
+               req_info->request_id = req_id;
+               req_info->offset = offset;
+               req_info->context = invocation;
+               gatt_requests = g_slist_append(gatt_requests, req_info);
+
+               _bt_common_event_cb(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
+                                       BLUETOOTH_ERROR_NONE, &read_req,
+                                       user_info->cb, user_info->user_data);
+
+#if defined(TIZEN_FEATURE_BT_HPS) || defined(TIZEN_FEATURE_BT_OTP)
+               param = g_variant_new("(sssyq)",
+                               read_req.att_handle,
+                               read_req.service_handle,
+                               read_req.address,
+                               read_req.req_id,
+                               read_req.offset);
+#ifdef TIZEN_FEATURE_BT_HPS
+               __bt_send_event_to_hps(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED, param);
+#endif
+#ifdef TIZEN_FEATURE_BT_OTP
+               __bt_send_event_to_otp(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED, param);
+#endif
+#endif
+               return;
+       } else if (g_strcmp0(method_name, "WriteValue") == 0) {
+               GVariant *var = NULL;
+               gchar *addr = NULL;
+               guint req_id = 0;
+               guint16 offset = 0;
+               gboolean response_needed = FALSE;
+               bt_gatt_value_change_t value_change = {0, };
+               bt_user_info_t *user_info = NULL;
+               int len = 0;
+               struct gatt_service_info *svc_info = NULL;
+               struct gatt_req_info *req_info = NULL;
+#if defined(TIZEN_FEATURE_BT_HPS) || defined(TIZEN_FEATURE_BT_OTP)
+               GVariant *param = NULL;
+#endif
+
+               BT_DBG("WriteValue");
+               BT_DBG("Application path = %s", object_path);
+               BT_DBG("Sender = %s", sender);
+
+               g_variant_get(parameters, "(&suqb@ay)",
+                               &addr, &req_id, &offset, &response_needed, &var);
+               BT_DBG("Request id = %u, Offset = %u", req_id, offset);
+
+               user_info = _bt_get_user_data(BT_COMMON);
+               if (!user_info) {
+                       BT_INFO("No callback is set for %s", object_path);
+                       g_variant_unref(var);
+                       if (response_needed)
+                               g_dbus_method_invocation_return_value(invocation, NULL);
+                       else
+                               g_object_unref(invocation);
+                       return;
+               }
+
+               svc_info = __bt_gatt_find_gatt_service_from_char(object_path);
+               if (svc_info == NULL) {
+                       BT_ERR("Coudn't find service for %s", object_path);
+                       g_variant_unref(var);
+                       if (response_needed)
+                               g_dbus_method_invocation_return_value(invocation, NULL);
+                       else
+                               g_object_unref(invocation);
+                       return;
+               }
+
+               value_change.att_handle = (char *)object_path;
+               value_change.address = addr;
+               value_change.service_handle = svc_info->serv_path;
+               value_change.offset = offset;
+               value_change.req_id = req_id;
+               value_change.response_needed = response_needed;
+
+               len = g_variant_get_size(var);
+               if (len > 0) {
+                       char *data;
+
+                       value_change.att_value = (guint8 *)g_malloc(len);
+
+                       data = (char *)g_variant_get_data(var);
+                       memcpy(value_change.att_value, data, len);
+               }
+               value_change.val_len = len;
+
+               if (response_needed) {
+                       /* Store requets information */
+                       req_info = g_new0(struct gatt_req_info, 1);
+                       req_info->attr_path = g_strdup(object_path);
+                       req_info->svc_path = g_strdup(value_change.service_handle);
+                       req_info->request_id = req_id;
+                       req_info->offset = offset;
+                       req_info->context = invocation;
+                       gatt_requests = g_slist_append(gatt_requests, req_info);
+               } else {
+                       g_object_unref(invocation);
+               }
+
+               _bt_common_event_cb(
+                       BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
+                       BLUETOOTH_ERROR_NONE, &value_change,
+                       user_info->cb, user_info->user_data);
+
+#if defined(TIZEN_FEATURE_BT_HPS) || defined(TIZEN_FEATURE_BT_OTP)
+               if (len > 0) {
+                       gchar *svc_path;
+                       svc_path = g_strdup(svc_info->serv_path);
+                       param = g_variant_new("(sssyq@ay)",
+                                       object_path,
+                                       svc_path,
+                                       addr,
+                                       req_id,
+                                       offset,
+                                       var);
+#ifdef TIZEN_FEATURE_BT_HPS
+                       __bt_send_event_to_hps(BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED, param);
+#endif
+#ifdef TIZEN_FEATURE_BT_OTP
+                       __bt_send_event_to_otp(BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED, param);
+#endif
+                       if (svc_path)
+                               g_free(svc_path);
+               }
+#endif
+
+               g_free(value_change.att_value);
+               g_variant_unref(var);
+               return;
+       } else if (g_strcmp0(method_name, "StartNotify") == 0) {
+               bt_user_info_t *user_info = NULL;
+               bt_gatt_char_notify_change_t notify_change = {0, };
+#if TIZEN_FEATURE_BT_OTP
+               GVariant *param = NULL;
+#endif
+               BT_DBG("StartNotify");
+               user_info = _bt_get_user_data(BT_COMMON);
+               if (user_info != NULL) {
+                       struct gatt_service_info *svc_info = NULL;
+                       svc_info = __bt_gatt_find_gatt_service_from_char(object_path);
+                       if (svc_info) {
+                               notify_change.service_handle = svc_info->serv_path;
+                               notify_change.att_handle = (char *)object_path;
+                               notify_change.att_notify = TRUE;
+                               _bt_common_event_cb(
+                                       BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
+                                       BLUETOOTH_ERROR_NONE, &notify_change,
+                                       user_info->cb, user_info->user_data);
+#if TIZEN_FEATURE_BT_OTP
+                               param = g_variant_new("(ssb)",
+                               notify_change.att_handle,
+                               notify_change.service_handle,
+                               notify_change.att_notify);
+                               __bt_send_event_to_otp(BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED, param);
+#endif
+                       }
+               }
+       } else if (g_strcmp0(method_name, "StopNotify") == 0) {
+               bt_user_info_t *user_info = NULL;
+               bt_gatt_char_notify_change_t notify_change = {0, };
+#if TIZEN_FEATURE_BT_OTP
+               GVariant *param = NULL;
+#endif
+               BT_DBG("StopNotify");
+               user_info = _bt_get_user_data(BT_COMMON);
+               if (user_info != NULL) {
+                       struct gatt_service_info *svc_info = NULL;
+                       svc_info = __bt_gatt_find_gatt_service_from_char(object_path);
+                       if (svc_info) {
+                               notify_change.service_handle = svc_info->serv_path;
+                               notify_change.att_handle = (char *)object_path;
+                               notify_change.att_notify = FALSE;
+                               _bt_common_event_cb(
+                                       BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
+                                       BLUETOOTH_ERROR_NONE, &notify_change,
+                                       user_info->cb, user_info->user_data);
+#if TIZEN_FEATURE_BT_OTP
+                               param = g_variant_new("(ssb)",
+                               notify_change.att_handle,
+                               notify_change.service_handle,
+                               notify_change.att_notify);
+                               __bt_send_event_to_otp(BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED, param);
+#endif
+                       }
+               }
+       } else if (g_strcmp0(method_name, "IndicateConfirm") == 0) {
+               gchar *addr = NULL;
+               bt_gatt_indicate_confirm_t confirm = {0, };
+               bt_user_info_t *user_info = NULL;
+               gboolean complete = FALSE;
+               struct gatt_service_info *svc_info = NULL;
+
+               BT_DBG("IndicateConfirm");
+               BT_DBG("Application path = %s", object_path);
+               BT_DBG("Sender = %s", sender);
+
+               g_variant_get(parameters, "(&sb)", &addr, &complete);
+               BT_DBG("Remote Device address number = %s", addr);
+
+               confirm.att_handle = (char *)object_path;
+               confirm.address = addr;
+               confirm.complete = complete;
+
+               svc_info = __bt_gatt_find_gatt_service_from_char(object_path);
+               if (svc_info != NULL) {
+                       confirm.service_handle = svc_info->serv_path;
+
+                       user_info = _bt_get_user_data(BT_COMMON);
+                       if (user_info != NULL) {
+                               _bt_common_event_cb(
+                                       BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED,
+                                       BLUETOOTH_ERROR_NONE, &confirm,
+                                       user_info->cb, user_info->user_data);
+                       }
+               }
+       }
+
        g_dbus_method_invocation_return_value(invocation, NULL);
 }
 
+static void __bt_gatt_desc_method_call(GDBusConnection *connection,
+                                       const gchar *sender,
+                                       const gchar *object_path,
+                                       const gchar *interface_name,
+                                       const gchar *method_name,
+                                       GVariant *parameters,
+                                       GDBusMethodInvocation *invocation,
+                                       gpointer user_data)
+{
+       if (g_strcmp0(method_name, "ReadValue") == 0) {
+               gchar *addr = NULL;
+               guint req_id = 0;
+               guint16 offset = 0;
+               bt_gatt_read_req_t read_req = {0, };
+               bt_user_info_t *user_info = NULL;
+               struct gatt_req_info *req_info = NULL;
+               struct gatt_service_info *svc_info = NULL;
+
+               BT_DBG("ReadValue");
+               BT_DBG("Application path = %s", object_path);
+               BT_DBG("Sender = %s", sender);
+
+               user_info = _bt_get_user_data(BT_COMMON);
+               if (user_info == NULL) {
+                       BT_INFO("No callback is set for %s", object_path);
+                       g_dbus_method_invocation_return_value(invocation, NULL);
+                       return;
+               }
+
+               svc_info = __bt_gatt_find_gatt_service_from_desc(object_path);
+               if (svc_info == NULL) {
+                       BT_ERR("Coudn't find service for %s", object_path);
+                       g_dbus_method_invocation_return_value(invocation, NULL);
+                       return;
+               }
+
+               g_variant_get(parameters, "(&suq)", &addr, &req_id, &offset);
+               BT_DBG("Request id = %u, Offset = %u", req_id, offset);
+
+               read_req.att_handle = (char *)object_path;
+               read_req.address = addr;
+               read_req.req_id = req_id;
+               read_req.offset = offset;
+               read_req.service_handle = svc_info->serv_path;
+
+               /* Store requets information */
+               req_info = g_new0(struct gatt_req_info, 1);
+               req_info->attr_path = g_strdup(object_path);
+               req_info->svc_path = g_strdup(read_req.service_handle);
+               req_info->request_id = req_id;
+               req_info->offset = offset;
+               req_info->context = invocation;
+               gatt_requests = g_slist_append(gatt_requests, req_info);
+
+               _bt_common_event_cb(
+                               BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
+                               BLUETOOTH_ERROR_NONE, &read_req,
+                               user_info->cb, user_info->user_data);
+
+               return;
+       } else if (g_strcmp0(method_name, "WriteValue") == 0) {
+               GVariant *var = NULL;
+               gchar *addr = NULL;
+               guint req_id = 0;
+               guint16 offset = 0;
+               gboolean response_needed = FALSE;
+               bt_gatt_value_change_t value_change = {0, };
+               bt_user_info_t *user_info = NULL;
+               int len = 0;
+               struct gatt_service_info *svc_info = NULL;
+               struct gatt_req_info *req_info = NULL;
+
+               BT_DBG("WriteValue");
+               BT_DBG("Application path = %s", object_path);
+               BT_DBG("Sender = %s", sender);
+
+               g_variant_get(parameters, "(&suqb@ay)",
+                               &addr, &req_id, &offset, &response_needed, &var);
+               BT_DBG("Request id = %u, Offset = %u", req_id, offset);
+
+               user_info = _bt_get_user_data(BT_COMMON);
+               if (user_info == NULL) {
+                       BT_INFO("No callback is set for %s", object_path);
+                       g_variant_unref(var);
+                       if (response_needed)
+                               g_dbus_method_invocation_return_value(invocation, NULL);
+                       else
+                               g_object_unref(invocation);
+                       return;
+               }
+
+               svc_info = __bt_gatt_find_gatt_service_from_desc(object_path);
+               if (svc_info == NULL) {
+                       BT_ERR("Coudn't find service for %s", object_path);
+                       g_variant_unref(var);
+                       if (response_needed)
+                               g_dbus_method_invocation_return_value(invocation, NULL);
+                       else
+                               g_object_unref(invocation);
+                       return;
+               }
+
+               value_change.att_handle = (char *)object_path;
+               value_change.address = addr;
+               value_change.service_handle = svc_info->serv_path;
+               value_change.offset = offset;
+               value_change.req_id = req_id;
+               value_change.response_needed = response_needed;
+
+               len = g_variant_get_size(var);
+               if (len > 0) {
+                       char *data;
+
+                       value_change.att_value = (guint8 *)g_malloc(len);
+
+                       data = (char *)g_variant_get_data(var);
+                       memcpy(value_change.att_value, data, len);
+               }
+               value_change.val_len = len;
+
+               if (response_needed) {
+                       /* Store requets information */
+                       req_info = g_new0(struct gatt_req_info, 1);
+                       req_info->attr_path = g_strdup(object_path);
+                       req_info->svc_path = g_strdup(value_change.service_handle);
+                       req_info->request_id = req_id;
+                       req_info->offset = offset;
+                       req_info->context = invocation;
+                       gatt_requests = g_slist_append(gatt_requests, req_info);
+               } else {
+                       g_object_unref(invocation);
+               }
+
+               _bt_common_event_cb(
+                       BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
+                       BLUETOOTH_ERROR_NONE, &value_change,
+                       user_info->cb, user_info->user_data);
+
+               g_free(value_change.att_value);
+               g_variant_unref(var);
+               return;
+       }
+}
+
 gboolean __bt_gatt_emit_interface_removed(gchar *object_path, gchar *interface)
 {
        gboolean ret;
@@ -362,13 +1123,13 @@ gboolean __bt_gatt_emit_interface_removed(gchar *object_path, gchar *interface)
        GVariantBuilder *array_builder;
 
        array_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
-       g_variant_builder_init(array_builder, G_VARIANT_TYPE ("as"));
+       g_variant_builder_init(array_builder, G_VARIANT_TYPE("as"));
        g_variant_builder_add(array_builder, "s", interface);
 
        ret = g_dbus_connection_emit_signal(g_conn, NULL, "/",
                                        "org.freedesktop.Dbus.Objectmanager",
                                        "InterfacesRemoved",
-                                       g_variant_new ("(oas)",
+                                       g_variant_new("(oas)",
                                        object_path, array_builder),
                                        &error);
 
@@ -385,109 +1146,21 @@ gboolean __bt_gatt_emit_interface_removed(gchar *object_path, gchar *interface)
        return ret;
 }
 
-static gboolean __bt_gatt_desc_set_property(GDBusConnection *connection,
-                               const gchar *sender, const gchar *object_path,
-                               const gchar *interface_name,
-                               const gchar *property_name,
-                               GVariant *value,
-                               GError **err, gpointer user_data)
-{
-       BT_DBG("+");
-
-       return TRUE;
-}
-
-static gboolean __bt_gatt_char_set_property(GDBusConnection *connection,
-                               const gchar *sender, const gchar *object_path,
-                               const gchar *interface_name,
-                               const gchar *property_name,
-                               GVariant *value,
-                               GError **err, gpointer user_data)
-{
-       BT_DBG("+");
-
-       if (g_strcmp0(property_name, "Value") == 0) {
-               GVariantIter *var = NULL;
-               bt_gatt_char_value_t char_val = {0, };
-               bt_user_info_t *user_info = NULL;
-               int len = 0, i;
-
-               g_variant_get(value, "ay", &var);
-               len = g_variant_get_size(var);
-
-               char_val.char_handle = object_path;
-               if (len > 0) {
-                       char_val.char_value = (guint8 *)malloc(len);
-                       if (!char_val.char_value)
-                               return FALSE;
-               }
-               for (i = 0; i < len; i++)
-                       g_variant_iter_loop(var, "y",  &char_val.char_value[i]);
-               char_val.val_len = len;
-               user_info = _bt_get_user_data(BT_COMMON);
-               if (user_info != NULL)
-                       _bt_common_event_cb(
-                               BLUETOOTH_EVENT_GATT_SERVER_CHARACTERISTIC_VALUE_CHANGED,
-                               BLUETOOTH_ERROR_NONE, &char_val,
-                               user_info->cb, user_info->user_data);
-
-               bluetooth_gatt_update_characteristic(object_path, char_val.char_value,
-                                                                       char_val.val_len);
-
-               free(char_val.char_value);
-       }
-
-       return TRUE;
-}
-
-static GVariant *__bt_gatt_desc_get_property(GDBusConnection *connection,
-                               const gchar *sender, const gchar *object_path,
-                               const gchar *interface_name,
-                               const gchar *property_name,
-                               GError **error, gpointer user_data)
-{
-       BT_DBG("+");
-
-       return NULL;
-}
-
-static GVariant *__bt_gatt_char_get_property(GDBusConnection *connection,
-                               const gchar *sender, const gchar *object_path,
-                               const gchar *interface_name,
-                               const gchar *property_name,
-                               GError **error, gpointer user_data)
-{
-       BT_DBG("+");
-
-       return NULL;
-}
-
-static GVariant *__bt_gatt_serv_get_property(GDBusConnection *connection,
-                               const gchar *sender, const gchar *object_path,
-                               const gchar *interface_name,
-                               const gchar *property_name,
-                               GError **error, gpointer user_data)
-{
-       BT_DBG("+");
-
-       return NULL;
-}
-
 static const GDBusInterfaceVTable desc_interface_vtable = {
+       __bt_gatt_desc_method_call,
+       NULL,
        NULL,
-       __bt_gatt_desc_get_property,
-       __bt_gatt_desc_set_property
 };
 
 static const GDBusInterfaceVTable char_interface_vtable = {
+       __bt_gatt_char_method_call,
+       NULL,
        NULL,
-       __bt_gatt_char_get_property,
-       __bt_gatt_char_set_property,
 };
 
 static const GDBusInterfaceVTable serv_interface_vtable = {
        NULL,
-       __bt_gatt_serv_get_property,
+       NULL,
        NULL,
 };
 
@@ -497,12 +1170,6 @@ static const GDBusInterfaceVTable manager_interface_vtable = {
        NULL
 };
 
-static const GDBusInterfaceVTable properties_interface_vtable = {
-       __bt_gatt_prop_method_call,
-       NULL,
-       NULL
-};
-
 static GDBusNodeInfo *__bt_gatt_create_method_node_info(
                                const gchar *introspection_data)
 {
@@ -512,12 +1179,16 @@ static GDBusNodeInfo *__bt_gatt_create_method_node_info(
        if (introspection_data == NULL)
                return NULL;
 
+
+       BT_DBG("Create new node info");
        node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
 
        if (err) {
                BT_ERR("Unable to create node: %s", err->message);
                g_clear_error(&err);
+               return NULL;
        }
+
        return node_info;
 }
 
@@ -591,6 +1262,19 @@ static struct gatt_desc_info *__bt_gatt_find_gatt_desc_info(
        return NULL;
 }
 
+static struct gatt_req_info *__bt_gatt_find_request_info(guint request_id)
+{
+       GSList *l;
+
+       for (l = gatt_requests; l != NULL; l = l->next) {
+               struct gatt_req_info *req_info = l->data;
+
+               if (req_info && req_info->request_id == request_id)
+                       return req_info;
+       }
+       BT_ERR("Gatt Request not found");
+       return NULL;
+}
 
 static GDBusProxy *__bt_gatt_gdbus_init_manager_proxy(const gchar *service,
                                const gchar *path, const gchar *interface)
@@ -635,45 +1319,6 @@ static GDBusProxy *__bt_gatt_gdbus_get_manager_proxy(const gchar *service,
                                path, interface);
 }
 
-static gboolean __bt_gatt_export_properties_method(const char *svc_path)
-{
-       guint prop_id;
-       GDBusNodeInfo *prop_info;
-       GError *error = NULL;
-       struct gatt_service_info *svc_info;
-
-       BT_DBG("svc_path %s", svc_path);
-       svc_info = __bt_gatt_find_gatt_service_info(svc_path);
-
-       if (!svc_info) {
-           BT_ERR("Unable to find service info");
-               return FALSE;
-       }
-
-       /* Register ObjectManager interface */
-       prop_info = __bt_gatt_create_method_node_info(
-                                               properties_introspection_xml);
-
-       if (prop_info == NULL) {
-               BT_ERR("failed to get node info");
-               return FALSE;
-       }
-
-       prop_id = g_dbus_connection_register_object(g_conn, svc_path,
-                                               prop_info->interfaces[0],
-                                               &properties_interface_vtable,
-                                               NULL, NULL, &error);
-
-       if (prop_id == 0) {
-               BT_ERR("failed to register: %s", error->message);
-               g_error_free(error);
-               return FALSE;
-       }
-       svc_info->prop_id = prop_id;
-
-       return TRUE;
-}
-
 int bluetooth_gatt_convert_prop2string(
                        bt_gatt_characteristic_property_t properties,
                        char *char_properties[])
@@ -708,6 +1353,69 @@ int bluetooth_gatt_convert_prop2string(
                char_properties[flag_count] = g_strdup("authenticated-signed-writes");
                flag_count++;
        }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_RELIABLE_WRITE) {
+               char_properties[flag_count] = g_strdup("reliable-write");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITABLE_AUXILIARIES) {
+               char_properties[flag_count] = g_strdup("writable-auxiliaries");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_READ) {
+               char_properties[flag_count] = g_strdup("encrypt-read");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_WRITE) {
+               char_properties[flag_count] = g_strdup("encrypt-write");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_AUTHENTICATED_READ) {
+               char_properties[flag_count] = g_strdup("encrypt-authenticated-read");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_AUTHENTICATED_WRITE) {
+               char_properties[flag_count] = g_strdup("encrypt-authenticated-write");
+               flag_count++;
+       }
+
+       if (flag_count == 0) {
+               char_properties[flag_count] = g_strdup("read");
+               flag_count++;
+       }
+
+       return flag_count;
+}
+
+int bluetooth_gatt_convert_perm2string(
+                       bt_gatt_permission_t properties,
+                       char *char_properties[])
+{
+       int flag_count = 0;
+
+       if (properties & BLUETOOTH_GATT_PERMISSION_READ) {
+               char_properties[flag_count] = g_strdup("read");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_PERMISSION_WRITE) {
+               char_properties[flag_count] = g_strdup("write");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_PERMISSION_ENCRYPT_READ) {
+               char_properties[flag_count] = g_strdup("encrypt-read");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_PERMISSION_ENCRYPT_WRITE) {
+               char_properties[flag_count] = g_strdup("encrypt-write");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_PERMISSION_ENCRYPT_AUTHENTICATED_READ) {
+               char_properties[flag_count] = g_strdup("encrypt-authenticated-read");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_PERMISSION_ENCRYPT_AUTHENTICATED_WRITE) {
+               char_properties[flag_count] = g_strdup("encrypt-authenticated-write");
+               flag_count++;
+       }
 
        if (flag_count == 0) {
                char_properties[flag_count] = g_strdup("read");
@@ -755,9 +1463,9 @@ void get_service_cb(GObject *object, GAsyncResult *res, gpointer user_data)
        GVariantIter *iter = NULL;
        const gchar *key = NULL;
        GVariant *value = NULL;
-       gchar *service = NULL;
-       gchar *characteristic = NULL;
-       gchar *descriptor = NULL;
+       const gchar *service = NULL;
+       const gchar *characteristic = NULL;
+       const gchar *descriptor = NULL;
        int n_char = 1;
 
        BT_DBG(" ");
@@ -775,7 +1483,7 @@ void get_service_cb(GObject *object, GAsyncResult *res, gpointer user_data)
                }
        } else {
                char *char_cmp = NULL;
-               g_variant_get (result, "(a{sv})", &iter);
+               g_variant_get(result, "(a{sv})", &iter);
                char_cmp = g_strdup_printf("Characteristic%d", n_char);
 
                while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
@@ -792,21 +1500,25 @@ void get_service_cb(GObject *object, GAsyncResult *res, gpointer user_data)
                                BT_DBG("Descriptor %s", descriptor);
                        }
                }
+               g_variant_iter_free(iter);
+
                /* TODO: Store the service informationa and
                 * Send respponse to CAPI layer. */
 
                g_variant_unref(result);
-               if (char_cmp);
+               if (char_cmp)
                        g_free(char_cmp);
        }
 }
-void register_service_cb(GObject *object, GAsyncResult *res, gpointer user_data)
+void register_application_cb(GObject *object, GAsyncResult *res, gpointer user_data)
 {
-       BT_DBG("register_service_cb\n");
+       BT_INFO("RegisterApplication is completed");
 
        GError *error = NULL;
        GVariant *result;
 
+       register_pending_cnt = 0;
+
        result = g_dbus_proxy_call_finish(manager_gproxy, res, &error);
 
        if (result == NULL) {
@@ -819,13 +1531,15 @@ void register_service_cb(GObject *object, GAsyncResult *res, gpointer user_data)
                                                error->code, error->message);
                        g_clear_error(&error);
                }
+       } else {
+               g_variant_unref(result);
        }
 }
 
-void unregister_service_cb(GObject *object, GAsyncResult *res,
+void unregister_application_cb(GObject *object, GAsyncResult *res,
                gpointer user_data)
 {
-       BT_DBG("unregister_service_cb\n");
+       BT_INFO("UnregisterApplication is completed");
 
        GError *error = NULL;
        GVariant *result;
@@ -842,6 +1556,8 @@ void unregister_service_cb(GObject *object, GAsyncResult *res,
                                        error->code, error->message);
                        g_clear_error(&error);
                }
+       } else {
+               g_variant_unref(result);
        }
 }
 
@@ -852,45 +1568,85 @@ static int __bt_gatt_unregister_service(const char *service_path)
                return BLUETOOTH_ERROR_NOT_FOUND;
        }
 
+       return BLUETOOTH_ERROR_NONE;
+}
+
+BT_EXPORT_API int bluetooth_gatt_unregister_application(void)
+{
        GDBusProxy *proxy = NULL;
 
-       proxy = __bt_gatt_gdbus_get_manager_proxy("org.bluez",
-                                       "/org/bluez", GATT_MNGR_INTERFACE);
+       if (is_server_started) {
+               proxy = __bt_gatt_gdbus_get_manager_proxy("org.bluez",
+                               "/org/bluez/hci0", GATT_MNGR_INTERFACE);
+
+               if (proxy == NULL || app_path == NULL)
+                       return BLUETOOTH_ERROR_INTERNAL;
 
-       if (proxy == NULL)
-               return BLUETOOTH_ERROR_INTERNAL;
+               BT_INFO("UnregisterApplication");
 
-       /* Async Call to Unregister Service */
-       g_dbus_proxy_call(proxy,
-                               "UnregisterService",
+               /* Async Call to Unregister Service */
+               g_dbus_proxy_call(proxy,
+                               "UnregisterApplication",
                                g_variant_new("(o)",
-                               service_path),
+                                       app_path),
                                G_DBUS_CALL_FLAGS_NONE, -1,
                                NULL,
-                               (GAsyncReadyCallback) unregister_service_cb,
+                               (GAsyncReadyCallback) unregister_application_cb,
                                NULL);
 
-       __bt_gatt_set_service_state(service_path, FALSE);
+               is_server_started = false;
+               return BLUETOOTH_ERROR_NONE;
+       }
 
+       BT_INFO("GATT server not started");
        return BLUETOOTH_ERROR_NONE;
 }
 
 static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
 {
        GDBusConnection *local_system_gconn = NULL;
+       char *address;
        GError *err = NULL;
 
        if (g_conn == NULL) {
-               g_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+               address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+               if (address == NULL) {
+                       if (err) {
+                               BT_ERR("Failed to get bus address: %s", err->message);
+                               g_clear_error(&err);
+                       }
+                       return NULL;
+               }
+
+               g_conn = g_dbus_connection_new_for_address_sync(address,
+                                       G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
+                                       G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
+                                       NULL, /* GDBusAuthObserver */
+                                       NULL,
+                                       &err);
                if (!g_conn) {
                        if (err) {
                                BT_ERR("Unable to connect to dbus: %s", err->message);
                                g_clear_error(&err);
                        }
-                       g_conn = NULL;
+                       return NULL;
                }
        } else if (g_dbus_connection_is_closed(g_conn)) {
-               local_system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+               address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+               if (address == NULL) {
+                       if (err) {
+                               BT_ERR("Failed to get bus address: %s", err->message);
+                               g_clear_error(&err);
+                       }
+                       return NULL;
+               }
+
+               local_system_gconn = g_dbus_connection_new_for_address_sync(address,
+                                       G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
+                                       G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
+                                       NULL, /* GDBusAuthObserver */
+                                       NULL,
+                                       &err);
 
                if (!local_system_gconn) {
                        BT_ERR("Unable to connect to dbus: %s", err->message);
@@ -905,72 +1661,113 @@ static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
 
 BT_EXPORT_API int bluetooth_gatt_init(void)
 {
-       guint object_id;
        GDBusConnection *conn;
-       GDBusNodeInfo *obj_info;
        GError *error = NULL;
+       GDBusNodeInfo *node_info = NULL;
+
+       if (app_path != NULL) {
+               BT_ERR("app path already exists! initialized");
+               return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
+       }
 
-       owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
-                               BT_GATT_SERVICE_NAME,
-                               G_BUS_NAME_OWNER_FLAGS_NONE,
-                               NULL, NULL, NULL, NULL, NULL);
+       if (owner_id == 0) {
+               owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+                                       BT_GATT_SERVICE_NAME,
+                                       G_BUS_NAME_OWNER_FLAGS_NONE,
+                                       NULL, NULL, NULL, NULL, NULL);
+       }
 
        BT_DBG("owner_id is [%d]", owner_id);
+       app_path = g_strdup_printf("/com/%d", getpid());
 
        serv_id = 1;
 
        conn = __bt_gatt_get_gdbus_connection();
        if (!conn) {
                BT_ERR("Unable to get connection");
-               return BLUETOOTH_ERROR_INTERNAL;
+               goto failed;
        }
 
        /* Register ObjectManager interface */
-       obj_info = __bt_gatt_create_method_node_info(
+       node_info = __bt_gatt_create_method_node_info(
                                        manager_introspection_xml);
 
-       if (obj_info == NULL) {
+       if (node_info == NULL) {
                BT_ERR("failed to get node info");
-               return BLUETOOTH_ERROR_INTERNAL;
+               goto failed;
        }
 
-       manager_id = g_dbus_connection_register_object(g_conn, "/",
-                                               obj_info->interfaces[0],
-                                               &manager_interface_vtable,
-                                               NULL, NULL, &error);
+       if (manager_id == 0) {
+               BT_INFO("manager_id does not exists");
+
+               manager_id = g_dbus_connection_register_object(g_conn, app_path,
+                                                       node_info->interfaces[0],
+                                                       &manager_interface_vtable,
+                                                       NULL, NULL, &error);
+       }
 
        if (manager_id == 0) {
                BT_ERR("failed to register: %s", error->message);
                g_error_free(error);
-               return BLUETOOTH_ERROR_INTERNAL;
+               goto failed;
        }
 
        return BLUETOOTH_ERROR_NONE;
+
+failed:
+       if (owner_id)
+               g_bus_unown_name(owner_id);
+
+       g_free(app_path);
+
+       app_path = NULL;
+       owner_id = 0;
+
+       __bt_gatt_close_gdbus_connection();
+
+       return BLUETOOTH_ERROR_INTERNAL;
 }
 
 BT_EXPORT_API int bluetooth_gatt_deinit()
 {
+       int ret = BLUETOOTH_ERROR_NONE;
        /* Unown gdbus bus */
        if (owner_id) {
-
                /* remove/unregister all services */
                BT_DBG("removing all registered gatt service\n");
                bluetooth_gatt_delete_services();
 
-               g_bus_unown_name(owner_id);
-
                /* unregister the exported interface for object manager */
                g_dbus_connection_unregister_object(g_conn,
                                        manager_id);
 
+               manager_id = 0;
+
+               ret = bluetooth_gatt_unregister_application();
+               if (ret != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("Fail to unregister application\n");
+
+               g_bus_unown_name(owner_id);
+               owner_id = 0;
+
+               g_free(app_path);
+               app_path = NULL;
+
                BT_DBG("Gatt service deinitialized \n");
 
                g_slist_free(gatt_services);
                gatt_services = NULL;
 
-               return BLUETOOTH_ERROR_NONE;
+               g_object_unref(manager_gproxy);
+               manager_gproxy = NULL;
+
+               __bt_gatt_close_gdbus_connection();
+
+               return ret;
        }
 
+       __bt_gatt_close_gdbus_connection();
+
        return BLUETOOTH_ERROR_NOT_FOUND;
 }
 
@@ -982,7 +1779,9 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
        GDBusNodeInfo *node_info;
        gchar *path = NULL;
        GVariantBuilder *builder = NULL;
+       GVariantBuilder *builder1 = NULL;
        GVariantBuilder *inner_builder = NULL;
+       gboolean svc_primary = TRUE;
        struct gatt_service_info *serv_info = NULL;
 
        node_info = __bt_gatt_create_method_node_info(
@@ -991,7 +1790,7 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
        if (node_info == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
-       path = g_strdup_printf(GATT_SERV_OBJECT_PATH"%d", serv_id++);
+       path = g_strdup_printf("%s"GATT_SERV_OBJECT_PATH"%d", app_path, serv_id++);
        BT_DBG("gatt service path is [%s]", path);
 
        object_id = g_dbus_connection_register_object(g_conn, path,
@@ -1016,6 +1815,7 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
        serv_info->serv_id = object_id;
        serv_info->service_uuid = g_strdup(svc_uuid);
        serv_info->is_svc_registered = FALSE;
+       serv_info->is_svc_primary = svc_primary;
 
        gatt_services = g_slist_append(gatt_services, serv_info);
 
@@ -1026,6 +1826,14 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
        g_variant_builder_add(inner_builder, "{sv}",
                "UUID", g_variant_new_string(svc_uuid));
 
+       g_variant_builder_add(inner_builder, "{sv}",
+               "Primary", g_variant_new_boolean(svc_primary));
+
+       builder1 = g_variant_builder_new(G_VARIANT_TYPE("ao"));
+
+       g_variant_builder_add(inner_builder, "{sv}", "Characteristics",
+                               g_variant_new("ao", builder1));
+
        g_variant_builder_add(builder, "{sa{sv}}",
                GATT_SERV_INTERFACE, inner_builder);
 
@@ -1043,12 +1851,14 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
        g_free(path);
        g_variant_builder_unref(inner_builder);
        g_variant_builder_unref(builder);
+       g_variant_builder_unref(builder1);
 
        return BLUETOOTH_ERROR_NONE;
 }
 
 BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
                        const char *svc_path, const char *char_uuid,
+                       bt_gatt_permission_t permissions,
                        bt_gatt_characteristic_property_t properties,
                        char **char_path)
 {
@@ -1062,6 +1872,7 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
        struct gatt_service_info *serv_info = NULL;
        struct gatt_char_info *char_info = NULL;
        GVariantBuilder *builder2 = NULL;
+       GVariantBuilder *builder3 = NULL;
        GVariant *flags_val = NULL;
        int i = 0;
        char *char_flags[NUMBER_OF_FLAGS];
@@ -1099,6 +1910,15 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
+       if (permissions & BLUETOOTH_GATT_PERMISSION_ENCRYPT_READ)
+               properties |= BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_READ;
+       if (permissions & BLUETOOTH_GATT_PERMISSION_ENCRYPT_AUTHENTICATED_READ)
+               properties |= BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_AUTHENTICATED_READ;
+       if (permissions & BLUETOOTH_GATT_PERMISSION_ENCRYPT_WRITE)
+               properties |= BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_WRITE;
+       if (permissions & BLUETOOTH_GATT_PERMISSION_ENCRYPT_AUTHENTICATED_WRITE)
+               properties |= BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_AUTHENTICATED_WRITE;
+
        flag_count = bluetooth_gatt_convert_prop2string(properties, char_flags);
 
        char_info = g_new0(struct gatt_char_info, 1);
@@ -1107,9 +1927,9 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
        char_info->char_id = object_id;
        char_info->char_uuid = g_strdup(char_uuid);
 
-       for (i = 0; i < flag_count; i++) {
+       for (i = 0; i < flag_count; i++)
                char_info->char_flags[i] = char_flags[i];
-               }
+
 
        char_info->flags_length = flag_count;
 
@@ -1125,14 +1945,18 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
 
        builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
 
-       for (i = 0; i < flag_count; i++) {
+       for (i = 0; i < flag_count; i++)
                g_variant_builder_add(builder2, "s", char_flags[i]);
-       }
 
        flags_val = g_variant_new("as", builder2);
        g_variant_builder_add(inner_builder, "{sv}", "Flags",
                                flags_val);
 
+       builder3 = g_variant_builder_new(G_VARIANT_TYPE("ao"));
+
+       g_variant_builder_add(inner_builder, "{sv}", "Descriptors",
+                               g_variant_new("ao", builder3));
+
        g_variant_builder_add(builder, "{sa{sv}}",
                                GATT_CHAR_INTERFACE,
                                inner_builder);
@@ -1153,6 +1977,7 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
        g_variant_builder_unref(inner_builder);
        g_variant_builder_unref(builder);
        g_variant_builder_unref(builder2);
+       g_variant_builder_unref(builder3);
 
        return BLUETOOTH_ERROR_NONE;
 }
@@ -1170,20 +1995,28 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristic_value(
        GVariant *char_val = NULL;
        GError *error = NULL;
        int i = 0;
+       int res = BLUETOOTH_ERROR_NONE;
 
        line_argv = g_strsplit_set(characteristic, "/", 0);
-       serv_path = g_strdup_printf("/%s", line_argv[1]);
+       serv_path = g_strdup_printf("/%s/%s/%s", line_argv[1], line_argv[2], line_argv[3]);
 
        char_info = __bt_gatt_find_gatt_char_info(serv_path, characteristic);
 
        if (char_info == NULL) {
-               g_strfreev(line_argv);
-               return BLUETOOTH_ERROR_INVALID_PARAM;
+               /* Fix : RESOURCE_LEAK */
+               res = BLUETOOTH_ERROR_INVALID_PARAM;
+               goto done;
        }
 
        char_info->value_length = value_length;
 
        char_info->char_value = (char *)malloc(value_length);
+       /* Fix : NULL_RETURNS */
+       if (char_info->char_value == NULL) {
+               res = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+               goto done;
+       }
+
        for (i = 0; i < value_length; i++)
                char_info->char_value[i] = char_value[i];
 
@@ -1192,9 +2025,8 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristic_value(
 
        builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
 
-       for (i = 0; i < value_length; i++) {
+       for (i = 0; i < value_length; i++)
                g_variant_builder_add(builder1, "y", char_value[i]);
-       }
 
        char_val = g_variant_new("ay", builder1);
                g_variant_builder_add(inner_builder, "{sv}", "Value", char_val);
@@ -1210,16 +2042,19 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristic_value(
                        char_info->char_path, builder),
                        &error);
 
-       g_strfreev(line_argv);
        g_variant_builder_unref(inner_builder);
        g_variant_builder_unref(builder);
        g_variant_builder_unref(builder1);
+done:
+       g_strfreev(line_argv);
+       g_free(serv_path);
 
-       return BLUETOOTH_ERROR_NONE;
+       return res;
 }
 
 BT_EXPORT_API int bluetooth_gatt_add_descriptor(
                        const char *char_path, const char *desc_uuid,
+                       bt_gatt_permission_t permissions,
                        char **desc_path)
 {
        static int desc_id = 1;
@@ -1233,6 +2068,11 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
        struct gatt_desc_info *desc_info = NULL;
        gchar **line_argv = NULL;
        char *serv_path;
+       GVariantBuilder *builder2 = NULL;
+       GVariant *flags_val = NULL;
+       int i = 0;
+       char *desc_flags[NUMBER_OF_FLAGS];
+       int flag_count = 0;
 
        if (new_char) {
                desc_id = 1;
@@ -1240,14 +2080,12 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
        }
 
        line_argv = g_strsplit_set(char_path, "/", 0);
-       serv_path = g_strdup_printf("/%s", line_argv[1]);
+       serv_path = g_strdup_printf("/%s/%s/%s", line_argv[1], line_argv[2], line_argv[3]);
 
        char_info = __bt_gatt_find_gatt_char_info(serv_path, char_path);
-
-       g_free(serv_path);
-
        if (char_info == NULL) {
                g_strfreev(line_argv);
+               g_free(serv_path);
                return BLUETOOTH_ERROR_INVALID_PARAM;
        }
 
@@ -1256,6 +2094,7 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
 
        if (node_info == NULL) {
                g_strfreev(line_argv);
+               g_free(serv_path);
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
@@ -1272,16 +2111,24 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
                g_error_free(error);
                g_free(path);
                g_strfreev(line_argv);
+               g_free(serv_path);
 
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
+       flag_count = bluetooth_gatt_convert_perm2string(permissions, desc_flags);
+
        desc_info = g_new0(struct gatt_desc_info, 1);
 
        desc_info->desc_path = g_strdup(path);
        desc_info->desc_id = object_id;
        desc_info->desc_uuid = g_strdup(desc_uuid);
 
+       for (i = 0; i < flag_count; i++)
+               desc_info->desc_flags[i] = desc_flags[i];
+
+       desc_info->flags_length = flag_count;
+
        char_info->desc_data = g_slist_append(char_info->desc_data, desc_info);
 
        builder = g_variant_builder_new(G_VARIANT_TYPE("a{sa{sv}}"));
@@ -1292,6 +2139,15 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
        g_variant_builder_add(inner_builder, "{sv}", "Characteristic",
                                g_variant_new("o", char_path));
 
+       builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
+
+       for (i = 0; i < flag_count; i++)
+               g_variant_builder_add(builder2, "s", desc_flags[i]);
+
+       flags_val = g_variant_new("as", builder2);
+       g_variant_builder_add(inner_builder, "{sv}", "Flags",
+                               flags_val);
+
        g_variant_builder_add(builder, "{sa{sv}}",
                                GATT_DESC_INTERFACE,
                                inner_builder);
@@ -1306,6 +2162,7 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
        *desc_path = g_strdup(path);
 
        g_free(path);
+       g_free(serv_path);
        g_strfreev(line_argv);
        g_variant_builder_unref(inner_builder);
        g_variant_builder_unref(builder);
@@ -1329,18 +2186,24 @@ BT_EXPORT_API int bluetooth_gatt_set_descriptor_value(
        int i ;
 
        line_argv = g_strsplit_set(desc_path, "/", 0);
-       serv_path = g_strdup_printf("/%s", line_argv[1]);
-       char_path = g_strdup_printf("%s/%s", serv_path, line_argv[2]);
+       serv_path = g_strdup_printf("/%s/%s/%s", line_argv[1], line_argv[2], line_argv[3]);
+       char_path = g_strdup_printf("%s/%s", serv_path, line_argv[4]);
 
        desc_info = __bt_gatt_find_gatt_desc_info(serv_path, char_path, desc_path);
 
-       if (desc_info == NULL) {
-               g_strfreev(line_argv);
-               return BLUETOOTH_ERROR_INVALID_PARAM;
-       }
+       /* Free the allocated memory */
+       g_strfreev(line_argv);
+       g_free(serv_path);
+       g_free(char_path);
+
+       /* Fix : NULL_RETURNS */
+       retv_if(desc_info == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
 
        desc_info->desc_value = (char *)malloc(value_length);
 
+       /* Fix : NULL_RETURNS */
+       retv_if(desc_info->desc_value == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION);
+
        for (i = 0; i < value_length; i++)
                desc_info->desc_value[i] = desc_value[i];
 
@@ -1351,9 +2214,9 @@ BT_EXPORT_API int bluetooth_gatt_set_descriptor_value(
 
        builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
 
-       for (i = 0; i < value_length; i++) {
+       for (i = 0; i < value_length; i++)
                g_variant_builder_add(builder1, "y", desc_value[i]);
-       }
+
        desc_val = g_variant_new("ay", builder1);
        g_variant_builder_add(inner_builder, "{sv}", "Value", desc_val);
 
@@ -1368,7 +2231,6 @@ BT_EXPORT_API int bluetooth_gatt_set_descriptor_value(
                                desc_info->desc_path, builder),
                                &error);
 
-       g_strfreev(line_argv);
        g_variant_builder_unref(inner_builder);
        g_variant_builder_unref(builder);
        g_variant_builder_unref(builder1);
@@ -1382,7 +2244,7 @@ int bluetooth_gatt_get_service(const char *svc_uuid)
        gchar *uuid = NULL;
 
        proxy = __bt_gatt_gdbus_get_manager_proxy("org.bluez",
-                                       "/org/bluez", GATT_MNGR_INTERFACE);
+                                       "/org/bluez/hci0", GATT_MNGR_INTERFACE);
        if (proxy == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
@@ -1405,38 +2267,58 @@ int bluetooth_gatt_get_service(const char *svc_uuid)
 BT_EXPORT_API int bluetooth_gatt_register_service(
                        const char *svc_path)
 {
-       GDBusProxy *proxy = NULL;
-       gchar *path = NULL;
+       if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_GATT_REGISTER_SERVICE)
+                       == BLUETOOTH_ERROR_PERMISSION_DEINED) {
+               BT_ERR("Don't have aprivilege to use this API");
+               return BLUETOOTH_ERROR_PERMISSION_DEINED;
+       }
+
+       register_pending_cnt++;
 
        if (__bt_gatt_get_service_state(svc_path)) {
                BT_DBG("service already registered \n");
                return BLUETOOTH_ERROR_NONE;
        }
 
-       if (!__bt_gatt_export_properties_method(svc_path)) {
-               BT_ERR("Failed to export Object manager method");
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
+       __bt_gatt_set_service_state(svc_path, TRUE);
 
-       proxy = __bt_gatt_gdbus_get_manager_proxy("org.bluez",
-                                       "/org/bluez", GATT_MNGR_INTERFACE);
-       if (proxy == NULL)
-               return BLUETOOTH_ERROR_INTERNAL;
+       return BLUETOOTH_ERROR_NONE;
+}
 
-       path = g_strdup(svc_path);
+BT_EXPORT_API int bluetooth_gatt_register_application(void)
+{
+       GDBusProxy *proxy = NULL;
 
-       g_dbus_proxy_call(proxy,
-                       "RegisterService",
-                       g_variant_new("(oa{sv})",
-                       path, NULL),
-                       G_DBUS_CALL_FLAGS_NONE, -1,
-                       NULL,
-                       (GAsyncReadyCallback) register_service_cb,
-                       NULL);
+       if (!is_server_started) {
 
-       __bt_gatt_set_service_state(svc_path, TRUE);
+               if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_GATT_REGISTER_APPLICATION)
+                               == BLUETOOTH_ERROR_PERMISSION_DEINED) {
+                       BT_ERR("Don't have aprivilege to use this API");
+                       return BLUETOOTH_ERROR_PERMISSION_DEINED;
+               }
 
-       g_free(path);
+               proxy = __bt_gatt_gdbus_get_manager_proxy("org.bluez",
+                               "/org/bluez/hci0", GATT_MNGR_INTERFACE);
+               if (proxy == NULL || app_path == NULL)
+                       return BLUETOOTH_ERROR_INTERNAL;
+
+               BT_INFO("RegisterApplication");
+
+               g_dbus_proxy_call(proxy,
+                               "RegisterApplication",
+                               g_variant_new("(oa{sv})",
+                                       app_path, NULL),
+                               G_DBUS_CALL_FLAGS_NONE, -1,
+                               NULL,
+                               (GAsyncReadyCallback) register_application_cb,
+                               NULL);
+
+               is_server_started = true;
+
+               return BLUETOOTH_ERROR_NONE;
+       }
+
+       BT_INFO("Already RegisterApplication");
 
        return BLUETOOTH_ERROR_NONE;
 }
@@ -1454,13 +2336,12 @@ BT_EXPORT_API int bluetooth_gatt_delete_services(void)
                        if (bluetooth_gatt_unregister_service(info->serv_path)
                                        != BLUETOOTH_ERROR_NONE) {
                                error = BLUETOOTH_ERROR_INTERNAL;
-                               BT_DBG(" Error in removing service %s \n",
+                               BT_ERR("Error in removing service %s \n",
                                                 info->serv_path);
                        }
                }
                BT_DBG(" All services removed successfully.\n ");
-       }
-       else {
+       } else {
                BT_DBG(" There are no registered services.\n ");
        }
 
@@ -1490,23 +2371,21 @@ BT_EXPORT_API int bluetooth_gatt_update_characteristic(
        gchar *serv_path = NULL;
 
        line_argv = g_strsplit_set(char_path, "/", 0);
-       serv_path = g_strdup_printf("/%s", line_argv[1]);
+       serv_path = g_strdup_printf("/%s/%s/%s", line_argv[1], line_argv[2], line_argv[3]);
 
        if (!__bt_gatt_get_service_state(serv_path)) {
                BT_DBG("service not registered for this characteristic \n");
-               g_strfreev(line_argv);
                g_free(serv_path);
+               g_strfreev(line_argv);
                return BLUETOOTH_ERROR_INTERNAL;
        }
-       g_free(serv_path);
 
        outer_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
        invalidated_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
 
        inner_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
-       for (i = 0; i < value_length; i++) {
+       for (i = 0; i < value_length; i++)
                g_variant_builder_add(inner_builder, "y", char_value[i]);
-       }
 
        update_value = g_variant_new("ay", inner_builder);
 
@@ -1532,8 +2411,30 @@ BT_EXPORT_API int bluetooth_gatt_update_characteristic(
                        g_clear_error(&error);
                }
                err = BLUETOOTH_ERROR_INTERNAL;
+       } else {
+               struct gatt_char_info *char_info = NULL;
+
+               char_info = __bt_gatt_find_gatt_char_info(serv_path, char_path);
+               if (char_info == NULL) {
+                       g_free(serv_path);
+                       g_strfreev(line_argv);
+                       g_variant_builder_unref(inner_builder);
+                       g_variant_builder_unref(outer_builder);
+                       g_variant_builder_unref(invalidated_builder);
+
+                       return BLUETOOTH_ERROR_INVALID_DATA;
+               }
+
+               char_info->value_length = value_length;
+
+               char_info->char_value = (char *)realloc(char_info->char_value, value_length);
+               if (char_info->char_value) {
+                       for (i = 0; i < value_length; i++)
+                               char_info->char_value[i] = char_value[i];
+               }
        }
 
+       g_free(serv_path);
        g_strfreev(line_argv);
        g_variant_builder_unref(inner_builder);
        g_variant_builder_unref(outer_builder);
@@ -1542,13 +2443,56 @@ BT_EXPORT_API int bluetooth_gatt_update_characteristic(
        return err;
 }
 
+static void __bt_gatt_free_descriptor_info(struct gatt_desc_info *desc_info)
+{
+       int i;
+
+       if (!desc_info)
+               return;
+
+       g_free(desc_info->desc_path);
+       g_free(desc_info->desc_uuid);
+       g_free(desc_info->desc_value);
+
+       for (i = 0; i < desc_info->flags_length; i++)
+               g_free(desc_info->desc_flags[i]);
+
+       g_free(desc_info);
+}
+
+static void __bt_gatt_free_characteristic_info(struct gatt_char_info *char_info)
+{
+       int i;
+
+       if (!char_info)
+               return;
+
+       g_free(char_info->char_path);
+       g_free(char_info->char_uuid);
+       g_free(char_info->char_value);
+
+       for (i = 0; i < char_info->flags_length; i++)
+               g_free(char_info->char_flags[i]);
+
+       g_free(char_info);
+}
+
+static void __bt_gatt_free_service_info(struct gatt_service_info *svc_info)
+{
+       if (!svc_info)
+               return;
+
+       g_free(svc_info->serv_path);
+       g_free(svc_info->service_uuid);
+       g_free(svc_info);
+}
+
 BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
 {
        GSList *l, *l1;
        struct gatt_service_info *svc_info;
        gboolean ret;
        int err = BLUETOOTH_ERROR_NONE;
-       GSList *tmp;
 
        BT_DBG("svc_path %s", svc_path);
        svc_info = __bt_gatt_find_gatt_service_info(svc_path);
@@ -1560,16 +2504,22 @@ BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
 
        err = __bt_gatt_unregister_service(svc_path);
        if (err != BLUETOOTH_ERROR_NONE) {
-               BT_DBG("Could not unregister application");
+               BT_ERR("Could not unregister application");
                return err;
        }
 
        for (l = svc_info->char_data; l != NULL; l = l->next) {
                struct gatt_char_info *char_info = l->data;
 
+               if (char_info == NULL)
+                       break;
+
                for (l1 = char_info->desc_data; l1 != NULL; l1 = l1->next) {
                        struct gatt_desc_info *desc_info = l1->data;
 
+                       if (desc_info == NULL)
+                               break;
+
                        ret = g_dbus_connection_unregister_object(g_conn,
                                                desc_info->desc_id);
                        if (ret) {
@@ -1579,7 +2529,15 @@ BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
                        } else {
                                err = BLUETOOTH_ERROR_INTERNAL;
                        }
+
+                       /* list remove & free */
+                       char_info->desc_data = g_slist_remove(char_info->desc_data, desc_info);
+                       __bt_gatt_free_descriptor_info(desc_info);
                }
+
+               g_slist_free(char_info->desc_data);
+               char_info->desc_data = NULL;
+
                ret = g_dbus_connection_unregister_object(g_conn,
                                        char_info->char_id);
                if (ret) {
@@ -1588,7 +2546,15 @@ BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
                } else {
                        err = BLUETOOTH_ERROR_INTERNAL;
                }
+
+               /* list remove & free */
+               svc_info->char_data = g_slist_remove(svc_info->char_data, char_info);
+               __bt_gatt_free_characteristic_info(char_info);
        }
+
+       g_slist_free(svc_info->char_data);
+       svc_info->char_data = NULL;
+
        ret = g_dbus_connection_unregister_object(g_conn, svc_info->serv_id);
        if (ret) {
                __bt_gatt_emit_interface_removed(svc_info->serv_path,
@@ -1598,22 +2564,169 @@ BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
        }
 
        ret = g_dbus_connection_unregister_object(g_conn, svc_info->prop_id);
-       if (ret) {
+       if (ret)
                BT_DBG("Unregistered the service on properties interface");
+
+       /* list remove & free */
+       gatt_services = g_slist_remove(gatt_services, svc_info);
+       __bt_gatt_free_service_info(svc_info);
+
+       new_service = FALSE;
+
+       if (gatt_services == NULL)
+               serv_id = 1;
+       else if (gatt_services->next == NULL)
+               serv_id--;
+
+       return err;
+}
+
+BT_EXPORT_API int bluetooth_gatt_send_response(int request_id, guint req_type,
+                                       int resp_state, int offset, char *value, int value_length)
+{
+       struct gatt_req_info *req_info = NULL;
+
+       if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_GATT_SEND_RESPONSE)
+                       == BLUETOOTH_ERROR_PERMISSION_DEINED) {
+               BT_ERR("Don't have aprivilege to use this API");
+               return BLUETOOTH_ERROR_PERMISSION_DEINED;
        }
 
-       for (tmp = gatt_services; tmp != NULL; tmp = tmp->next) {
-               struct gatt_service_info *info = tmp->data;
+       req_info = __bt_gatt_find_request_info(request_id);
+       if (req_info == NULL) {
+               BT_ERR("Coundn't find request id [%d]", request_id);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
 
-               if (g_strcmp0(info->serv_path, svc_path) == 0) {
-                       g_slist_delete_link(gatt_services, tmp->data);
+       if (resp_state != BLUETOOTH_ATT_ERROR_NONE) {
+               BT_ERR("resp_state is 0x%X", resp_state);
+
+               switch (resp_state) {
+               case BLUETOOTH_ATT_ERROR_WRITE_REQUEST_REJECTED:
+                       g_dbus_method_invocation_return_dbus_error(req_info->context,
+                       "org.bluez.Error.Failed", "Write Request Rejected");
+                       break;
+               case BLUETOOTH_ATT_ERROR_OBJECT_NOT_SELECTED:
+                       g_dbus_method_invocation_return_dbus_error(req_info->context,
+                       "org.bluez.Error.Failed", "Object Not Selected");
+                       break;
+               case BLUETOOTH_ATT_ERROR_CONCURRENCY_LIMIT_EXCEEDED:
+                       g_dbus_method_invocation_return_dbus_error(req_info->context,
+                       "org.bluez.Error.Failed", "Concurrency Limit Exceeded");
+                       break;
+               case BLUETOOTH_ATT_ERROR_OBJECT_NAME_EXISTS:
+                       g_dbus_method_invocation_return_dbus_error(req_info->context,
+                       "org.bluez.Error.Failed", "Object Name Already Exists");
+                       break;
+               case BLUETOOTH_ATT_ERROR_CCCD_IMPROPERLY_CONFIGURED:
+                       g_dbus_method_invocation_return_dbus_error(req_info->context,
+                       "org.bluez.Error.Failed", "CCC Improperly Configured");
+                       break;
+               default:
+                       g_dbus_method_invocation_return_dbus_error(req_info->context,
+                       "org.bluez.Error.Failed", "Application Error");
+                       break;
                }
+
+               gatt_requests = g_slist_remove(gatt_requests, req_info);
+
+               req_info->context = NULL;
+               if (req_info->attr_path)
+                       g_free(req_info->attr_path);
+               if (req_info->svc_path)
+                       g_free(req_info->svc_path);
+               g_free(req_info);
+
+               return BLUETOOTH_ERROR_NONE;
        }
 
-       new_service = FALSE;
+       if (req_type == BLUETOOTH_GATT_ATT_REQUEST_TYPE_READ) {
+               int i;
+               GVariantBuilder *inner_builder = NULL;
+               inner_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+               if (value_length > 0 && value != NULL) {
+                       for (i = 0; i < value_length; i++)
+                               g_variant_builder_add(inner_builder, "y", value[i]);
+               }
+               g_dbus_method_invocation_return_value(req_info->context,
+                               g_variant_new("(ay)", inner_builder));
+               g_variant_builder_unref(inner_builder);
+       } else {
+               g_dbus_method_invocation_return_value(req_info->context, NULL);
+       }
+       gatt_requests = g_slist_remove(gatt_requests, req_info);
 
-       if (gatt_services->next == NULL)
-               serv_id--;
+       req_info->context = NULL;
+       if (req_info->attr_path)
+               g_free(req_info->attr_path);
+       if (req_info->svc_path)
+               g_free(req_info->svc_path);
+       g_free(req_info);
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_set_notification(const char *char_path,
+                                               bluetooth_device_address_t *unicast_address)
+{
+       GVariantBuilder *outer_builder;
+       GVariantBuilder *invalidated_builder;
+       GError *error = NULL;
+       gboolean notify = TRUE;
+       gboolean ret = TRUE;
+       int err = BLUETOOTH_ERROR_NONE;
+       gchar **line_argv = NULL;
+       gchar *serv_path = NULL;
+       char addr[20] = { 0 };
+
+       line_argv = g_strsplit_set(char_path, "/", 0);
+       serv_path = g_strdup_printf("/%s/%s/%s", line_argv[1], line_argv[2], line_argv[3]);
+
+       if (!__bt_gatt_get_service_state(serv_path)) {
+               BT_DBG("service not registered for this characteristic \n");
+               g_free(serv_path);
+               g_strfreev(line_argv);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       g_free(serv_path);
+
+       outer_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+       invalidated_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
+
+       g_variant_builder_add(outer_builder, "{sv}", "Notifying",
+                                       g_variant_new("b", notify));
+
+       if (unicast_address) {
+               _bt_convert_addr_type_to_string(addr,
+                                       (unsigned char *)unicast_address->addr);
+       }
+       g_variant_builder_add(outer_builder, "{sv}", "Unicast",
+                               g_variant_new("s", addr));
+
+       BT_DBG("Set characteristic Notification \n");
+       ret = g_dbus_connection_emit_signal(g_conn, NULL,
+                                       char_path,
+                                       "org.freedesktop.DBus.Properties",
+                                       "PropertiesChanged",
+                                       g_variant_new("(sa{sv}as)",
+                                       "org.bluez.GattCharacteristic1",
+                                       outer_builder, invalidated_builder),
+                                       &error);
+
+       if (!ret) {
+               if (error != NULL) {
+                       BT_ERR("D-Bus API failure: errCode[%x], \
+                                       message[%s]",
+                                       error->code, error->message);
+                       g_clear_error(&error);
+               }
+               err = BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       g_strfreev(line_argv);
+       g_variant_builder_unref(outer_builder);
+       g_variant_builder_unref(invalidated_builder);
 
        return err;
 }