char *sender;
GSList *filter_list;
gboolean is_scanning;
- gboolean stop_pending;
} bt_adapter_le_scanner_t;
static bluetooth_advertising_params_t adv_params = {
le_adv_slot = NULL;
}
+static void __bt_free_le_scanner(bt_adapter_le_scanner_t *scanner)
+{
+ g_free(scanner->sender);
+ g_slist_free_full(scanner->filter_list, g_free);
+ g_free(scanner);
+}
+
+static void __bt_free_le_scanner_all(void)
+{
+ g_slist_free_full(scanner_list, (GDestroyNotify)__bt_free_le_scanner);
+ scanner_list = NULL;
+
+ scan_filter_enabled = FALSE;
+ is_le_scanning = FALSE;
+ is_le_set_scan_parameter = FALSE;
+ le_scan_params.type = BT_LE_ACTIVE_SCAN;
+ le_scan_params.interval = 0;
+ le_scan_params.window = 0;
+}
+
int _bt_le_set_max_packet_len(void)
{
int result = BLUETOOTH_ERROR_NONE;
return NULL;
}
-int __bt_get_available_scan_filter_slot_id(void)
+static int __bt_get_available_scan_filter_slot_id(void)
{
GSList *l;
bt_adapter_le_scanner_t *scanner;
return FALSE;
}
-int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *filter, int *slot_id)
+int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *filter)
{
GDBusProxy *proxy;
GError *error = NULL;
bt_adapter_le_scanner_t *scanner = NULL;
bluetooth_le_scan_filter_t *filter_data = NULL;
int feature_selection = 0;
+ int slot_id;
- *slot_id = __bt_get_available_scan_filter_slot_id();
- if (*slot_id == -1)
+ slot_id = __bt_get_available_scan_filter_slot_id();
+ if (slot_id == -1)
return BLUETOOTH_ERROR_NO_RESOURCES;
proxy = _bt_get_adapter_proxy();
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
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
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
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
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
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
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)
if (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;
+ filter_data->slot_id = slot_id;
scanner->filter_list = g_slist_append(scanner->filter_list, filter_data);
}
return BLUETOOTH_ERROR_NONE;
}
-int _bt_unregister_scan_filter(const char *sender, int slot_id)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret;
- bt_adapter_le_scanner_t *scanner = NULL;
- bluetooth_le_scan_filter_t *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)) {
- filter_data = l->data;
- if (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;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_clear",
- g_variant_new("(ii)", 0, slot_id),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_clear Fail: %s", error->message);
- g_clear_error(&error);
- }
-
- scanner->filter_list = g_slist_remove(scanner->filter_list, filter_data);
- g_free(filter_data);
-
- if (ret)
- g_variant_unref(ret);
- return BLUETOOTH_ERROR_NONE;
-}
-
int _bt_unregister_all_scan_filters(const char *sender)
{
GDBusProxy *proxy;
return BLUETOOTH_ERROR_NONE;
}
-static gboolean __start_le_scan_timeout(gpointer user_data)
-{
- char *sender = (char *)user_data;
- _bt_start_le_scan(sender);
-
- return FALSE;
-}
-
-
int _bt_start_le_scan(const char *sender)
{
GDBusProxy *proxy;
scanner_list = g_slist_append(scanner_list, scanner);
}
- if (scanner->stop_pending == TRUE) {
- BT_DBG("Waiting LEDiscoveryFinished");
- g_timeout_add(500, (GSourceFunc)__start_le_scan_timeout, scanner->sender);
- return BLUETOOTH_ERROR_NONE;
- }
-
if (scanner->is_scanning == TRUE) {
BT_ERR("BT is already in LE scanning");
return BLUETOOTH_ERROR_IN_PROGRESS;
GDBusProxy *proxy;
GError *error = NULL;
GVariant *ret;
- bt_adapter_le_scanner_t *scan_sender = __bt_find_scanner_from_list(sender);
- bt_adapter_le_scanner_t *scanner;
+ bt_adapter_le_scanner_t *scanner = __bt_find_scanner_from_list(sender);
GSList *l;
gboolean next_scanning = FALSE;
gboolean need_scan_filter = TRUE;
- if (scan_sender == NULL || scan_sender->is_scanning == FALSE)
+ if (scanner == NULL || scanner->is_scanning == FALSE)
return BLUETOOTH_ERROR_NOT_IN_OPERATION;
- scan_sender->is_scanning = FALSE;
- scan_sender->stop_pending = TRUE;
+ _bt_unregister_all_scan_filters(sender);
+
+ scanner_list = g_slist_remove(scanner_list, scanner);
+ __bt_free_le_scanner(scanner);
for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
scanner = l->data;
scan_filter_enabled = TRUE;
}
BT_INFO("next_scanning exists. Keep the LE scanning");
- scan_sender->stop_pending = FALSE;
return BLUETOOTH_ERROR_NONE;
} else {
if (scan_filter_enabled == TRUE) {
for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
scanner = l->data;
scanner->is_scanning = FALSE;
- scanner->stop_pending = FALSE;
}
}
-static void __bt_free_le_scanner(void)
-{
- GSList *l;
- bt_adapter_le_scanner_t *scanner;
-
- for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
- scanner = l->data;
- g_free(scanner->sender);
- g_slist_free_full(scanner->filter_list, g_free);
- g_free(scanner);
- }
-
- g_slist_free(scanner_list);
- scanner_list = NULL;
-
- scan_filter_enabled = FALSE;
- is_le_scanning = FALSE;
- is_le_set_scan_parameter = FALSE;
- le_scan_params.type = BT_LE_ACTIVE_SCAN;
- le_scan_params.interval = 0;
- le_scan_params.window = 0;
-}
-
void _bt_set_le_scan_status(gboolean mode)
{
BT_DBG("set is_le_scanning : %d -> %d", is_le_scanning, mode);
void _bt_service_adapter_le_deinit(void)
{
__bt_free_le_adv_slot();
- __bt_free_le_scanner();
+ __bt_free_le_scanner_all();
}