Remove wrong dependency in the systemd service file
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-adapter-le.c
index 01aaad0..d85f6bb 100644 (file)
  */
 
 #include <stdio.h>
+#include <dbus/dbus.h>
 #include <gio/gio.h>
 #include <glib.h>
 #include <dlog.h>
 #include <string.h>
 #include <vconf.h>
 #include <syspopup_caller.h>
+#include <aul.h>
 
 #include "bt-internal-types.h"
 #include "bt-service-common.h"
@@ -78,7 +80,87 @@ 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 void __bt_free_le_adv_slot(void)
+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;
+       }
+}
+#if 0
+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);
+}
+#endif
+void _bt_send_char_value_changed_event(void *param)
+{
+#if 0
+       g_slist_foreach(gatt_client_senders, __bt_send_foreach_event,
+                                       (gpointer)param);
+#else
+       _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED, param);
+#endif
+}
+
+void __bt_free_le_adv_slot(void)
 {
        int i;
 
@@ -88,11 +170,36 @@ static void __bt_free_le_adv_slot(void)
        for (i = 0; i < le_feature_info.adv_inst_max; i++) {
                if (le_adv_slot[i].sender)
                        g_free(le_adv_slot[i].sender);
+               if (le_adv_slot[i].hold_timer_id > 0)
+                       g_source_remove(le_adv_slot[i].hold_timer_id);
        }
        g_free(le_adv_slot);
        le_adv_slot = NULL;
 }
 
+int _bt_le_set_max_packet_len(void)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       int tx_octets, tx_time;
+       bluetooth_le_read_maximum_data_length_t max_len = {0};
+
+       if (BLUETOOTH_ERROR_NONE != _bt_le_read_maximum_data_length(&max_len))
+               return BLUETOOTH_ERROR_INTERNAL;
+
+       if (max_len.max_tx_octets > BT_LE_TX_LEN_DEFAULT) {
+               tx_octets =  max_len.max_tx_octets > BT_LE_TX_LEN_MAX ?
+                               BT_LE_TX_LEN_MAX : max_len.max_tx_octets;
+               tx_time = BT_LE_TX_TIME_MAX;
+
+               result = _bt_le_write_host_suggested_default_data_length(tx_octets, tx_time);
+
+               BT_DBG("Wrote max packet size : result[%d], MAX[%d], set[%d]",
+                               result, max_len.max_tx_octets, tx_octets);
+       }
+
+       return result;
+}
+
 gboolean _bt_update_le_feature_support(const char *item, const char *value)
 {
        if (item == NULL || value == NULL)
@@ -179,9 +286,6 @@ int __bt_get_available_adv_slot_id(const char *sender, int adv_handle, gboolean
 
 static void __bt_register_adv_slot_owner(const char *sender, int adv_handle, int slot_id)
 {
-       if (le_adv_slot == NULL)
-               return;
-
        if (le_adv_slot[slot_id].sender == NULL) {
                le_adv_slot[slot_id].sender = strdup(sender);
                le_adv_slot[slot_id].adv_handle = adv_handle;
@@ -190,9 +294,6 @@ static void __bt_register_adv_slot_owner(const char *sender, int adv_handle, int
 
 void _bt_unregister_adv_slot_owner(int slot_id)
 {
-       if (le_adv_slot == NULL)
-               return;
-
        if (le_adv_slot[slot_id].hold_timer_id > 0) {
                BT_INFO("Hold state adv is not unregistered");
                return;
@@ -221,9 +322,6 @@ int _bt_get_adv_slot_adv_handle(int slot_id)
 
 void _bt_set_advertising_status(int slot_id, gboolean mode)
 {
-       if (le_adv_slot == NULL)
-               return;
-
        le_adv_slot[slot_id].is_advertising = mode;
 }
 
@@ -232,6 +330,9 @@ gboolean _bt_is_advertising(void)
        gboolean status = FALSE;
        int i;
 
+       if (le_adv_slot == NULL)
+               return FALSE;
+
        for (i = 0; i < le_feature_info.adv_inst_max; i++) {
                if (le_adv_slot[i].is_advertising == TRUE)
                        status = TRUE;
@@ -240,11 +341,6 @@ gboolean _bt_is_advertising(void)
        return status;
 }
 
-gboolean _bt_is_multi_adv_supported(void)
-{
-       return (le_feature_info.adv_inst_max > 1) ? TRUE : FALSE;
-}
-
 void _bt_stop_advertising_by_terminated_process(const char* terminated_name)
 {
        int i;
@@ -327,7 +423,7 @@ int _bt_set_advertising(const char *sender, int adv_handle, gboolean enable, gbo
                __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
 
        le_adv_slot[slot_id].is_advertising = enable;
-       BT_INFO_C("### Set advertising [%d]", enable);
+       BT_INFO_C("### Set advertising [%d], Slot id [%d]", enable, slot_id);
 
        if (ret)
                g_variant_unref(ret);
@@ -431,7 +527,7 @@ int _bt_set_custom_advertising(const char *sender, int adv_handle,
                __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
 
        le_adv_slot[slot_id].is_advertising = enable;
-       BT_INFO_C("### Set advertising [%d]", enable);
+       BT_INFO_C("### Set advertising [%d], Slot id [%d]", enable, slot_id);
        if (ret)
                g_variant_unref(ret);
 
@@ -999,8 +1095,6 @@ int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *fil
 
                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) {
@@ -1874,8 +1968,42 @@ void _bt_send_scan_result_event(const bt_remote_le_dev_info_t *le_dev_info,
                                        scan_data_len,
                                        scan_data_param);
 
+#if 0
                _bt_send_event_to_dest(scanner->sender, BT_LE_ADAPTER_EVENT,
                                BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND, param);
+#else
+               _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND, param);
+#endif
+       }
+}
+
+void _bt_send_ibeacon_scan_result_event(const bt_remote_ibeacon_dev_info_t *ibeacon_dev_info)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       GSList *l;
+       GVariant *param;
+       bt_adapter_le_scanner_t *scanner = NULL;
+
+       ret_if(ibeacon_dev_info == NULL);
+       BT_DBG("_bt_send_ibeacon_scan_result_event");
+
+       for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
+               scanner = l->data;
+               if (scanner->is_scanning == FALSE)
+                       continue;
+
+               param = g_variant_new("(isnnnsnnn)",
+                                       result,
+                                       ibeacon_dev_info->address,
+                                       ibeacon_dev_info->addr_type,
+                                       ibeacon_dev_info->company_id,
+                                       ibeacon_dev_info->ibeacon_type,
+                                       ibeacon_dev_info->uuid,
+                                       ibeacon_dev_info->major_id,
+                                       ibeacon_dev_info->minor_id,
+                                       ibeacon_dev_info->measured_power);
+
+               _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_REMOTE_IBEACON_DEVICE_FOUND, param);
        }
 }