Fix TCT fail issue
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-adapter-le.c
index a489902..563b924 100644 (file)
@@ -52,6 +52,8 @@ typedef struct {
        int adv_inst_max;
        int rpa_offloading;
        int max_filter;
+       int le_2m_phy;
+       int le_coded_phy;
 } bt_adapter_le_feature_info_t;
 
 typedef struct {
@@ -178,15 +180,14 @@ void _bt_hal_set_advertising_status(int slot_id, gboolean mode)
 
 gboolean _bt_hal_is_advertising(void)
 {
-       gboolean status = FALSE;
        int i;
 
        for (i = 0; i < le_feature_info.adv_inst_max; i++) {
                if (le_adv_slot[i].is_advertising == TRUE)
-                       status = TRUE;
+                       return TRUE;
        }
 
-       return status;
+       return FALSE;
 }
 
 int _bt_hal_le_init(void)
@@ -198,7 +199,9 @@ void _bt_hal_le_deinit(void)
 {
        __bt_hal_free_le_adv_slot();
 }
-gboolean _bt_hal_update_le_feature_support(const char *item, const char *value)
+
+gboolean _bt_hal_update_le_feature_support(const char *item, const char *value,
+                       bt_local_le_features_t *le_features)
 {
        if (item == NULL || value == NULL)
                return FALSE;
@@ -220,12 +223,45 @@ gboolean _bt_hal_update_le_feature_support(const char *item, const char *value)
                        INFO("Advertising instance max : %d", le_feature_info.adv_inst_max);
                        le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max);
                }
+               /* Fill LE feature bytes */
+               le_features->max_adv_instance = atoi(value);
+
        } else if (g_strcmp0(item, "rpa_offloading") == 0) {
                le_feature_info.rpa_offloading = atoi(value);
                INFO("RPA offloading : %d", le_feature_info.rpa_offloading);
+
+               /* Fill LE feature bytes */
+               le_features->rpa_offload_supported = atoi(value);
+
        } else if (g_strcmp0(item, "max_filter") == 0) {
                le_feature_info.max_filter = atoi(value);
                INFO("BLE Scan max filter : %d", le_feature_info.max_filter);
+
+               /* Fill LE feature bytes */
+               le_features->max_adv_filter_supported = atoi(value);
+
+       } else if (g_strcmp0(item, "2m_phy") == 0) {
+               if (g_strcmp0(value, "true") == 0) {
+                       le_feature_info.le_2m_phy = TRUE;
+                       /* Fill LE feature bytes */
+                       le_features->le_2m_phy_supported = 0x1;
+               } else {
+                       le_feature_info.le_2m_phy = FALSE;
+                       /* Fill LE feature bytes */
+                       le_features->le_2m_phy_supported = 0x0;
+               }
+               INFO("2M PHY Supported [%s]",  le_feature_info.le_2m_phy ? "TRUE" : "FALSE");
+       } else if (g_strcmp0(item, "coded_phy") == 0) {
+               if (g_strcmp0(value, "true") == 0) {
+                       le_feature_info.le_coded_phy = TRUE;
+                       /* Fill LE feature bytes */
+                       le_features->le_coded_phy_supported = 0x1;
+               } else {
+                       le_feature_info.le_coded_phy = FALSE;
+                       /* Fill LE feature bytes */
+                       le_features->le_coded_phy_supported = 0x0;
+               }
+               INFO("CODED PHY Supported [%s]",  le_feature_info.le_coded_phy ? "TRUE" : "FALSE");
        } else {
                DBG("No registered item");
                return FALSE;
@@ -241,7 +277,7 @@ void _bt_hal_free_server_slot(int slot_id)
        memset(&le_adv_slot[slot_id], 0x00, sizeof(bt_adapter_le_adv_slot_t));
 }
 
-int _bt_hal_get_available_adv_slot_id(bt_uuid_t *uuid)
+int _bt_hal_get_available_adv_slot_id(bt_uuid_t *uuid, gboolean use_reserved_slot)
 {
        int i;
 
@@ -261,6 +297,14 @@ int _bt_hal_get_available_adv_slot_id(bt_uuid_t *uuid)
                }
        }
 
+       /* We should consider 'use_reverved_slot' in later */
+       if (le_feature_info.adv_inst_max <= 1)
+               i = 0;
+       else if (use_reserved_slot == TRUE)
+               i = 1;
+       else
+               i = 2;
+
        for (i = 0; i < le_feature_info.adv_inst_max; i++) {
                if (le_adv_slot[i].initialized == 0) {
                        DBG("Slot to be allocated [%d] UUID to be registered [%s]",
@@ -590,7 +634,7 @@ int _bt_hal_set_advertising_params(int server_if, int min_interval,
        max = max_interval / BT_HAL_ADV_INTERVAL_SPLIT;
 
        ret = g_dbus_proxy_call_sync(proxy, "SetAdvertisingParameters",
-                       g_variant_new("(uuuui)", min, max,
+                       g_variant_new("(uuuuii)", min, max,
                        BT_HAL_ADV_FILTER_POLICY_DEFAULT, adv_type,
                        server_if), G_DBUS_CALL_FLAGS_NONE,
                        -1, NULL, &error);
@@ -812,14 +856,21 @@ int _bt_hal_adapter_le_stop_scan(void)
                        -1, NULL, &error);
        if (ret == NULL) {
                if (error) {
+                       g_dbus_error_strip_remote_error(error);
                        ERR("StopLEDiscovery Fail: %s", error->message);
+
+                       /* Abnormal case for ARTIK530 */
+                       if (g_strrstr(error->message, "No discovery started") ||
+                                g_strrstr(error->message, "Operation already in progress")) {
+                               g_clear_error(&error);
+                               return BT_STATUS_SUCCESS;
+                       }
+
                        g_clear_error(&error);
+                       return BT_STATUS_FAIL;
                }
-
-               return BT_STATUS_FAIL;
        }
 
-
        g_variant_unref(ret);
 
        DBG("-");