2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <syspopup_caller.h>
26 #include "bt-internal-types.h"
27 #include "bt-service-common.h"
28 #include "bt-service-event.h"
29 #include "bt-service-adapter.h"
30 #include "bt-service-adapter-le.h"
31 #include "bt-service-util.h"
34 #define BT_ADV_INTERVAL_MIN 20 /* msec */
35 #define BT_ADV_INTERVAL_MAX 10240
36 #define BT_ADV_INTERVAL_SPLIT 0.625
37 #define BT_DEFAULT_ADV_MIN_INTERVAL 500
38 #define BT_DEFAULT_ADV_MAX_INTERVAL 500
39 #define BT_ADV_FILTER_POLICY_DEFAULT 0x00
40 #define BT_ADV_TYPE_DEFAULT 0x00
41 #define BT_ADV_FILTER_POLICY_ALLOW_SCAN_CONN_WL_ONLY 0x03
42 #define BT_ADV_MULTI_MAX 16
48 } bt_adapter_le_feature_info_t;
53 gboolean is_advertising;
55 } bt_adapter_le_adv_slot_t;
61 } bt_adapter_le_scanner_t;
63 static bluetooth_advertising_params_t adv_params = {
64 BT_DEFAULT_ADV_MIN_INTERVAL,
65 BT_DEFAULT_ADV_MAX_INTERVAL,
66 BT_ADV_FILTER_POLICY_DEFAULT,
68 static bluetooth_advertising_data_t adv_data = { {0} };
69 static int adv_data_len;
70 static bluetooth_scan_resp_data_t resp_data = { {0} };
71 static int resp_data_len;
73 static bt_adapter_le_feature_info_t le_feature_info = { 1, 0, 0 };
74 static bt_adapter_le_adv_slot_t *le_adv_slot = NULL;
76 GSList *scanner_list = NULL;
77 static gboolean is_le_set_scan_parameter = FALSE;
78 static gboolean is_le_scanning = FALSE;
79 static gboolean scan_filter_enabled = FALSE;
80 static bt_le_scan_type_t le_scan_type = BT_LE_PASSIVE_SCAN;
82 static void __bt_free_le_adv_slot(void)
86 if (le_adv_slot == NULL)
89 for (i = 0; i < le_feature_info.adv_inst_max; i++) {
90 if (le_adv_slot[i].sender)
91 g_free(le_adv_slot[i].sender);
97 gboolean _bt_update_le_feature_support(const char *item, const char *value)
99 if (item == NULL || value == NULL)
103 _bt_service_adapter_le_init();
105 if (g_strcmp0(item, "adv_inst_max") == 0) {
108 slot_num = atoi(value);
109 retv_if(slot_num < 0, FALSE);
110 retv_if(slot_num > BT_ADV_MULTI_MAX, FALSE);
112 if (slot_num != le_feature_info.adv_inst_max) {
113 __bt_free_le_adv_slot();
114 le_feature_info.adv_inst_max = slot_num;
115 BT_INFO("Advertising instance max : %d", le_feature_info.adv_inst_max);
116 le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max);
118 } else if (g_strcmp0(item, "rpa_offloading") == 0) {
119 le_feature_info.rpa_offloading = atoi(value);
120 BT_INFO("RPA offloading : %d", le_feature_info.rpa_offloading);
121 } else if (g_strcmp0(item, "max_filter") == 0) {
122 le_feature_info.max_filter = atoi(value);
123 BT_INFO("BLE Scan max filter : %d", le_feature_info.max_filter);
125 BT_DBG("No registered item");
132 static gboolean __bt_is_factory_test_mode(void)
136 if (vconf_get_bool(VCONFKEY_BT_DUT_MODE, &mode)) {
137 BT_ERR("Get the DUT Mode fail");
142 BT_INFO("DUT Test Mode !!");
149 int __bt_get_available_adv_slot_id(const char *sender, int adv_handle, gboolean use_reserved_slot)
153 if (le_adv_slot == NULL) {
154 BT_ERR("le_adv_slot is NULL");
158 BT_DBG("adv_inst_max : %d", le_feature_info.adv_inst_max);
160 for (i = 0; i < le_feature_info.adv_inst_max; i++) {
161 if (le_adv_slot[i].sender == NULL)
163 if ((g_strcmp0(le_adv_slot[i].sender, sender) == 0) && (le_adv_slot[i].adv_handle == adv_handle))
167 if (le_feature_info.adv_inst_max <= 2)
169 else if (le_feature_info.adv_inst_max > 2 && use_reserved_slot == TRUE)
174 for (; i < le_feature_info.adv_inst_max; i++) {
175 if (le_adv_slot[i].sender == NULL)
182 static void __bt_register_adv_slot_owner(const char *sender, int adv_handle, int slot_id)
184 if (le_adv_slot == NULL)
187 if (le_adv_slot[slot_id].sender == NULL) {
188 le_adv_slot[slot_id].sender = strdup(sender);
189 le_adv_slot[slot_id].adv_handle = adv_handle;
193 void _bt_unregister_adv_slot_owner(int slot_id)
195 if (le_adv_slot == NULL)
198 if (le_adv_slot[slot_id].hold_timer_id > 0) {
199 BT_INFO("Hold state adv is not unregistered");
203 g_free(le_adv_slot[slot_id].sender);
204 le_adv_slot[slot_id].sender = NULL;
205 le_adv_slot[slot_id].adv_handle = 0;
208 const char* _bt_get_adv_slot_owner(int slot_id)
210 if (le_adv_slot == NULL)
213 return le_adv_slot[slot_id].sender;
216 int _bt_get_adv_slot_adv_handle(int slot_id)
218 if (le_adv_slot == NULL)
221 return le_adv_slot[slot_id].adv_handle;
224 void _bt_set_advertising_status(int slot_id, gboolean mode)
226 if (le_adv_slot == NULL)
229 le_adv_slot[slot_id].is_advertising = mode;
232 gboolean _bt_is_advertising(void)
234 gboolean status = FALSE;
237 for (i = 0; i < le_feature_info.adv_inst_max; i++) {
238 if (le_adv_slot[i].is_advertising == TRUE)
245 gboolean _bt_is_multi_adv_supported(void)
247 return (le_feature_info.adv_inst_max > 1) ? TRUE : FALSE;
250 void _bt_stop_advertising_by_terminated_process(const char* terminated_name)
254 if (le_adv_slot == NULL)
257 for (i = 0; i < le_feature_info.adv_inst_max; i++) {
258 if (le_adv_slot[i].sender != NULL) {
259 if (strcasecmp(terminated_name, le_adv_slot[i].sender) == 0) {
260 BT_ERR("Stop advertising by terminated process(%s).", terminated_name);
261 _bt_set_advertising(terminated_name, le_adv_slot[i].adv_handle, FALSE, FALSE);
267 gboolean _bt_get_advertising_params(bluetooth_advertising_params_t *params)
272 memcpy(params, &adv_params, sizeof(bluetooth_advertising_params_t));
277 int _bt_set_advertising(const char *sender, int adv_handle, gboolean enable, gboolean use_reserved_slot)
280 GError *error = NULL;
284 if (__bt_is_factory_test_mode()) {
285 BT_ERR("Unable to start advertising in factory binary !!");
286 return BLUETOOTH_ERROR_NOT_SUPPORT;
289 if (_bt_adapter_get_status() != BT_ACTIVATED &&
290 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
291 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
294 slot_id = __bt_get_available_adv_slot_id(sender, adv_handle, use_reserved_slot);
296 BT_ERR("There is NO available slot!!");
297 return BLUETOOTH_ERROR_NO_RESOURCES;
300 if (le_adv_slot[slot_id].is_advertising == TRUE && enable == TRUE)
301 return BLUETOOTH_ERROR_IN_PROGRESS;
303 if (le_adv_slot[slot_id].hold_timer_id > 0) {
304 g_source_remove(le_adv_slot[slot_id].hold_timer_id);
305 le_adv_slot[slot_id].hold_timer_id = 0;
306 _bt_unregister_adv_slot_owner(slot_id);
309 if (le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
310 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
312 proxy = _bt_get_adapter_proxy();
313 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
315 ret = g_dbus_proxy_call_sync(proxy, "SetAdvertising",
316 g_variant_new("(bi)", enable, slot_id),
317 G_DBUS_CALL_FLAGS_NONE,
323 BT_ERR("SetAdvertising Fail: %s", error->message);
324 g_clear_error(&error);
325 return BLUETOOTH_ERROR_INTERNAL;
329 __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
331 le_adv_slot[slot_id].is_advertising = enable;
332 BT_INFO_C("### Set advertising [%d]", enable);
335 g_variant_unref(ret);
337 return BLUETOOTH_ERROR_NONE;
340 int _bt_set_custom_advertising(const char *sender, int adv_handle,
341 gboolean enable, bluetooth_advertising_params_t *params, gboolean use_reserved_slot)
345 GError *error = NULL;
350 BT_CHECK_PARAMETER(params, return);
352 if (__bt_is_factory_test_mode()) {
353 BT_ERR("Unable to start advertising in factory binary !!");
354 return BLUETOOTH_ERROR_NOT_SUPPORT;
357 if (_bt_adapter_get_status() != BT_ACTIVATED &&
358 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
359 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
362 slot_id = __bt_get_available_adv_slot_id(sender, adv_handle, use_reserved_slot);
364 BT_ERR("There is NO available slot!!");
365 return BLUETOOTH_ERROR_NO_RESOURCES;
368 if (le_adv_slot[slot_id].is_advertising == TRUE && enable == TRUE)
369 return BLUETOOTH_ERROR_IN_PROGRESS;
371 if (le_adv_slot[slot_id].hold_timer_id > 0) {
372 g_source_remove(le_adv_slot[slot_id].hold_timer_id);
373 le_adv_slot[slot_id].hold_timer_id = 0;
374 _bt_unregister_adv_slot_owner(slot_id);
377 if (le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
378 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
380 proxy = _bt_get_adapter_proxy();
381 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
383 if (params->interval_min > params->interval_max ||
384 params->interval_min < BT_ADV_INTERVAL_MIN ||
385 params->interval_max > BT_ADV_INTERVAL_MAX)
386 return BLUETOOTH_ERROR_INVALID_PARAM;
388 if (params->filter_policy > BLUETOOTH_ALLOW_SCAN_CONN_WHITE_LIST)
389 return BLUETOOTH_ERROR_INVALID_PARAM;
391 if (params->type == BLUETOOTH_ADV_CONNECTABLE_DIRECT_HIGH ||
392 params->type == BLUETOOTH_ADV_CONNECTABLE_DIRECT_LOW ||
393 params->type == BLUETOOTH_ADV_NON_CONNECTABLE)
394 return BLUETOOTH_ERROR_NOT_SUPPORT;
396 min = params->interval_min / BT_ADV_INTERVAL_SPLIT;
397 max = params->interval_max / BT_ADV_INTERVAL_SPLIT;
399 ret = g_dbus_proxy_call_sync(proxy, "SetAdvertisingParameters",
400 g_variant_new("(uuuui)", min, max,
401 params->filter_policy, params->type,
402 slot_id), G_DBUS_CALL_FLAGS_NONE,
406 BT_ERR("SetAdvertisingParameters Fail: %s", error->message);
407 g_clear_error(&error);
408 return BLUETOOTH_ERROR_INTERNAL;
411 adv_params.interval_min = params->interval_min;
412 adv_params.interval_max = params->interval_max;
413 adv_params.filter_policy = params->filter_policy;
414 adv_params.type = params->type;
417 g_variant_unref(ret);
419 ret = g_dbus_proxy_call_sync(proxy, "SetAdvertising",
420 g_variant_new("(bi)", enable, slot_id),
421 G_DBUS_CALL_FLAGS_NONE,
427 BT_ERR("SetAdvertising Fail: %s", error->message);
428 g_clear_error(&error);
429 return BLUETOOTH_ERROR_INTERNAL;
433 __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
435 le_adv_slot[slot_id].is_advertising = enable;
436 BT_INFO_C("### Set advertising [%d]", enable);
438 g_variant_unref(ret);
440 return BLUETOOTH_ERROR_NONE;
443 static gboolean __bt_hold_current_advertising_timeout_cb(gpointer user_data)
446 GError *error = NULL;
449 BT_INFO("Restart advertising stopped by bt-service");
451 le_adv_slot[0].hold_timer_id = 0;
453 proxy = _bt_get_adapter_proxy();
454 retv_if(proxy == NULL, FALSE);
456 ret = g_dbus_proxy_call_sync(proxy, "SetAdvertising",
457 g_variant_new("(bi)", TRUE, 0),
458 G_DBUS_CALL_FLAGS_NONE,
464 BT_ERR("SetAdvertising Fail: %s", error->message);
465 g_clear_error(&error);
470 g_variant_unref(ret);
475 int _bt_hold_current_advertising(void)
478 GError *error = NULL;
481 if (le_adv_slot[0].sender && le_adv_slot[0].is_advertising == TRUE) {
482 BT_INFO("Stop current advertising by bt-service");
484 proxy = _bt_get_adapter_proxy();
485 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
487 ret = g_dbus_proxy_call_sync(proxy, "SetAdvertising",
488 g_variant_new("(bi)", FALSE, 0),
489 G_DBUS_CALL_FLAGS_NONE,
495 BT_ERR("SetAdvertising Fail: %s", error->message);
496 g_clear_error(&error);
497 return BLUETOOTH_ERROR_INTERNAL;
501 g_variant_unref(ret);
503 le_adv_slot[0].hold_timer_id = g_timeout_add(2000,
504 __bt_hold_current_advertising_timeout_cb, NULL);
506 BT_INFO("It's NOT advertising");
507 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
510 return BLUETOOTH_ERROR_NONE;
513 static int __bt_get_ad_data_by_type(char *in_data, int in_len,
514 char in_type, char **data, int *data_len)
516 if (in_data == NULL || data == NULL || data_len == NULL)
517 return BLUETOOTH_ERROR_INTERNAL;
520 return BLUETOOTH_ERROR_INTERNAL;
526 for (i = 0; i < in_len; i++) {
528 if (len <= 0 || i + 1 >= in_len) {
529 BT_ERR("Invalid advertising data");
530 return BLUETOOTH_ERROR_INTERNAL;
533 type = in_data[i + 1];
534 if (type == in_type) {
544 if (i + len > in_len) {
545 BT_ERR("Invalid advertising data");
546 return BLUETOOTH_ERROR_INTERNAL;
547 } else if (len == 0) {
548 BT_DBG("AD Type 0x%02x data is not set", in_type);
551 return BLUETOOTH_ERROR_NONE;
554 *data = g_memdup(&in_data[i], len);
556 return BLUETOOTH_ERROR_OUT_OF_MEMORY;
559 return BLUETOOTH_ERROR_NONE;
562 int _bt_get_advertising_data(bluetooth_advertising_data_t *adv, int *length)
564 BT_CHECK_PARAMETER(adv, return);
565 BT_CHECK_PARAMETER(length, return);
567 memcpy(adv, &adv_data, sizeof(adv_data));
568 *length = adv_data_len;
570 return BLUETOOTH_ERROR_NONE;
573 int _bt_set_advertising_data(const char *sender, int adv_handle,
574 bluetooth_advertising_data_t *adv, int length, gboolean use_reserved_slot)
577 GError *error = NULL;
578 GVariant *ret, *ad_data, *param = NULL;
579 GVariant *temp = NULL;
580 GVariantBuilder *builder;
582 char *old_mdata = NULL;
583 char *new_mdata = NULL;
588 if (__bt_is_factory_test_mode()) {
589 BT_ERR("Unable to set advertising data in factory binary !!");
590 return BLUETOOTH_ERROR_NOT_SUPPORT;
593 BT_CHECK_PARAMETER(adv, return);
595 if (_bt_adapter_get_status() != BT_ACTIVATED &&
596 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
597 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
600 proxy = _bt_get_adapter_proxy();
601 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
603 slot_id = __bt_get_available_adv_slot_id(sender, adv_handle, use_reserved_slot);
605 BT_ERR("There is NO available slot!!");
606 return BLUETOOTH_ERROR_NO_RESOURCES;
609 builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
610 for (i = 0; i < length; i++)
611 g_variant_builder_add(builder, "y", adv->data[i]);
613 temp = g_variant_new("ay", builder);
614 g_variant_builder_unref(builder);
615 ret = g_dbus_proxy_call_sync(proxy, "SetAdvertisingData",
616 g_variant_new("(@ayi)", temp, slot_id),
617 G_DBUS_CALL_FLAGS_NONE,
621 BT_ERR("SetAdvertisingData Fail: %s", error->message);
622 g_clear_error(&error);
623 return BLUETOOTH_ERROR_INTERNAL;
626 __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
628 __bt_get_ad_data_by_type((char *)adv_data.data, adv_data_len, 0xff,
629 &old_mdata, &old_len);
630 __bt_get_ad_data_by_type((char *)adv->data, length, 0xff,
631 &new_mdata, &new_len);
632 if (old_len != new_len ||
633 (old_mdata && new_mdata &&
634 memcmp(old_mdata, new_mdata, new_len))) {
635 ad_data = g_variant_new_from_data((const GVariantType *)"ay",
636 new_mdata, new_len, TRUE, NULL, NULL);
637 param = g_variant_new("(@ay)", ad_data);
638 _bt_send_event(BT_ADAPTER_EVENT,
639 BLUETOOTH_EVENT_ADVERTISING_MANUFACTURER_DATA_CHANGED,
645 memset(&adv_data, 0x00, sizeof(bluetooth_advertising_data_t));
646 memcpy(&adv_data, adv, length);
647 adv_data_len = length;
649 BT_INFO("Set advertising data");
651 g_variant_unref(ret);
653 return BLUETOOTH_ERROR_NONE;
656 int _bt_get_scan_response_data(bluetooth_scan_resp_data_t *response, int *length)
658 BT_CHECK_PARAMETER(response, return);
659 BT_CHECK_PARAMETER(length, return);
661 memcpy(response, &resp_data, sizeof(resp_data));
662 *length = resp_data_len;
664 return BLUETOOTH_ERROR_NONE;
667 int _bt_set_scan_response_data(const char *sender, int adv_handle,
668 bluetooth_scan_resp_data_t *response, int length, gboolean use_reserved_slot)
671 GError *error = NULL;
672 GVariant *ret, *scan_data, *param = NULL;
673 GVariant *temp = NULL;
674 GVariantBuilder *builder;
676 char *old_mdata = NULL;
677 char *new_mdata = NULL;
682 if (__bt_is_factory_test_mode()) {
683 BT_ERR("Unable to set scan response list in factory binary !!");
684 return BLUETOOTH_ERROR_NOT_SUPPORT;
687 BT_CHECK_PARAMETER(response, return);
689 if (_bt_adapter_get_status() != BT_ACTIVATED &&
690 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
691 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
694 proxy = _bt_get_adapter_proxy();
695 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
697 slot_id = __bt_get_available_adv_slot_id(sender, adv_handle, use_reserved_slot);
699 BT_ERR("There is NO available slot!!");
700 return BLUETOOTH_ERROR_NO_RESOURCES;
702 builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
703 for (i = 0; i < length; i++)
704 g_variant_builder_add(builder, "y", response->data[i]);
706 temp = g_variant_new("ay", builder);
707 g_variant_builder_unref(builder);
708 ret = g_dbus_proxy_call_sync(proxy, "SetScanRespData",
709 g_variant_new("(@ayi)", temp, slot_id),
710 G_DBUS_CALL_FLAGS_NONE,
714 BT_ERR("SetScanRespData Fail: %s", error->message);
715 g_clear_error(&error);
716 return BLUETOOTH_ERROR_INTERNAL;
719 __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
721 /* Compare with previous scan resp data */
722 __bt_get_ad_data_by_type((char *)resp_data.data, resp_data_len, 0xff,
723 &old_mdata, &old_len);
724 __bt_get_ad_data_by_type((char *)response->data, length, 0xff,
725 &new_mdata, &new_len);
726 if (old_len != new_len ||
727 (old_mdata && new_mdata &&
728 memcmp(old_mdata, new_mdata, new_len))) {
729 scan_data = g_variant_new_from_data((const GVariantType *)"ay",
730 new_mdata, new_len, TRUE, NULL, NULL);
731 param = g_variant_new("(@ay)", scan_data);
732 _bt_send_event(BT_ADAPTER_EVENT,
733 BLUETOOTH_EVENT_SCAN_RESPONSE_MANUFACTURER_DATA_CHANGED,
739 memset(&resp_data, 0x00, sizeof(bluetooth_scan_resp_data_t));
740 memcpy(&resp_data, response, length);
741 resp_data_len = length;
744 g_variant_unref(ret);
745 BT_INFO("Set scan response data");
746 return BLUETOOTH_ERROR_NONE;
749 int _bt_set_scan_parameters(bluetooth_le_scan_params_t *params)
752 GError *error = NULL;
757 BT_CHECK_PARAMETER(params, return);
759 if (_bt_adapter_get_status() != BT_ACTIVATED &&
760 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
761 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
764 proxy = _bt_get_adapter_proxy();
765 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
767 if (params->interval < BT_LE_SCAN_INTERVAL_MIN || params->interval > BT_LE_SCAN_INTERVAL_MAX)
768 return BLUETOOTH_ERROR_INVALID_PARAM;
770 if (params->window < BT_LE_SCAN_WINDOW_MIN || params->window > BT_LE_SCAN_WINDOW_MAX)
771 return BLUETOOTH_ERROR_INVALID_PARAM;
773 if (params->window > params->interval)
774 return BLUETOOTH_ERROR_INVALID_PARAM;
776 itv = params->interval / BT_ADV_INTERVAL_SPLIT;
777 win = params->window / BT_ADV_INTERVAL_SPLIT;
779 ret = g_dbus_proxy_call_sync(proxy, "SetScanParameters",
780 g_variant_new("(uuu)", params->type, itv, win),
781 G_DBUS_CALL_FLAGS_NONE, -1,
785 BT_ERR("SetScanParameters Fail: %s", error->message);
786 g_clear_error(&error);
787 return BLUETOOTH_ERROR_INTERNAL;
790 _bt_set_le_scan_type(params->type);
792 is_le_set_scan_parameter = TRUE;
795 g_variant_unref(ret);
796 BT_INFO("Set scan parameters");
797 return BLUETOOTH_ERROR_NONE;
800 bt_adapter_le_scanner_t* __bt_find_scanner_from_list(const char *sender)
803 bt_adapter_le_scanner_t *scanner;
805 for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
807 if (g_strcmp0(scanner->sender, sender) == 0)
814 int __bt_get_available_scan_filter_slot_id(void)
817 bt_adapter_le_scanner_t *scanner;
819 bluetooth_le_scan_filter_t *filter_data;
820 gboolean *slot_check_list = NULL;
823 if (le_feature_info.max_filter == 0) {
824 BT_ERR("Scan filter is NOT Supported");
827 slot_check_list = g_malloc0(sizeof(gboolean) * le_feature_info.max_filter);
829 for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
831 for (fl = scanner->filter_list; fl != NULL; fl = g_slist_next(fl)) {
832 filter_data = fl->data;
833 if (filter_data->slot_id < le_feature_info.max_filter)
834 slot_check_list[filter_data->slot_id] = TRUE;
838 for (i = 0; i < le_feature_info.max_filter; i++) {
839 if (slot_check_list[i] == FALSE) {
840 g_free(slot_check_list);
845 BT_ERR("There is NO available slot for scan filter.");
846 g_free(slot_check_list);
850 gboolean _bt_is_scan_filter_supported(void)
852 if (le_feature_info.max_filter > 0)
858 int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *filter, int *slot_id)
861 GError *error = NULL;
862 GVariant *ret, *param;
863 GVariant *arr_uuid_param = NULL, *arr_uuid_mask_param = NULL;
864 GVariant *arr_data_param = NULL, *arr_data_mask_param = NULL;
865 GArray *arr_uuid = NULL;
866 GArray *arr_uuid_mask = NULL;
867 GArray *arr_data = NULL;
868 GArray *arr_data_mask = NULL;
869 bt_adapter_le_scanner_t *scanner = NULL;
870 bluetooth_le_scan_filter_t *filter_data = NULL;
871 int feature_selection = 0;
873 *slot_id = __bt_get_available_scan_filter_slot_id();
875 return BLUETOOTH_ERROR_NO_RESOURCES;
877 proxy = _bt_get_adapter_proxy();
878 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
880 if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS) {
881 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
882 feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS;
884 _bt_convert_addr_type_to_string(address, filter->device_address.addr);
886 arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
887 NULL, 0, TRUE, NULL, NULL);
888 arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
889 NULL, 0, TRUE, NULL, NULL);
890 arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
891 NULL, 0, TRUE, NULL, NULL);
892 arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
893 NULL, 0, TRUE, NULL, NULL);
895 param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
897 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
898 BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS, // filter_type
899 *slot_id, // filter_index
901 0, // company_id_mask
902 arr_uuid_param, // p_uuid
903 arr_uuid_mask_param, // p_uuid_mask
906 arr_data_param, // p_data
907 arr_data_mask_param); // p_mask
909 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove",
910 param, G_DBUS_CALL_FLAGS_NONE,
914 BT_ERR("scan_filter_add_remove Fail: %s", error->message);
915 g_clear_error(&error);
918 g_variant_unref(ret);
921 if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME) {
922 feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME;
924 arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
925 NULL, 0, TRUE, NULL, NULL);
926 arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
927 NULL, 0, TRUE, NULL, NULL);
928 arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
929 NULL, 0, TRUE, NULL, NULL);
930 arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
931 NULL, 0, TRUE, NULL, NULL);
933 param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
935 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
936 BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME, // filter_type
937 *slot_id, // filter_index
939 0, // company_id_mask
940 arr_uuid_param, // p_uuid
941 arr_uuid_mask_param, // p_uuid_mask
942 filter->device_name, // string
944 arr_data_param, // p_data
945 arr_data_mask_param);
947 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove",
948 param, G_DBUS_CALL_FLAGS_NONE,
952 BT_ERR("scan_filter_add_remove Fail: %s", error->message);
953 g_clear_error(&error);
956 g_variant_unref(ret);
959 if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID) {
960 feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID;
962 arr_uuid = g_array_new(TRUE, TRUE, sizeof(guint8));
963 arr_uuid_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
965 g_array_append_vals(arr_uuid, filter->service_uuid.data.data, filter->service_uuid.data_len * sizeof(guint8));
966 g_array_append_vals(arr_uuid_mask, filter->service_uuid_mask.data.data, filter->service_uuid_mask.data_len * sizeof(guint8));
968 arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
969 arr_uuid->data, arr_uuid->len, TRUE, NULL, NULL);
970 arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
971 arr_uuid_mask->data, arr_uuid_mask->len, TRUE, NULL, NULL);
972 arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
973 NULL, 0, TRUE, NULL, NULL);
974 arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
975 NULL, 0, TRUE, NULL, NULL);
977 param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
979 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
980 BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID, // filter_type
981 *slot_id, // filter_index
983 0, // company_id_mask
984 arr_uuid_param, // p_uuid
985 arr_uuid_mask_param, // p_uuid_mask
988 arr_data_param, // p_data
989 arr_data_mask_param);
991 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove",
992 param, G_DBUS_CALL_FLAGS_NONE,
996 BT_ERR("scan_filter_add_remove Fail: %s", error->message);
997 g_clear_error(&error);
1000 g_variant_unref(ret);
1002 g_array_free(arr_uuid, TRUE);
1003 g_array_free(arr_uuid_mask, TRUE);
1004 g_array_free(arr_data, TRUE);
1005 g_array_free(arr_data_mask, TRUE);
1008 if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID) {
1009 feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID;
1011 arr_uuid = g_array_new(TRUE, TRUE, sizeof(guint8));
1012 arr_uuid_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
1014 g_array_append_vals(arr_uuid, filter->service_solicitation_uuid.data.data, filter->service_solicitation_uuid.data_len * sizeof(guint8));
1015 g_array_append_vals(arr_uuid_mask, filter->service_solicitation_uuid_mask.data.data, filter->service_solicitation_uuid_mask.data_len * sizeof(guint8));
1017 arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
1018 arr_uuid->data, arr_uuid->len, TRUE, NULL, NULL);
1019 arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
1020 arr_uuid_mask->data, arr_uuid_mask->len, TRUE, NULL, NULL);
1021 arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
1022 NULL, 0, TRUE, NULL, NULL);
1023 arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
1024 NULL, 0, TRUE, NULL, NULL);
1026 param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
1028 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
1029 BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID, // filter_type
1030 *slot_id, // filter_index
1032 0, // company_id_mask
1033 arr_uuid_param, // p_uuid
1034 arr_uuid_mask_param, // p_uuid_mask
1037 arr_data_param, // p_data
1038 arr_data_mask_param);
1040 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove", param,
1041 G_DBUS_CALL_FLAGS_NONE,
1045 BT_ERR("scan_filter_add_remove Fail: %s", error->message);
1046 g_clear_error(&error);
1049 g_variant_unref(ret);
1051 g_array_free(arr_uuid, TRUE);
1052 g_array_free(arr_uuid_mask, TRUE);
1055 if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA) {
1056 feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA;
1058 arr_data = g_array_new(TRUE, TRUE, sizeof(guint8));
1059 arr_data_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
1061 g_array_append_vals(arr_data, filter->service_data.data.data, filter->service_data.data_len * sizeof(guint8));
1062 g_array_append_vals(arr_data_mask, filter->service_data_mask.data.data, filter->service_data_mask.data_len * sizeof(guint8));
1064 arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
1065 NULL, 0, TRUE, NULL, NULL);
1066 arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
1067 NULL, 0, TRUE, NULL, NULL);
1068 arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
1069 arr_data->data, arr_data->len, TRUE, NULL, NULL);
1070 arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
1071 arr_data_mask->data, arr_data_mask->len, TRUE, NULL, NULL);
1073 param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
1075 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
1076 BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA, // filter_type
1077 *slot_id, // filter_index
1079 0, // company_id_mask
1080 arr_uuid_param, // p_uuid
1081 arr_uuid_mask_param, // p_uuid_mask
1084 arr_data_param, // p_data
1085 arr_data_mask_param);
1087 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove", param,
1088 G_DBUS_CALL_FLAGS_NONE,
1092 BT_ERR("scan_filter_add_remove Fail: %s", error->message);
1093 g_clear_error(&error);
1096 g_variant_unref(ret);
1098 g_array_free(arr_data, TRUE);
1099 g_array_free(arr_data_mask, TRUE);
1102 if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA) {
1103 feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA;
1105 arr_data = g_array_new(TRUE, TRUE, sizeof(guint8));
1106 arr_data_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
1108 g_array_append_vals(arr_data, filter->manufacturer_data.data.data, filter->manufacturer_data.data_len * sizeof(guint8));
1109 g_array_append_vals(arr_data_mask, filter->manufacturer_data_mask.data.data, filter->manufacturer_data_mask.data_len * sizeof(guint8));
1111 arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
1112 NULL, 0, TRUE, NULL, NULL);
1113 arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
1114 NULL, 0, TRUE, NULL, NULL);
1115 arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
1116 arr_data->data, arr_data->len, TRUE, NULL, NULL);
1117 arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
1118 arr_data_mask->data, arr_data_mask->len, TRUE, NULL, NULL);
1120 param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
1122 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
1123 BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA, // filter_type
1124 *slot_id, // filter_index
1125 filter->manufacturer_id, // company_id
1126 0xFFFF, // company_id_mask
1127 arr_uuid_param, // p_uuid
1128 arr_uuid_mask_param, // p_uuid_mask
1131 arr_data_param, // p_data
1132 arr_data_mask_param);
1134 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove", param,
1135 G_DBUS_CALL_FLAGS_NONE,
1139 BT_ERR("scan_filter_add_remove Fail: %s", error->message);
1140 g_clear_error(&error);
1143 g_variant_unref(ret);
1145 g_array_free(arr_data, TRUE);
1146 g_array_free(arr_data_mask, TRUE);
1149 BT_DBG("Filter selection %.2x", feature_selection);
1151 param = g_variant_new("(iiiiiiiiiiii)",
1153 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
1154 *slot_id, // filter_index
1155 feature_selection, // feat_seln
1156 0, // list_logic_type (OR - 0x00, AND - 0x01)
1157 1, // filt_logic_type (OR - 0x00, AND - 0x01)
1158 -127, // rssi_high_thres
1159 -127, // rssi_low_thres
1160 0, // dely_mode (Immediate - 0x00, on found - 0x01, batched - 0x02)
1163 0); // found_timeout_cnt
1164 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_param_setup",
1165 param, G_DBUS_CALL_FLAGS_NONE,
1169 BT_ERR("scan_filter_add_remove Fail: %s", error->message);
1170 g_clear_error(&error);
1173 scanner = __bt_find_scanner_from_list(sender);
1174 if (scanner == NULL) {
1175 scanner = g_malloc0(sizeof(bt_adapter_le_scanner_t));
1176 scanner->sender = g_strdup(sender);
1177 scanner_list = g_slist_append(scanner_list, scanner);
1182 filter_data = g_malloc0(sizeof(bluetooth_le_scan_filter_t));
1183 memcpy(filter_data, filter, sizeof(bluetooth_le_scan_filter_t));
1184 filter_data->slot_id = *slot_id;
1186 scanner->filter_list = g_slist_append(scanner->filter_list, filter_data);
1190 g_variant_unref(ret);
1191 return BLUETOOTH_ERROR_NONE;
1194 int _bt_unregister_scan_filter(const char *sender, int slot_id)
1197 GError *error = NULL;
1199 bt_adapter_le_scanner_t *scanner = NULL;
1200 bluetooth_le_scan_filter_t *filter_data = NULL;
1202 gboolean is_slot_id_found = FALSE;
1204 scanner = __bt_find_scanner_from_list(sender);
1205 if (scanner == NULL) {
1206 BT_ERR("There is NO available scanner.");
1207 return BLUETOOTH_ERROR_NOT_FOUND;
1210 for (l = scanner->filter_list; l != NULL; l = g_slist_next(l)) {
1211 filter_data = l->data;
1212 if (filter_data->slot_id == slot_id) {
1213 is_slot_id_found = TRUE;
1217 if (is_slot_id_found == FALSE) {
1218 BT_ERR("There is NO registered slot.");
1219 return BLUETOOTH_ERROR_NOT_FOUND;
1222 proxy = _bt_get_adapter_proxy();
1223 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1225 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_clear",
1226 g_variant_new("(ii)", 0, slot_id),
1227 G_DBUS_CALL_FLAGS_NONE,
1231 BT_ERR("scan_filter_clear Fail: %s", error->message);
1232 g_clear_error(&error);
1235 scanner->filter_list = g_slist_remove(scanner->filter_list, filter_data);
1236 g_free(filter_data);
1239 g_variant_unref(ret);
1240 return BLUETOOTH_ERROR_NONE;
1243 int _bt_unregister_all_scan_filters(const char *sender)
1246 GError *error = NULL;
1248 bt_adapter_le_scanner_t *scanner = NULL;
1249 bluetooth_le_scan_filter_t *filter_data = NULL;
1252 scanner = __bt_find_scanner_from_list(sender);
1253 if (scanner == NULL) {
1254 BT_ERR("There is NO available scanner.");
1255 return BLUETOOTH_ERROR_NOT_FOUND;
1258 proxy = _bt_get_adapter_proxy();
1259 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1261 for (l = scanner->filter_list; l != NULL; l = g_slist_next(l)) {
1262 filter_data = l->data;
1264 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_clear",
1265 g_variant_new("(ii)", 0, filter_data->slot_id),
1266 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1269 BT_ERR("scan_filter_clear Fail: %s", error->message);
1270 g_clear_error(&error);
1273 g_variant_unref(ret);
1276 g_slist_free_full(scanner->filter_list, g_free);
1277 scanner->filter_list = NULL;
1279 return BLUETOOTH_ERROR_NONE;
1282 int _bt_start_le_scan(const char *sender)
1285 GError *error = NULL;
1287 bt_adapter_le_scanner_t *scanner = __bt_find_scanner_from_list(sender);
1289 if (scanner == NULL) {
1290 scanner = g_malloc0(sizeof(bt_adapter_le_scanner_t));
1291 scanner->sender = g_strdup(sender);
1292 scanner_list = g_slist_append(scanner_list, scanner);
1295 if (scanner->is_scanning == TRUE) {
1296 BT_ERR("BT is already in LE scanning");
1297 return BLUETOOTH_ERROR_IN_PROGRESS;
1299 scanner->is_scanning = TRUE;
1301 proxy = _bt_get_adapter_proxy();
1302 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1304 if (_bt_is_le_scanning()) {
1305 if (scan_filter_enabled == TRUE) {
1306 if (scanner->filter_list == NULL) {
1307 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_enable",
1308 g_variant_new("(ib)", 0, FALSE),
1309 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1312 BT_ERR("scan_filter_clear Fail: %s", error->message);
1313 g_clear_error(&error);
1317 g_variant_unref(ret);
1318 BT_INFO("Disable LE Scan Filter");
1319 scan_filter_enabled = FALSE;
1321 BT_INFO("LE Filter Scan is continue");
1324 BT_INFO("LE Full Scan is already on progress");
1326 return BLUETOOTH_ERROR_NONE;
1328 if (is_le_set_scan_parameter == FALSE) {
1329 /* Set default scan parameter same with BT_ADAPTER_LE_SCAN_MODE_LOW_ENERGY */
1330 bluetooth_le_scan_params_t scan_params;
1331 scan_params.type = BT_LE_ACTIVE_SCAN;
1332 scan_params.interval = 5000;
1333 scan_params.window = 500;
1334 _bt_set_scan_parameters(&scan_params);
1337 if (scanner->filter_list == NULL) {
1338 BT_INFO("Start LE Full Scan");
1339 scan_filter_enabled = FALSE;
1341 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_enable",
1342 g_variant_new("(ib)", 0, TRUE),
1343 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1346 BT_ERR("scan_filter_clear Fail: %s", error->message);
1347 g_clear_error(&error);
1351 g_variant_unref(ret);
1352 BT_INFO("Enable LE Scan Filter");
1353 scan_filter_enabled = TRUE;
1357 ret = g_dbus_proxy_call_sync(proxy, "StartLEDiscovery",
1358 NULL, G_DBUS_CALL_FLAGS_NONE,
1362 BT_ERR("StartLEDiscovery Fail: %s", error->message);
1363 g_clear_error(&error);
1364 return BLUETOOTH_ERROR_INTERNAL;
1368 g_variant_unref(ret);
1369 return BLUETOOTH_ERROR_NONE;
1372 int _bt_stop_le_scan(const char *sender)
1375 GError *error = NULL;
1377 bt_adapter_le_scanner_t *scanner = __bt_find_scanner_from_list(sender);
1379 gboolean next_scanning = FALSE;
1380 gboolean need_scan_filter = TRUE;
1382 if (scanner == NULL || scanner->is_scanning == FALSE)
1383 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
1385 scanner->is_scanning = FALSE;
1387 for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
1389 if (scanner->is_scanning == TRUE) {
1390 next_scanning = TRUE;
1391 if (scanner->filter_list == NULL)
1392 need_scan_filter = FALSE;
1396 proxy = _bt_get_adapter_proxy();
1397 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1399 if (next_scanning == TRUE) {
1400 if (scan_filter_enabled == FALSE && need_scan_filter == TRUE) {
1401 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_enable",
1402 g_variant_new("(ib)", 0, TRUE),
1403 G_DBUS_CALL_FLAGS_NONE,
1407 BT_ERR("scan_filter_clear Fail: %s", error->message);
1408 g_clear_error(&error);
1412 g_variant_unref(ret);
1413 BT_INFO("Enable LE Scan Filter");
1414 scan_filter_enabled = TRUE;
1416 return BLUETOOTH_ERROR_NONE;
1418 if (scan_filter_enabled == TRUE) {
1419 ret = g_dbus_proxy_call_sync(proxy, "scan_filter_enable",
1420 g_variant_new("(ib)", 0, FALSE),
1421 G_DBUS_CALL_FLAGS_NONE,
1425 BT_ERR("scan_filter_clear Fail: %s", error->message);
1426 g_clear_error(&error);
1430 g_variant_unref(ret);
1431 BT_INFO("Disable LE Scan Filter");
1433 BT_INFO("Just stop LE scan");
1437 ret = g_dbus_proxy_call_sync(proxy, "StopLEDiscovery",
1438 NULL, G_DBUS_CALL_FLAGS_NONE,
1441 BT_ERR("LE Scan stop failed");
1442 return BLUETOOTH_ERROR_INTERNAL;
1445 scan_filter_enabled = FALSE;
1446 is_le_set_scan_parameter = FALSE;
1448 g_variant_unref(ret);
1449 return BLUETOOTH_ERROR_NONE;
1452 void _bt_disable_all_scanner_status(void)
1455 bt_adapter_le_scanner_t *scanner;
1457 for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
1459 scanner->is_scanning = FALSE;
1463 static void __bt_free_le_scanner(void)
1466 bt_adapter_le_scanner_t *scanner;
1468 for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
1470 g_free(scanner->sender);
1471 g_slist_free_full(scanner->filter_list, g_free);
1475 g_slist_free(scanner_list);
1476 scanner_list = NULL;
1478 scan_filter_enabled = FALSE;
1479 is_le_scanning = FALSE;
1480 is_le_set_scan_parameter = FALSE;
1483 void _bt_set_le_scan_status(gboolean mode)
1485 is_le_scanning = mode;
1488 gboolean _bt_is_le_scanning(void)
1490 return is_le_scanning;
1493 void _bt_set_le_scan_type(bt_le_scan_type_t type)
1495 le_scan_type = type;
1498 bt_le_scan_type_t _bt_get_le_scan_type(void)
1500 return le_scan_type;
1503 static gboolean __bt_check_scan_result_uuid(const char *adv_data,
1504 int adv_data_len, const char *svc_uuid, int uuid_len,
1505 const char *uuid_mask, char ad_type)
1511 __bt_get_ad_data_by_type((char*)adv_data, adv_data_len,
1512 ad_type, &data, &data_len);
1514 for (i = 0; i < data_len; i += uuid_len) {
1515 if (uuid_len > (data_len - i))
1518 if (_bt_byte_arr_cmp_with_mask(data + i,
1519 svc_uuid, uuid_mask, uuid_len) == 0) {
1530 static gboolean __bt_check_scan_result_with_filter(const char *device_address,
1531 const char *adv_data, int adv_data_len,
1532 const char *scan_data, int scan_data_len,
1533 const bt_adapter_le_scanner_t *scanner)
1536 bluetooth_le_scan_filter_t *filter_data = NULL;
1539 gboolean is_matched = FALSE;
1541 if (scanner->filter_list == NULL) {
1542 BT_INFO("This scanner is on Full Scan.");
1546 for (l = scanner->filter_list; l != NULL; l = g_slist_next(l)) {
1547 filter_data = l->data;
1549 if (filter_data->added_features &
1550 BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS) {
1551 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1553 _bt_convert_addr_type_to_string(address,
1554 filter_data->device_address.addr);
1555 if (strncmp(address, device_address,
1556 BT_ADDRESS_STRING_SIZE) != 0)
1560 if (filter_data->added_features &
1561 BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID) {
1564 if (__bt_check_scan_result_uuid(adv_data,
1566 (char*)filter_data->service_uuid.data.data,
1567 filter_data->service_uuid.data_len,
1568 (char*)filter_data->service_uuid_mask.data.data,
1569 BT_LE_AD_TYPE_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS)
1572 if (__bt_check_scan_result_uuid(adv_data,
1574 (char*)filter_data->service_uuid.data.data,
1575 filter_data->service_uuid.data_len,
1576 (char*)filter_data->service_uuid_mask.data.data,
1577 BT_LE_AD_TYPE_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS)
1580 if (__bt_check_scan_result_uuid(adv_data,
1582 (char*)filter_data->service_uuid.data.data,
1583 filter_data->service_uuid.data_len,
1584 (char*)filter_data->service_uuid_mask.data.data,
1585 BT_LE_AD_TYPE_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS)
1588 if (__bt_check_scan_result_uuid(adv_data,
1590 (char*)filter_data->service_uuid.data.data,
1591 filter_data->service_uuid.data_len,
1592 (char*)filter_data->service_uuid_mask.data.data,
1593 BT_LE_AD_TYPE_COMP_LIST_128_BIT_SERVICE_CLASS_UUIDS)
1596 if (__bt_check_scan_result_uuid(scan_data,
1598 (char*)filter_data->service_uuid.data.data,
1599 filter_data->service_uuid.data_len,
1600 (char*)filter_data->service_uuid_mask.data.data,
1601 BT_LE_AD_TYPE_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS)
1604 if (__bt_check_scan_result_uuid(scan_data,
1606 (char*)filter_data->service_uuid.data.data,
1607 filter_data->service_uuid.data_len,
1608 (char*)filter_data->service_uuid_mask.data.data,
1609 BT_LE_AD_TYPE_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS)
1612 if (__bt_check_scan_result_uuid(scan_data,
1614 (char*)filter_data->service_uuid.data.data,
1615 filter_data->service_uuid.data_len,
1616 (char*)filter_data->service_uuid_mask.data.data,
1617 BT_LE_AD_TYPE_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS)
1620 if (__bt_check_scan_result_uuid(scan_data,
1622 (char*)filter_data->service_uuid.data.data,
1623 filter_data->service_uuid.data_len,
1624 (char*)filter_data->service_uuid_mask.data.data,
1625 BT_LE_AD_TYPE_COMP_LIST_128_BIT_SERVICE_CLASS_UUIDS)
1629 if (is_matched == FALSE)
1632 if (filter_data->added_features &
1633 BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID) {
1636 if (__bt_check_scan_result_uuid(adv_data,
1638 (char*)filter_data->service_solicitation_uuid.data.data,
1639 filter_data->service_solicitation_uuid.data_len,
1640 (char*)filter_data->service_solicitation_uuid_mask.data.data,
1641 BT_LE_AD_TYPE_LIST_16_BIT_SERVICE_SOLICITATION_UUIDS)
1644 if (__bt_check_scan_result_uuid(adv_data,
1646 (char*)filter_data->service_solicitation_uuid.data.data,
1647 filter_data->service_solicitation_uuid.data_len,
1648 (char*)filter_data->service_solicitation_uuid_mask.data.data,
1649 BT_LE_AD_TYPE_LIST_128_BIT_SERVICE_SOLICITATION_UUIDS)
1652 if (__bt_check_scan_result_uuid(scan_data,
1654 (char*)filter_data->service_solicitation_uuid.data.data,
1655 filter_data->service_solicitation_uuid.data_len,
1656 (char*)filter_data->service_solicitation_uuid_mask.data.data,
1657 BT_LE_AD_TYPE_LIST_16_BIT_SERVICE_SOLICITATION_UUIDS)
1660 if (__bt_check_scan_result_uuid(scan_data,
1662 (char*)filter_data->service_solicitation_uuid.data.data,
1663 filter_data->service_solicitation_uuid.data_len,
1664 (char*)filter_data->service_solicitation_uuid_mask.data.data,
1665 BT_LE_AD_TYPE_LIST_128_BIT_SERVICE_SOLICITATION_UUIDS)
1669 if (is_matched == FALSE)
1672 if (filter_data->added_features &
1673 BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME) {
1674 char name[BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX] = {0, };
1679 __bt_get_ad_data_by_type((char*)adv_data, adv_data_len,
1680 BT_LE_AD_TYPE_COMPLETE_LOCAL_NAME,
1683 if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
1684 data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
1685 memcpy(name, data, data_len);
1686 name[data_len] = '\0';
1689 if (strncmp(filter_data->device_name,
1690 name, data_len) == 0)
1693 __bt_get_ad_data_by_type((char*)scan_data,
1695 BT_LE_AD_TYPE_COMPLETE_LOCAL_NAME,
1698 if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
1699 data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
1700 memcpy(name, data, data_len);
1701 name[data_len] = '\0';
1704 if (strncmp(filter_data->device_name,
1705 name, data_len) == 0)
1709 if (is_matched == FALSE)
1712 if (filter_data->added_features &
1713 BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA) {
1718 __bt_get_ad_data_by_type((char*)adv_data,
1720 BT_LE_AD_TYPE_MANUFACTURER_SPECIFIC_DATA,
1724 int manufacturer_id;
1725 manufacturer_id = (data[1] << 8) + data[0];
1727 if (filter_data->manufacturer_id == manufacturer_id) {
1728 if (filter_data->manufacturer_data.data_len == 0) {
1731 if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
1732 data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
1733 if (_bt_byte_arr_cmp_with_mask(data + 2,
1734 (char*)filter_data->manufacturer_data.data.data,
1735 (char*)filter_data->manufacturer_data_mask.data.data,
1736 data_len - 2) == 0) {
1744 __bt_get_ad_data_by_type((char*)scan_data,
1746 BT_LE_AD_TYPE_MANUFACTURER_SPECIFIC_DATA,
1750 int manufacturer_id;
1751 manufacturer_id = (data[1] << 8) + data[0];
1753 if (filter_data->manufacturer_id == manufacturer_id) {
1754 if (filter_data->manufacturer_data.data_len == 0) {
1757 if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
1758 data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
1759 if (_bt_byte_arr_cmp_with_mask(data + 2,
1760 (char*)filter_data->manufacturer_data.data.data,
1761 (char*)filter_data->manufacturer_data_mask.data.data,
1762 data_len - 2) == 0) {
1771 if (is_matched == FALSE)
1774 if (filter_data->added_features &
1775 BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA) {
1780 __bt_get_ad_data_by_type((char*)adv_data,
1782 BT_LE_AD_TYPE_SERVICE_DATA,
1785 if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
1786 data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
1787 if (_bt_byte_arr_cmp_with_mask(data,
1788 (char*)filter_data->service_data.data.data,
1789 (char*)filter_data->service_data_mask.data.data,
1796 __bt_get_ad_data_by_type((char*)scan_data,
1798 BT_LE_AD_TYPE_SERVICE_DATA,
1801 if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
1802 data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
1803 if (_bt_byte_arr_cmp_with_mask(data,
1804 (char*)filter_data->service_data.data.data,
1805 (char*)filter_data->service_data_mask.data.data,
1813 if (is_matched == FALSE)
1817 BT_INFO("The scan result is conformable.");
1821 BT_INFO("The scan result is NOT conformable.");
1825 void _bt_send_scan_result_event(const bt_remote_le_dev_info_t *le_dev_info,
1826 const bt_le_adv_info_t *adv_info)
1828 int result = BLUETOOTH_ERROR_NONE;
1830 GVariant *scan_data_param, *adv_data_param;
1832 bt_adapter_le_scanner_t *scanner = NULL;
1833 const char *adv_data = NULL;
1834 int adv_data_len = 0;
1835 const char *scan_data = NULL;
1836 int scan_data_len = 0;
1838 ret_if(le_dev_info == NULL);
1839 if (_bt_get_le_scan_type() == BT_LE_ACTIVE_SCAN)
1840 ret_if(adv_info == NULL);
1842 if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
1843 adv_data = le_dev_info->adv_data;
1844 adv_data_len = le_dev_info->adv_data_len;
1845 scan_data = le_dev_info->adv_data;
1848 adv_data = adv_info->data;
1849 adv_data_len = adv_info->data_len;
1850 scan_data = le_dev_info->adv_data;
1851 scan_data_len = le_dev_info->adv_data_len;
1854 for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
1856 if (scanner->is_scanning == FALSE)
1859 if (__bt_check_scan_result_with_filter(le_dev_info->address,
1860 adv_data, adv_data_len, scan_data, scan_data_len,
1864 adv_data_param = g_variant_new_from_data((const GVariantType *)"ay",
1865 adv_data, adv_data_len, TRUE, NULL, NULL);
1866 scan_data_param = g_variant_new_from_data((const GVariantType *)"ay",
1867 scan_data, scan_data_len, TRUE, NULL, NULL);
1869 param = g_variant_new("(isnnn@ayn@ay)",
1871 le_dev_info->address,
1872 le_dev_info->addr_type,
1879 _bt_send_event_to_dest(scanner->sender, BT_LE_ADAPTER_EVENT,
1880 BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND, param);
1884 int _bt_add_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type)
1887 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1888 GError *error = NULL;
1891 if (__bt_is_factory_test_mode()) {
1892 BT_ERR("Unable to add white list in factory binary !!");
1893 return BLUETOOTH_ERROR_NOT_SUPPORT;
1896 BT_CHECK_PARAMETER(device_address, return);
1898 if (address_type != BLUETOOTH_DEVICE_PUBLIC_ADDRESS &&
1899 address_type != BLUETOOTH_DEVICE_RANDOM_ADDRESS)
1900 return BLUETOOTH_ERROR_INVALID_PARAM;
1902 _bt_convert_addr_type_to_string(address, device_address->addr);
1904 proxy = _bt_get_adapter_proxy();
1905 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1907 ret = g_dbus_proxy_call_sync(proxy, "AddDeviceWhiteList",
1908 g_variant_new("(su)", address, address_type),
1909 G_DBUS_CALL_FLAGS_NONE, -1,
1913 BT_ERR("AddDeviceWhiteList Fail: %s", error->message);
1914 g_clear_error(&error);
1915 return BLUETOOTH_ERROR_INTERNAL;
1919 g_variant_unref(ret);
1920 BT_INFO("Add white list");
1922 return BLUETOOTH_ERROR_NONE;
1925 int _bt_remove_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type)
1928 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
1929 GError *error = NULL;
1932 if (__bt_is_factory_test_mode()) {
1933 BT_ERR("Unable to remove white list in factory binary !!");
1934 return BLUETOOTH_ERROR_NOT_SUPPORT;
1937 BT_CHECK_PARAMETER(device_address, return);
1939 if (address_type != BLUETOOTH_DEVICE_PUBLIC_ADDRESS &&
1940 address_type != BLUETOOTH_DEVICE_RANDOM_ADDRESS)
1941 return BLUETOOTH_ERROR_INVALID_PARAM;
1943 _bt_convert_addr_type_to_string(address, device_address->addr);
1945 proxy = _bt_get_adapter_proxy();
1946 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1948 ret = g_dbus_proxy_call_sync(proxy, "RemoveDeviceWhiteList",
1949 g_variant_new("(su)", address, address_type),
1950 G_DBUS_CALL_FLAGS_NONE, -1,
1954 BT_ERR("RemoveDeviceWhiteList Fail: %s", error->message);
1955 g_clear_error(&error);
1956 return BLUETOOTH_ERROR_INTERNAL;
1960 g_variant_unref(ret);
1961 BT_INFO("Remove white list");
1963 return BLUETOOTH_ERROR_NONE;
1966 int _bt_clear_white_list(void)
1969 GError *error = NULL;
1972 if (__bt_is_factory_test_mode()) {
1973 BT_ERR("Unable to clear white list in factory binary !!");
1974 return BLUETOOTH_ERROR_NOT_SUPPORT;
1977 proxy = _bt_get_adapter_proxy();
1978 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
1980 ret = g_dbus_proxy_call_sync(proxy, "ClearDeviceWhiteList",
1981 NULL, G_DBUS_CALL_FLAGS_NONE,
1985 BT_ERR("ClearDeviceWhiteList Fail: %s", error->message);
1986 g_clear_error(&error);
1987 return BLUETOOTH_ERROR_INTERNAL;
1990 g_variant_unref(ret);
1992 BT_INFO("Clear white list");
1994 return BLUETOOTH_ERROR_NONE;
1997 int _bt_initialize_ipsp(void)
2001 GError *error = NULL;
2004 if (_bt_adapter_get_status() != BT_ACTIVATED &&
2005 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
2006 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
2009 proxy = _bt_get_adapter_proxy();
2010 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2012 ret = g_dbus_proxy_call_sync(proxy, "InitializeIpsp",
2013 NULL, G_DBUS_CALL_FLAGS_NONE,
2016 BT_ERR("Initialize IPSP Failed :[%s]", error->message);
2017 g_clear_error(&error);
2018 return BLUETOOTH_ERROR_INTERNAL;
2021 g_variant_unref(ret);
2023 BT_INFO("IPSP initialization called successfully");
2025 return BLUETOOTH_ERROR_NONE;
2028 int _bt_deinitialize_ipsp(void)
2032 GError *error = NULL;
2035 if (_bt_adapter_get_status() != BT_ACTIVATED &&
2036 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
2037 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
2040 proxy = _bt_get_adapter_proxy();
2041 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2043 ret = g_dbus_proxy_call_sync(proxy, "DeinitializeIpsp",
2044 NULL, G_DBUS_CALL_FLAGS_NONE,
2047 BT_ERR("De-Initialize IPSP Failed :[%s]", error->message);
2048 g_clear_error(&error);
2049 return BLUETOOTH_ERROR_INTERNAL;
2052 g_variant_unref(ret);
2054 BT_INFO("IPSP De-initialization called successfully");
2056 return BLUETOOTH_ERROR_NONE;
2059 int _bt_le_read_maximum_data_length(
2060 bluetooth_le_read_maximum_data_length_t *max_le_datalength)
2062 GError *error = NULL;
2064 GVariant *reply = NULL;
2065 guint16 max_tx_octets, max_tx_time;
2066 guint16 max_rx_octets, max_rx_time;
2068 proxy = _bt_get_adapter_proxy();
2069 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2071 reply = g_dbus_proxy_call_sync(proxy, "LEReadMaximumDataLength",
2072 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2074 if (reply == NULL) {
2075 BT_ERR("LEReadMaximumDataLength dBUS-RPC failed");
2076 if (error != NULL) {
2077 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
2078 error->code, error->message);
2079 g_clear_error(&error);
2081 return BLUETOOTH_ERROR_INTERNAL;
2084 g_variant_get(reply, "(qqqq)", &max_tx_octets, &max_tx_time,
2085 &max_rx_octets, &max_rx_time);
2087 max_le_datalength->max_tx_octets = max_tx_octets;
2088 max_le_datalength->max_tx_time = max_tx_time;
2089 max_le_datalength->max_rx_octets = max_rx_octets;
2090 max_le_datalength->max_rx_time = max_rx_time;
2092 g_variant_unref(reply);
2094 return BLUETOOTH_ERROR_NONE;
2096 int _bt_le_write_host_suggested_default_data_length(
2097 const unsigned int def_tx_Octets, const unsigned int def_tx_Time)
2099 GError *error = NULL;
2101 GVariant *reply = NULL;
2103 proxy = _bt_get_adapter_proxy();
2104 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2106 reply = g_dbus_proxy_call_sync(proxy,
2107 "LEWriteHostSuggestedDataLength",
2108 g_variant_new("(qq)", def_tx_Octets, def_tx_Time),
2109 G_DBUS_CALL_FLAGS_NONE,
2114 if (reply == NULL) {
2115 BT_ERR("_bt_le_write_host_suggested_default_data_length dBUS-RPC failed");
2116 if (error != NULL) {
2117 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
2118 error->code, error->message);
2119 g_clear_error(&error);
2121 return BLUETOOTH_ERROR_INTERNAL;
2124 g_variant_unref(reply);
2126 return BLUETOOTH_ERROR_NONE;
2129 int _bt_le_read_host_suggested_default_data_length(
2130 bluetooth_le_read_host_suggested_data_length_t *def_data_length)
2132 GError *error = NULL;
2134 GVariant *reply = NULL;
2135 guint16 def_tx_octets, def_tx_time;
2137 proxy = _bt_get_adapter_proxy();
2138 retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2140 reply = g_dbus_proxy_call_sync(proxy, "LEReadHostSuggestedDataLength",
2141 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
2143 if (reply == NULL) {
2144 BT_ERR("LEReadHostSuggestedDataLength dBUS-RPC failed");
2145 if (error != NULL) {
2146 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
2147 error->code, error->message);
2148 g_clear_error(&error);
2150 return BLUETOOTH_ERROR_INTERNAL;
2153 g_variant_get(reply, "(qq)", &def_tx_octets, &def_tx_time);
2155 def_data_length->def_tx_octets = def_tx_octets;
2156 def_data_length->def_tx_time = def_tx_time;
2158 g_variant_unref(reply);
2160 return BLUETOOTH_ERROR_NONE;
2163 int _bt_le_set_data_length(bluetooth_device_address_t *device_address,
2164 const unsigned int max_tx_Octets, const unsigned int max_tx_Time)
2166 GError *error = NULL;
2167 guint16 txOctets = max_tx_Octets;
2168 guint16 txTime = max_tx_Time;
2169 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
2170 gchar *device_path = NULL;
2171 GDBusConnection *conn;
2172 GDBusProxy *device_proxy;
2174 _bt_convert_addr_type_to_string(address, device_address->addr);
2176 device_path = _bt_get_device_object_path(address);
2178 if (device_path == NULL) {
2179 BT_DBG("Device path is null");
2180 return BLUETOOTH_ERROR_INTERNAL;
2183 conn = _bt_gdbus_get_system_gconn();
2185 BT_ERR("conn == NULL");
2186 g_free(device_path);
2187 return BLUETOOTH_ERROR_INTERNAL;
2190 device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
2191 NULL, BT_BLUEZ_NAME,
2192 device_path, BT_DEVICE_INTERFACE, NULL, NULL);
2194 g_free(device_path);
2195 retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
2197 g_dbus_proxy_call_sync(device_proxy,
2199 g_variant_new("(qq)", txOctets, txTime),
2200 G_DBUS_CALL_FLAGS_NONE,
2205 g_object_unref(device_proxy);
2208 BT_ERR("LESetDataLength error: [%s]", error->message);
2209 g_error_free(error);
2210 return BLUETOOTH_ERROR_INTERNAL;
2213 return BLUETOOTH_ERROR_NONE;
2216 int _bt_service_adapter_le_init(void)
2218 le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max);
2220 return BLUETOOTH_ERROR_NONE;
2223 void _bt_service_adapter_le_deinit(void)
2225 __bt_free_le_adv_slot();
2226 __bt_free_le_scanner();