Adapt the unregister scan filter functionality into BT-HAL framework 55/216155/3
authorhimanshu <h.himanshu@samsung.com>
Mon, 21 Oct 2019 08:58:56 +0000 (14:28 +0530)
committerhimanshu <h.himanshu@samsung.com>
Tue, 22 Oct 2019 05:27:58 +0000 (10:57 +0530)
This API unregisters a registered scan filter.

Change-Id: I2bfe2a55970b4e4a31df777e889a25c2387e89c0
Signed-off-by: himanshu <h.himanshu@samsung.com>
bt-oal/bluez_hal/src/bt-hal-gatt-client.c
bt-oal/include/oal-gatt.h
bt-oal/oal-gatt.c
bt-service-adaptation/services/adapter/bt-service-core-adapter-le.c
bt-service-adaptation/services/bt-request-handler.c
bt-service-adaptation/services/include/bt-service-core-adapter-le.h

index 9e6bcd5..632d221 100644 (file)
@@ -2740,8 +2740,28 @@ bt_status_t scan_filter_add_remove(int client_if, int action, int filt_type,
 /** Clear all scan filter conditions for specific filter index*/
 bt_status_t scan_filter_clear(int client_if, int filt_index)
 {
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       GVariant *ret;
        CHECK_BTGATT_INIT();
-       return BT_STATUS_UNSUPPORTED;
+
+       proxy = _bt_hal_get_adapter_proxy();
+       if (proxy == NULL)
+               return BT_STATUS_FAIL;
+
+       ret = g_dbus_proxy_call_sync(proxy, "scan_filter_clear",
+                               g_variant_new("(ii)", client_if, filt_index),
+                               G_DBUS_CALL_FLAGS_NONE,
+                               -1, NULL, &error);
+
+       if (error) {
+               ERR("scan_filter_clear Fail: %s", error->message);
+               g_clear_error(&error);
+               return BT_STATUS_FAIL;
+       }
+       if (ret)
+               g_variant_unref(ret);
+       return BT_STATUS_SUCCESS;
 }
 
 /** Enable / disable scan filter feature*/
index 238bc57..090c0c4 100644 (file)
@@ -445,6 +445,8 @@ oal_status_t gattc_write_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id, oa
 
 oal_status_t gattc_disconnect(int client_id, bt_address_t *device_address, int conn_id);
 
+oal_status_t gattc_unregister_scan_filter(int slot_id);
+
 oal_status_t gattc_conn_param_update(bt_address_t * address, int min, int max, int latency, int timeout);
 
 oal_status_t gattc_register_for_notification(int client_id, bt_address_t * address,
index 61c9e09..000439e 100644 (file)
@@ -2152,3 +2152,21 @@ oal_status_t gattc_conn_param_update(bt_address_t * address, int min, int max, i
        }
        return OAL_STATUS_SUCCESS;
 }
+
+oal_status_t gattc_unregister_scan_filter(int slot_id)
+{
+       int ret;
+       int client_if = 0;
+
+       API_TRACE("");
+       CHECK_OAL_GATT_ENABLED();
+
+       BT_INFO("Remove Scan filter Slot ID is: [%d]", slot_id);
+
+       ret = gatt_api->client->scan_filter_clear(client_if, slot_id);
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("error: %s", status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+       return OAL_STATUS_SUCCESS;
+}
index f2e41bd..cd62f3f 100644 (file)
@@ -735,6 +735,41 @@ static void __bt_le_event_handler(int event_type, gpointer event_data)
        }
 }
 
+int _bt_unregister_scan_filter(const char *sender, int slot_id)
+{
+       int ret;
+       bt_adapter_le_scanner_t *scanner = NULL;
+       bluetooth_le_scan_filter_t *scan_filter_data = NULL;
+       GSList *l;
+       gboolean is_slot_id_found = FALSE;
+
+       scanner = __bt_find_scanner_from_list(sender);
+       if (scanner == NULL) {
+               BT_ERR("There is NO available scanner.");
+               return BLUETOOTH_ERROR_NOT_FOUND;
+       }
+
+       for (l = scanner->filter_list; l != NULL; l = g_slist_next(l)) {
+               scan_filter_data = l->data;
+               if (scan_filter_data->slot_id == slot_id) {
+                       is_slot_id_found = TRUE;
+                       break;
+               }
+       }
+       if (is_slot_id_found == FALSE) {
+               BT_ERR("There is NO registered slot.");
+               return BLUETOOTH_ERROR_NOT_FOUND;
+       }
+       ret = gattc_unregister_scan_filter(slot_id);
+       if (OAL_STATUS_SUCCESS != ret) {
+               BT_ERR("gattc_unregister_scan_filter failed");
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+       scanner->filter_list = g_slist_remove(scanner->filter_list, scan_filter_data);
+       g_free(scan_filter_data);
+       return BLUETOOTH_ERROR_NONE;
+}
+
 int _bt_le_init(void)
 {
        BT_DBG("+");
index d0c369c..635efc7 100644 (file)
@@ -3136,6 +3136,18 @@ normal:
                g_array_append_vals(*out_param1, &is_coded_phy_supported, sizeof(gboolean));
                break;
        }
+       case BT_UNREGISTER_SCAN_FILTER:{
+               char *sender = NULL;
+               int slot_id;
+
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
+               __bt_service_get_parameters(in_param1, &slot_id, sizeof(int));
+               BT_DBG("Remove scan filter [Slot ID : %d]", slot_id);
+
+               result = _bt_unregister_scan_filter(sender, slot_id);
+
+               break;
+       }
        case BT_DISCONNECT_DEVICE: {
                bluetooth_device_address_t address = { {0} };
 
index a505a19..8807201 100644 (file)
@@ -100,6 +100,8 @@ int _bt_set_le_privacy(gboolean set_privacy);
 int _bt_set_white_list(bluetooth_device_address_t *device_address, int address_type, bool is_add);
 
 int _bt_set_manufacturer_data(bluetooth_manufacturer_data_t *m_data);
+
+int _bt_unregister_scan_filter(const char *sender, int slot_id);
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */