[BT-Frwk] Fixed build warnings.
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-adapter-le.c
old mode 100644 (file)
new mode 100755 (executable)
index 475e144..070e3f6
@@ -1,11 +1,5 @@
 /*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
- *              Girishashok Joshi <girish.joshi@samsung.com>
- *              Chanyeol Park <chanyeol.park@samsung.com>
+ * Copyright (c) 2011 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.
@@ -22,8 +16,7 @@
  */
 
 #include <stdio.h>
-//#include <dbus/dbus-glib.h>
-//#include <dbus/dbus.h>
+#include <dbus/dbus.h>
 #include <gio/gio.h>
 #include <glib.h>
 #include <dlog.h>
@@ -39,6 +32,7 @@
 #include "bt-service-event.h"
 #include "bt-service-adapter.h"
 #include "bt-service-adapter-le.h"
+#include "bt-service-util.h"
 
 
 #define BT_ADV_INTERVAL_MIN 20 /* msec */
@@ -87,6 +81,82 @@ static gboolean is_le_scanning = FALSE;
 static gboolean scan_filter_enabled = FALSE;
 static bt_le_scan_type_t le_scan_type = BT_LE_PASSIVE_SCAN;
 
+static GSList *gatt_client_senders = NULL;
+
+
+gboolean _bt_is_set_scan_parameter(void)
+{
+       return is_le_set_scan_parameter;
+}
+
+void _bt_init_gatt_client_senders(void)
+{
+       _bt_clear_request_list();
+}
+
+int _bt_insert_gatt_client_sender(char *sender)
+{
+       char *info;
+
+       retv_if(sender == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
+
+       info = g_strdup(sender);
+       retv_if(info == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION);
+
+       gatt_client_senders = g_slist_append(gatt_client_senders, info);
+
+       BT_DBG("insert sender: %s", sender);
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_delete_gatt_client_sender(char *sender)
+{
+       GSList *l;
+       char *info;
+
+       BT_DBG("remove sender: %s", sender);
+
+       for (l = gatt_client_senders; l != NULL; l = g_slist_next(l)) {
+               info = l->data;
+               if (info == NULL)
+                       continue;
+
+               if (g_strcmp0(info, sender) == 0) {
+                       BT_DBG("remove info");
+                       gatt_client_senders = g_slist_remove(gatt_client_senders, info);
+                       g_free(info);
+                       return BLUETOOTH_ERROR_NONE;
+               }
+       }
+
+       return BLUETOOTH_ERROR_NOT_FOUND;
+}
+
+void _bt_clear_gatt_client_senders(void)
+{
+       if (gatt_client_senders) {
+               g_slist_foreach(gatt_client_senders, (GFunc)g_free, NULL);
+               g_slist_free(gatt_client_senders);
+               gatt_client_senders = NULL;
+       }
+}
+
+static void __bt_send_foreach_event(gpointer data, gpointer user_data)
+{
+       char *sender = data;
+       GVariant *param = user_data;
+
+       _bt_send_event_to_dest(sender, BT_DEVICE_EVENT,BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
+                                       param);
+}
+
+void _bt_send_char_value_changed_event(void *param)
+{
+       g_slist_foreach(gatt_client_senders, __bt_send_foreach_event,
+                                       (gpointer)param);
+}
+
 void __bt_free_le_adv_slot(void)
 {
        int i;
@@ -183,7 +253,7 @@ int __bt_get_available_adv_slot_id(const char *sender, int adv_handle, gboolean
        return -1;
 }
 
-void __bt_register_adv_slot_owner(const char *sender, int adv_handle, int slot_id)
+void _bt_register_adv_slot_owner(const char *sender, int adv_handle, int slot_id)
 {
        if (le_adv_slot[slot_id].sender == NULL) {
                le_adv_slot[slot_id].sender = strdup(sender);
@@ -191,7 +261,7 @@ void __bt_register_adv_slot_owner(const char *sender, int adv_handle, int slot_i
        }
 }
 
-void __bt_unregister_adv_slot_owner(int slot_id)
+void _bt_unregister_adv_slot_owner(int slot_id)
 {
        g_free(le_adv_slot[slot_id].sender);
        le_adv_slot[slot_id].sender = NULL;
@@ -305,7 +375,7 @@ int _bt_set_advertising(const char *sender, int adv_handle, gboolean enable, gbo
        }
 
        if (enable == TRUE)
-               __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
+               _bt_register_adv_slot_owner(sender, adv_handle, slot_id);
 
        le_adv_slot[slot_id].is_advertising = enable;
        BT_INFO("Set advertising [%d]", enable);
@@ -403,9 +473,9 @@ int _bt_set_custom_advertising(const char *sender, int adv_handle,
        }
 
        if (enable == TRUE)
-               __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
+               _bt_register_adv_slot_owner(sender, adv_handle, slot_id);
        else
-               __bt_unregister_adv_slot_owner(slot_id);
+               _bt_unregister_adv_slot_owner(slot_id);
 
        le_adv_slot[slot_id].is_advertising = enable;
        BT_INFO_C("Set advertising [%d]", enable);
@@ -529,7 +599,7 @@ int _bt_set_advertising_data(const char *sender, int adv_handle,
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
+       _bt_register_adv_slot_owner(sender, adv_handle, slot_id);
 
        __bt_get_ad_data_by_type((char *)adv_data.data, adv_data_len, 0xff,
                        &old_mdata, &old_len);
@@ -623,7 +693,7 @@ int _bt_set_scan_response_data(const char *sender, int adv_handle,
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
+       _bt_register_adv_slot_owner(sender, adv_handle, slot_id);
 
        /* Compare with previous scan resp data */
        __bt_get_ad_data_by_type((char *)resp_data.data, resp_data_len, 0xff,
@@ -724,7 +794,7 @@ int __bt_get_available_scan_filter_slot_id(void)
        bt_adapter_le_scanner_t *scanner;
        GSList *fl;
        bluetooth_le_scan_filter_t *filter_data;
-       gboolean *slot_check_list;
+       gboolean *slot_check_list = NULL;
        int i;
 
        if (le_feature_info.max_filter == 0) {
@@ -732,6 +802,10 @@ int __bt_get_available_scan_filter_slot_id(void)
                return -1;
        }
        slot_check_list = g_malloc0(sizeof(gboolean) * le_feature_info.max_filter);
+       if (slot_check_list == NULL) {
+               BT_ERR("Fail to allocate memory");
+               return -1;
+       }
 
        for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
                scanner = l->data;
@@ -760,12 +834,12 @@ int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *fil
        GDBusProxy *proxy;
        GError *error = NULL;
        GVariant *ret, *param;
-       GVariant *arr_uuid_param, *arr_uuid_mask_param;
-       GVariant *arr_data_param, *arr_data_mask_param;
-       GArray *arr_uuid;
-       GArray *arr_uuid_mask;
-       GArray *arr_data;
-       GArray *arr_data_mask;
+       GVariant *arr_uuid_param = NULL, *arr_uuid_mask_param = NULL;
+       GVariant *arr_data_param = NULL, *arr_data_mask_param = NULL;
+       GArray *arr_uuid = NULL;
+       GArray *arr_uuid_mask = NULL;
+       GArray *arr_data = NULL;
+       GArray *arr_data_mask = NULL;
        bt_adapter_le_scanner_t *scanner = NULL;
        bluetooth_le_scan_filter_t *filter_data = NULL;
        int feature_selection = 0;
@@ -777,31 +851,26 @@ int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *fil
        proxy = _bt_get_adapter_proxy();
        retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       arr_uuid = g_array_new(TRUE, TRUE, sizeof(guint8));
-       arr_uuid_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
-       arr_data = g_array_new(TRUE, TRUE, sizeof(guint8));
-       arr_data_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
-
-       arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
-                                            arr_uuid, filter->service_uuid.data_len * sizeof(guint8), TRUE, NULL, NULL);
-       arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
-                                            arr_uuid_mask, filter->service_uuid_mask.data_len * sizeof(guint8), TRUE, NULL, NULL);
-       arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
-                                            arr_data, filter->service_data.data_len * sizeof(guint8), TRUE, NULL, NULL);
-       arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
-                                            arr_data_mask, filter->service_data_mask.data_len * sizeof(guint8), TRUE, NULL, NULL);
-
        if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS) {
                char address[BT_ADDRESS_STRING_SIZE] = { 0 };
                feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS;
 
                _bt_convert_addr_type_to_string(address, filter->device_address.addr);
 
+               arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
+               arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
+               arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
+               arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
+
                param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
                                        0,      // client_if
                                        0,      // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
                                        BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS,        // filter_type
-                                       slot_id,        // filter_index
+                                       *slot_id,       // filter_index
                                        0,      // company_id
                                        0,      // company_id_mask
                                        arr_uuid_param, // p_uuid
@@ -826,11 +895,20 @@ int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *fil
        if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME) {
                feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME;
 
+               arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
+               arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
+               arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
+               arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
+
                param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
                                        0,      // client_if
                                        0,      // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
                                        BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME,   // filter_type
-                                       slot_id,        // filter_index
+                                       *slot_id,       // filter_index
                                        0,      // company_id
                                        0,      // company_id_mask
                                        arr_uuid_param, // p_uuid
@@ -855,19 +933,26 @@ int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *fil
        if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID) {
                feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID;
 
+               arr_uuid = g_array_new(TRUE, TRUE, sizeof(guint8));
+               arr_uuid_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
+
                g_array_append_vals(arr_uuid, filter->service_uuid.data.data, filter->service_uuid.data_len * sizeof(guint8));
                g_array_append_vals(arr_uuid_mask, filter->service_uuid_mask.data.data, filter->service_uuid_mask.data_len * sizeof(guint8));
 
                arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
-                                            arr_uuid, filter->service_uuid.data_len * sizeof(guint8), TRUE, NULL, NULL);
+                                            arr_uuid->data, arr_uuid->len, TRUE, NULL, NULL);
                arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
-                                            arr_uuid, filter->service_uuid_mask.data_len * sizeof(guint8), TRUE, NULL, NULL);
+                                            arr_uuid_mask->data, arr_uuid_mask->len, TRUE, NULL, NULL);
+               arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
+               arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
 
                param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
                                        0,      // client_if
                                        0,      // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
                                        BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID,  // filter_type
-                                       slot_id,        // filter_index
+                                       *slot_id,       // filter_index
                                        0,      // company_id
                                        0,      // company_id_mask
                                        arr_uuid_param, // p_uuid
@@ -887,24 +972,36 @@ int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *fil
                }
                if (ret)
                        g_variant_unref(ret);
+
+               g_array_free(arr_uuid, TRUE);
+               g_array_free(arr_uuid_mask, TRUE);
+               g_array_free(arr_data, TRUE);
+               g_array_free(arr_data_mask, TRUE);
        }
 
        if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID) {
                feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID;
 
+               arr_uuid = g_array_new(TRUE, TRUE, sizeof(guint8));
+               arr_uuid_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
+
                g_array_append_vals(arr_uuid, filter->service_solicitation_uuid.data.data, filter->service_solicitation_uuid.data_len * sizeof(guint8));
                g_array_append_vals(arr_uuid_mask, filter->service_solicitation_uuid_mask.data.data, filter->service_solicitation_uuid_mask.data_len * sizeof(guint8));
 
                arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
-                                            arr_uuid, filter->service_solicitation_uuid.data_len * sizeof(guint8), TRUE, NULL, NULL);
+                                            arr_uuid->data, arr_uuid->len, TRUE, NULL, NULL);
                arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
-                                            arr_uuid, filter->service_solicitation_uuid_mask.data_len * sizeof(guint8), TRUE, NULL, NULL);
+                                            arr_uuid_mask->data, arr_uuid_mask->len, TRUE, NULL, NULL);
+               arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
+               arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
 
                param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
                                        0,      // client_if
                                        0,      // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
                                        BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID,     // filter_type
-                                       slot_id,        // filter_index
+                                       *slot_id,       // filter_index
                                        0,      // company_id
                                        0,      // company_id_mask
                                        arr_uuid_param, // p_uuid
@@ -924,24 +1021,34 @@ int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *fil
                }
                if (ret)
                        g_variant_unref(ret);
+
+               g_array_free(arr_uuid, TRUE);
+               g_array_free(arr_uuid_mask, TRUE);
        }
 
        if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA) {
                feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA;
 
+               arr_data = g_array_new(TRUE, TRUE, sizeof(guint8));
+               arr_data_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
+
                g_array_append_vals(arr_data, filter->service_data.data.data, filter->service_data.data_len * sizeof(guint8));
                g_array_append_vals(arr_data_mask, filter->service_data_mask.data.data, filter->service_data_mask.data_len * sizeof(guint8));
 
+               arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
+               arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
                arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
-                                            arr_uuid, filter->service_data.data_len * sizeof(guint8), TRUE, NULL, NULL);
+                                            arr_data->data, arr_data->len, TRUE, NULL, NULL);
                arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
-                                            arr_uuid, filter->service_data_mask.data_len * sizeof(guint8), TRUE, NULL, NULL);
+                                            arr_data_mask->data, arr_data_mask->len, TRUE, NULL, NULL);
 
                param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
                                        0,      // client_if
                                        0,      // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
                                        BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA,  // filter_type
-                                       slot_id,        // filter_index
+                                       *slot_id,       // filter_index
                                        0,      // company_id
                                        0,      // company_id_mask
                                        arr_uuid_param, // p_uuid
@@ -961,24 +1068,34 @@ int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *fil
                }
                if (ret)
                        g_variant_unref(ret);
+
+               g_array_free(arr_data, TRUE);
+               g_array_free(arr_data_mask, TRUE);
        }
 
        if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA) {
                feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA;
 
+               arr_data = g_array_new(TRUE, TRUE, sizeof(guint8));
+               arr_data_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
+
                g_array_append_vals(arr_data, filter->manufacturer_data.data.data, filter->manufacturer_data.data_len * sizeof(guint8));
                g_array_append_vals(arr_data_mask, filter->manufacturer_data_mask.data.data, filter->manufacturer_data_mask.data_len * sizeof(guint8));
 
+               arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
+               arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+                                                                                       NULL, 0, TRUE, NULL, NULL);
                arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
-                                            arr_uuid, filter->manufacturer_data.data_len * sizeof(guint8), TRUE, NULL, NULL);
+                                            arr_data->data, arr_data->len, TRUE, NULL, NULL);
                arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
-                                            arr_uuid, filter->manufacturer_data_mask.data_len * sizeof(guint8), TRUE, NULL, NULL);
+                                            arr_data_mask->data, arr_data_mask->len, TRUE, NULL, NULL);
 
                param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
                                        0,      // client_if
                                        0,      // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
                                        BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA,     // filter_type
-                                       slot_id,        // filter_index
+                                       *slot_id,       // filter_index
                                        filter->manufacturer_id,        // company_id
                                        0xFFFF, // company_id_mask
                                        arr_uuid_param, // p_uuid
@@ -998,19 +1115,17 @@ int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *fil
                }
                if (ret)
                        g_variant_unref(ret);
-       }
 
-       g_array_free(arr_uuid, TRUE);
-       g_array_free(arr_uuid_mask, TRUE);
-       g_array_free(arr_data, TRUE);
-       g_array_free(arr_data_mask, TRUE);
+               g_array_free(arr_data, TRUE);
+               g_array_free(arr_data_mask, TRUE);
+       }
 
        BT_DBG("Filter selection %.2x", feature_selection);
 
        param = g_variant_new("(iiiiiiiiiiii)",
                                0,      // client_if
                                0,      // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
-                               slot_id,        // filter_index
+                               *slot_id,       // filter_index
                                feature_selection,      // feat_seln
                                0,      // list_logic_type (OR - 0x00, AND - 0x01)
                                1,      // filt_logic_type (OR - 0x00, AND - 0x01)
@@ -1032,15 +1147,20 @@ int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *fil
        scanner = __bt_find_scanner_from_list(sender);
        if (scanner == NULL) {
                scanner = g_malloc0(sizeof(bt_adapter_le_scanner_t));
-               scanner->sender = strdup(sender);
-               scanner_list = g_slist_append(scanner_list, scanner);
+               if (scanner) {
+                       scanner->sender = strdup(sender);
+                       scanner_list = g_slist_append(scanner_list, scanner);
+               }
        }
 
        filter_data = g_malloc0(sizeof(bluetooth_le_scan_filter_t));
-       memcpy(filter_data, filter, sizeof(bluetooth_le_scan_filter_t));
-       filter_data->slot_id = *slot_id;
+       if (filter_data) {
+               memcpy(filter_data, filter, sizeof(bluetooth_le_scan_filter_t));
+               filter_data->slot_id = *slot_id;
 
-       scanner->filter_list = g_slist_append(scanner->filter_list, filter_data);
+               if (scanner)
+                       scanner->filter_list = g_slist_append(scanner->filter_list, filter_data);
+       }
 
        if (ret)
                g_variant_unref(ret);
@@ -1144,6 +1264,8 @@ int _bt_start_le_scan(const char *sender)
 
        if (scanner == NULL) {
                scanner = g_malloc0(sizeof(bt_adapter_le_scanner_t));
+               retv_if(scanner == NULL, BLUETOOTH_ERROR_INTERNAL);
+
                scanner->sender = strdup(sender);
                scanner_list = g_slist_append(scanner_list, scanner);
        }
@@ -1152,6 +1274,7 @@ int _bt_start_le_scan(const char *sender)
                BT_ERR("BT is already in LE scanning");
                return BLUETOOTH_ERROR_IN_PROGRESS;
        }
+       scanner->is_scanning = TRUE;
 
        proxy = _bt_get_adapter_proxy();
        retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
@@ -1178,14 +1301,12 @@ int _bt_start_le_scan(const char *sender)
                } else {
                        BT_INFO("LE Full Scan is already on progress");
                }
-
-               scanner->is_scanning = TRUE;
                return BLUETOOTH_ERROR_NONE;
        } else {
                if (is_le_set_scan_parameter == FALSE) {
                        /* Set default scan parameter same with BT_ADAPTER_LE_SCAN_MODE_LOW_ENERGY */
                        bluetooth_le_scan_params_t scan_params;
-                       scan_params.type = 1;
+                       scan_params.type = BT_LE_ACTIVE_SCAN;
                        scan_params.interval = 5000;
                        scan_params.window = 500;
                        _bt_set_scan_parameters(&scan_params);
@@ -1223,8 +1344,6 @@ int _bt_start_le_scan(const char *sender)
 
        if (ret)
                g_variant_unref(ret);
-
-       scanner->is_scanning = TRUE;
        return BLUETOOTH_ERROR_NONE;
 }
 
@@ -1814,3 +1933,225 @@ int _bt_clear_white_list(void)
        return BLUETOOTH_ERROR_NONE;
 }
 
+int _bt_initialize_ipsp(void)
+{
+       BT_DBG("+");
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       GVariant *ret;
+
+       if (_bt_adapter_get_status() != BT_ACTIVATED &&
+               _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
+               return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+       }
+
+       proxy = _bt_get_adapter_proxy();
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       ret = g_dbus_proxy_call_sync(proxy, "InitializeIpsp",
+                               NULL,G_DBUS_CALL_FLAGS_NONE,
+                               -1, NULL, &error);
+       if (error) {
+               BT_ERR("Initialize IPSP Failed :[%s]", error->message);
+               g_clear_error(&error);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+       if (ret)
+               g_variant_unref(ret);
+
+       BT_INFO("IPSP initialization called successfully");
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_deinitialize_ipsp(void)
+{
+       BT_DBG("+");
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       GVariant *ret;
+
+       if (_bt_adapter_get_status() != BT_ACTIVATED &&
+               _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
+               return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+       }
+
+       proxy = _bt_get_adapter_proxy();
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       ret = g_dbus_proxy_call_sync(proxy, "DeinitializeIpsp",
+                               NULL,G_DBUS_CALL_FLAGS_NONE,
+                               -1, NULL, &error);
+       if (error) {
+               BT_ERR("De-Initialize IPSP Failed :[%s]", error->message);
+               g_clear_error(&error);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+       if (ret)
+               g_variant_unref(ret);
+
+       BT_INFO("IPSP De-initialization called successfully");
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_le_read_maximum_data_length(
+               bluetooth_le_read_maximum_data_length_t *max_le_datalength)
+{
+       GError *error = NULL;
+       GDBusProxy *proxy;
+       GVariant *reply = NULL;
+       guint16 max_tx_octets, max_tx_time;
+       guint16 max_rx_octets, max_rx_time;
+
+       proxy = _bt_get_adapter_proxy();
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       reply = g_dbus_proxy_call_sync(proxy, "LEReadMaximumDataLength",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+       g_object_unref(proxy);
+
+       if (reply == NULL) {
+               BT_ERR("LEReadMaximumDataLength dBUS-RPC failed");
+               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;
+       }
+
+       g_variant_get(reply ,"(qqqq)", &max_tx_octets, &max_tx_time,
+                               &max_rx_octets, &max_rx_time);
+
+       max_le_datalength->max_tx_octets = max_tx_octets;
+       max_le_datalength->max_tx_time = max_tx_time;
+       max_le_datalength->max_rx_octets = max_rx_octets;
+       max_le_datalength->max_rx_time = max_rx_time;
+
+       g_variant_unref(reply);
+
+       return BLUETOOTH_ERROR_NONE;
+}
+int _bt_le_write_host_suggested_default_data_length(
+       const unsigned int def_tx_Octets, const unsigned int def_tx_Time)
+{
+       GError *error = NULL;
+       GDBusProxy *proxy;
+       GVariant *reply = NULL;
+
+       proxy = _bt_get_adapter_proxy();
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       reply = g_dbus_proxy_call_sync(proxy,
+                       "LEWriteHostSuggestedDataLength",
+                       g_variant_new("(qq)", def_tx_Octets, def_tx_Time),
+                       G_DBUS_CALL_FLAGS_NONE,
+                       -1,
+                       NULL,
+                       &error);
+
+       g_object_unref(proxy);
+
+       if (reply == NULL) {
+               BT_ERR("_bt_le_write_host_suggested_default_data_length dBUS-RPC failed");
+               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;
+       }
+
+       g_variant_unref(reply);
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_le_read_host_suggested_default_data_length(
+               bluetooth_le_read_host_suggested_data_length_t *def_data_length)
+{
+       GError *error = NULL;
+       GDBusProxy *proxy;
+       GVariant *reply = NULL;
+       guint16 def_tx_octets, def_tx_time;
+
+       proxy = _bt_get_adapter_proxy();
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       reply = g_dbus_proxy_call_sync(proxy, "LEReadHostSuggestedDataLength",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+       if (reply == NULL) {
+               BT_ERR("LEReadHostSuggestedDataLength dBUS-RPC failed");
+               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;
+       }
+
+       g_variant_get(reply ,"(qq)", &def_tx_octets, &def_tx_time);
+
+       def_data_length->def_tx_octets = def_tx_octets;
+       def_data_length->def_tx_time = def_tx_time;
+
+       g_variant_unref(reply);
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_le_set_data_length(bluetooth_device_address_t *device_address,
+       const unsigned int max_tx_Octets, const unsigned int max_tx_Time)
+{
+       GError *error = NULL;
+       guint16 txOctets = max_tx_Octets;
+       guint16 txTime = max_tx_Time;
+       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+       gchar *device_path = NULL;
+       GDBusConnection *conn;
+       GDBusProxy *device_proxy;
+
+       _bt_convert_addr_type_to_string(address, device_address->addr);
+
+       device_path = _bt_get_device_object_path(address);
+
+       if (device_path == NULL) {
+               BT_DBG("Device path is null");
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       conn = _bt_get_system_gconn();
+       if (conn == NULL) {
+               BT_ERR("conn == NULL");
+               g_free(device_path);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                                                               NULL, BT_BLUEZ_NAME,
+                                                               device_path, BT_DEVICE_INTERFACE,  NULL, NULL);
+
+       g_free(device_path);
+       retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       g_dbus_proxy_call_sync(device_proxy,
+                                       "LESetDataLength",
+                                       g_variant_new("(qq)", txOctets, txTime),
+                                       G_DBUS_CALL_FLAGS_NONE,
+                                       -1,
+                                       NULL,
+                                       &error);
+
+       g_object_unref(device_proxy);
+
+       if (error) {
+                BT_ERR("LESetDataLength error: [%s]", error->message);
+                g_error_free(error);
+                return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}