static bt_scan_filter_h pxp_immediate_alert_filter;
static bt_scan_filter_h pxp_signal_loss_filter;
-static GSList *advertiser_list = NULL;
+static GSList *advertiser_list;
+static GSList *scan_filter_list;
+static int scan_filter_id;
/* LCOV_EXCL_START */
int bt_adapter_enable(void)
}
}
}
+
+static bt_le_scan_filter_s *__bt_adapter_le_duplicate_scan_filter(
+ const bt_le_scan_filter_s *src)
+{
+ bt_le_scan_filter_s *filter = g_malloc0(sizeof(bt_le_scan_filter_s));
+
+ filter->filter_id = src->filter_id;
+ filter->device_address = g_strdup(src->device_address);
+ filter->device_name = g_strdup(src->device_name);
+ filter->service_uuid = g_strdup(src->service_uuid);
+ filter->service_uuid_mask = g_strdup(src->service_uuid_mask);
+ filter->service_solicitation_uuid = g_strdup(src->service_solicitation_uuid);
+ filter->service_solicitation_uuid_mask = g_strdup(src->service_solicitation_uuid_mask);
+ filter->service_data_uuid = g_strdup(src->service_data_uuid);
+ filter->service_data = g_memdup(src->service_data, src->service_data_len);
+ filter->service_data_len = src->service_data_len;
+ filter->service_data_mask = g_memdup(src->service_data_mask, src->service_data_len);
+ filter->manufacturer_id = src->manufacturer_id;
+ filter->manufacturer_data = g_memdup(src->manufacturer_data, src->manufacturer_data_len);
+ filter->manufacturer_data_len = src->manufacturer_data_len;
+ filter->manufacturer_data_mask = g_memdup(src->manufacturer_data_mask, src->manufacturer_data_len);
+
+ return filter;
+}
+
+static void __bt_adapter_le_free_scan_filter(bt_le_scan_filter_s *filter)
+{
+ if (filter == NULL)
+ return;
+
+ g_free(filter->device_address);
+ g_free(filter->device_name);
+ g_free(filter->service_uuid);
+ g_free(filter->service_uuid_mask);
+ g_free(filter->service_solicitation_uuid);
+ g_free(filter->service_solicitation_uuid_mask);
+ g_free(filter->service_data_uuid);
+ g_free(filter->service_data);
+ g_free(filter->service_data_mask);
+ g_free(filter->manufacturer_data);
+ g_free(filter->manufacturer_data_mask);
+ g_free(filter);
+}
/* LCOV_EXCL_STOP */
int bt_adapter_le_start_scan(bt_adapter_le_scan_result_cb cb, void *user_data)
{
int error_code = BT_ERROR_NONE;
+ GSList *l;
BT_CHECK_LE_SUPPORT();
BT_CHECK_INIT_STATUS();
_bt_le_adapter_init();
+ for (l = scan_filter_list; l != NULL; l = l->next) {
+ bluetooth_le_scan_filter_t filter;
+ bt_le_scan_filter_s *__filter = l->data;
+ __bt_adapter_le_convert_scan_filter(&filter, __filter);
+
+ error_code = _bt_get_error_code(bluetooth_register_scan_filter(&filter));
+ if (error_code != BT_ERROR_NONE) {
+ BT_ERR("Scan filter error %s(0x%08x)",
+ _bt_convert_error_to_string(error_code),
+ error_code); /* LCOV_EXCL_LINE */
+ }
+ }
+
error_code = _bt_get_error_code(bluetooth_start_le_discovery());
if (error_code != BT_ERROR_NONE) {
BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); /* LCOV_EXCL_LINE */
__filter = (bt_le_scan_filter_s *)g_malloc0(sizeof(bt_le_scan_filter_s));
+ __filter->filter_id = scan_filter_id++;
__filter->manufacturer_id = -1;
*scan_filter = (bt_scan_filter_h)__filter;
BT_CHECK_INIT_STATUS();
BT_CHECK_INPUT_PARAMETER(scan_filter);
- g_free(__filter->device_address);
- g_free(__filter->device_name);
- g_free(__filter->service_uuid);
- g_free(__filter->service_uuid_mask);
- g_free(__filter->service_solicitation_uuid);
- g_free(__filter->service_solicitation_uuid_mask);
- g_free(__filter->service_data_uuid);
- g_free(__filter->service_data);
- g_free(__filter->service_data_mask);
- g_free(__filter->manufacturer_data);
- g_free(__filter->manufacturer_data_mask);
- g_free(__filter);
+ __bt_adapter_le_free_scan_filter(__filter);
return BT_ERROR_NONE;
}
int bt_adapter_le_scan_filter_register(bt_scan_filter_h scan_filter)
{
- int error_code = BT_ERROR_NONE;
bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter;
- bluetooth_le_scan_filter_t filter;
+ GSList *l;
BT_CHECK_LE_SUPPORT();
BT_CHECK_INIT_STATUS();
return BT_ERROR_NOW_IN_PROGRESS;
}
- __bt_adapter_le_convert_scan_filter(&filter, __filter);
-
- error_code = _bt_get_error_code(bluetooth_register_scan_filter(&filter,
- &__filter->slot_id));
-
-#ifdef TIZEN_FEATURE_TCT_TMP_SUPPORT
- if (error_code == BT_ERROR_NOT_SUPPORTED)
- error_code = BT_ERROR_NONE;
-#endif
-
- if (error_code != BT_ERROR_NONE) {
- BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
- error_code); /* LCOV_EXCL_LINE */
+ for (l = scan_filter_list; l != NULL; l = l->next) {
+ bt_le_scan_filter_s *filter = l->data;
+ if (__filter->filter_id == filter->filter_id) {
+ scan_filter_list = g_slist_remove(scan_filter_list, filter);
+ __bt_adapter_le_free_scan_filter(filter);
+ break;
+ }
}
- return error_code;
+ scan_filter_list = g_slist_append(scan_filter_list,
+ __bt_adapter_le_duplicate_scan_filter(__filter));
+
+ return BT_ERROR_NONE;
}
int bt_adapter_le_scan_filter_unregister(bt_scan_filter_h scan_filter)
{
- int error_code = BT_ERROR_NONE;
bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter;
+ GSList *l;
BT_CHECK_LE_SUPPORT();
BT_CHECK_INIT_STATUS();
return BT_ERROR_NOW_IN_PROGRESS;
}
- error_code = _bt_get_error_code(bluetooth_unregister_scan_filter(__filter->slot_id));
-
-#ifdef TIZEN_FEATURE_TCT_TMP_SUPPORT
- if (error_code == BT_ERROR_NOT_SUPPORTED)
- error_code = BT_ERROR_NONE;
-#endif
- if (error_code != BT_ERROR_NONE) {
- BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
- error_code); /* LCOV_EXCL_LINE */
+ for (l = scan_filter_list; l != NULL; l = l->next) {
+ bt_le_scan_filter_s *filter = l->data;
+ if (__filter->filter_id == filter->filter_id) {
+ scan_filter_list = g_slist_remove(scan_filter_list, filter);
+ __bt_adapter_le_free_scan_filter(filter);
+ break;
+ }
}
- return error_code;
+ return BT_ERROR_NONE;
}
int bt_adapter_le_scan_filter_unregister_all(void)
return BT_ERROR_NOW_IN_PROGRESS;
}
- error_code = _bt_get_error_code(bluetooth_unregister_all_scan_filters());
-
-#ifdef TIZEN_FEATURE_TCT_TMP_SUPPORT
- if (error_code == BT_ERROR_NOT_SUPPORTED)
- error_code = BT_ERROR_NONE;
-#endif
- if (error_code != BT_ERROR_NONE) {
- BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code),
- error_code); /* LCOV_EXCL_LINE */
- }
+ g_slist_free_full(scan_filter_list, (GDestroyNotify)__bt_adapter_le_free_scan_filter);
+ scan_filter_list = NULL;
return error_code;
}