le_adv_slot = NULL;
}
-int _bt_service_adapter_le_init(void)
-{
- le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_service_adapter_le_deinit(void)
-{
- __bt_free_le_adv_slot();
-}
-
gboolean _bt_update_le_feature_support(const char *item, const char *value)
{
if (item == NULL || value == NULL)
return FALSE;
+ if (!le_adv_slot)
+ _bt_service_adapter_le_init();
+
if (g_strcmp0(item, "adv_inst_max") == 0) {
int slot_num;
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;
+ }
+
g_free(le_adv_slot[slot_id].sender);
le_adv_slot[slot_id].sender = NULL;
le_adv_slot[slot_id].adv_handle = 0;
if (le_adv_slot[slot_id].is_advertising == TRUE && enable == TRUE)
return BLUETOOTH_ERROR_IN_PROGRESS;
- if (le_adv_slot[slot_id].sender != NULL && le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
- return BLUETOOTH_ERROR_NOT_IN_OPERATION;
-
if (le_adv_slot[slot_id].hold_timer_id > 0) {
g_source_remove(le_adv_slot[slot_id].hold_timer_id);
le_adv_slot[slot_id].hold_timer_id = 0;
+ _bt_unregister_adv_slot_owner(slot_id);
}
+ if (le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
+ return BLUETOOTH_ERROR_NOT_IN_OPERATION;
+
proxy = _bt_get_adapter_proxy();
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
if (le_adv_slot[slot_id].is_advertising == TRUE && enable == TRUE)
return BLUETOOTH_ERROR_IN_PROGRESS;
- if (le_adv_slot[slot_id].sender != NULL && le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
- return BLUETOOTH_ERROR_NOT_IN_OPERATION;
-
if (le_adv_slot[slot_id].hold_timer_id > 0) {
g_source_remove(le_adv_slot[slot_id].hold_timer_id);
le_adv_slot[slot_id].hold_timer_id = 0;
+ _bt_unregister_adv_slot_owner(slot_id);
}
+ if (le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
+ return BLUETOOTH_ERROR_NOT_IN_OPERATION;
+
proxy = _bt_get_adapter_proxy();
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
if (enable == TRUE)
__bt_register_adv_slot_owner(sender, adv_handle, slot_id);
- else
- _bt_unregister_adv_slot_owner(slot_id);
le_adv_slot[slot_id].is_advertising = enable;
BT_INFO_C("### Set advertising [%d]", enable);
le_adv_slot[0].hold_timer_id = g_timeout_add(2000,
__bt_hold_current_advertising_timeout_cb, NULL);
} else {
- BT_ERR("It's NOT advertising");
+ BT_INFO("It's NOT advertising");
return BLUETOOTH_ERROR_NOT_IN_OPERATION;
}
scanner = __bt_find_scanner_from_list(sender);
if (scanner == NULL) {
scanner = g_malloc0(sizeof(bt_adapter_le_scanner_t));
- scanner->sender = strdup(sender);
+ scanner->sender = g_strdup(sender);
scanner_list = g_slist_append(scanner_list, 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;
- if (scanner)
+ 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;
+
scanner->filter_list = g_slist_append(scanner->filter_list, filter_data);
+ }
if (ret)
g_variant_unref(ret);
if (scanner == NULL) {
scanner = g_malloc0(sizeof(bt_adapter_le_scanner_t));
- scanner->sender = strdup(sender);
+ scanner->sender = g_strdup(sender);
scanner_list = g_slist_append(scanner_list, scanner);
}
}
}
+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;
+}
+
void _bt_set_le_scan_status(gboolean mode)
{
is_le_scanning = mode;
return BLUETOOTH_ERROR_NONE;
}
+
+int _bt_service_adapter_le_init(void)
+{
+ le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+void _bt_service_adapter_le_deinit(void)
+{
+ __bt_free_le_adv_slot();
+ __bt_free_le_scanner();
+}