Code Sync [Tizen3.0]: Merged the tizen_2.4 Spin code to tizen.org
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-adapter-le.c
1 /*
2  * Bluetooth-frwk
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
7  *               Girishashok Joshi <girish.joshi@samsung.com>
8  *               Chanyeol Park <chanyeol.park@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *              http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23
24 #include <stdio.h>
25 #include <dbus/dbus-glib.h>
26 #include <dbus/dbus.h>
27 #include <glib.h>
28 #include <dlog.h>
29 #include <string.h>
30 #include <vconf.h>
31 #include <syspopup_caller.h>
32 #include <aul.h>
33 #include <notification.h>
34 //#include <journal/device.h>
35
36 #include "bt-internal-types.h"
37 #include "bt-service-common.h"
38 #include "bt-service-event.h"
39 #include "bt-service-adapter.h"
40 #include "bt-service-adapter-le.h"
41
42
43 #define BT_ADV_INTERVAL_MIN 20 /* msec */
44 #define BT_ADV_INTERVAL_MAX 10240
45 #define BT_ADV_INTERVAL_SPLIT 0.625
46 #define BT_DEFAULT_ADV_MIN_INTERVAL 500
47 #define BT_DEFAULT_ADV_MAX_INTERVAL 500
48 #define BT_ADV_FILTER_POLICY_DEFAULT    0x00
49 #define BT_ADV_TYPE_DEFAULT     0x00
50 #define BT_ADV_FILTER_POLICY_ALLOW_SCAN_CONN_WL_ONLY    0x03
51
52 typedef struct {
53         int adv_inst_max;
54         int rpa_offloading;
55         int max_filter;
56 } bt_adapter_le_feature_info_t;
57
58 typedef struct {
59         char *sender;
60         gboolean is_advertising;
61 } bt_adapter_le_adv_slot_t;
62
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,
67         BT_ADV_TYPE_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;
72
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;
75
76 void __bt_free_le_adv_slot(void)
77 {
78         int i;
79
80         if (le_adv_slot == NULL)
81                 return;
82
83         for (i = 0; i < le_feature_info.adv_inst_max; i++) {
84                 if (le_adv_slot[i].sender)
85                         g_free(le_adv_slot[i].sender);
86         }
87         g_free(le_adv_slot);
88         le_adv_slot = NULL;
89 }
90
91 int _bt_service_adapter_le_init(void)
92 {
93         le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max);
94
95         return BLUETOOTH_ERROR_NONE;
96 }
97
98 void _bt_service_adapter_le_deinit(void)
99 {
100         __bt_free_le_adv_slot();
101 }
102
103 gboolean _bt_update_le_feature_support(const char *item, const char *value)
104 {
105         if (item== NULL || value == NULL)
106                 return FALSE;
107
108         if (g_strcmp0(item, "adv_inst_max") == 0) {
109                 if (atoi(value) != le_feature_info.adv_inst_max) {
110                         __bt_free_le_adv_slot();
111                         le_feature_info.adv_inst_max = atoi(value);
112                         le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max);
113                 }
114         } else if (g_strcmp0(item, "rpa_offloading") == 0) {
115                 le_feature_info.rpa_offloading = atoi(value);
116         } else if (g_strcmp0(item, "max_filter") == 0) {
117                 le_feature_info.max_filter = atoi(value);
118         } else {
119                 BT_DBG("No registered item");
120                 return FALSE;
121         }
122
123         return TRUE;
124 }
125
126 static gboolean __bt_is_factory_test_mode(void)
127 {
128         int mode = 0;
129 #ifdef ENABLE_TIZEN_2_4
130         if (vconf_get_bool(VCONFKEY_BT_DUT_MODE, &mode)) {
131                 BT_ERR("Get the DUT Mode fail");
132                 return TRUE;
133         }
134 #endif
135         if (mode != FALSE) {
136                 BT_INFO("DUT Test Mode !!");
137                 return TRUE;
138         }
139
140         return FALSE;
141 }
142
143 int __bt_get_available_adv_slot_id(const char *sender, gboolean use_reserved_slot)
144 {
145         int i;
146
147         if (le_adv_slot == NULL)
148                 return -1;
149
150         if (use_reserved_slot == TRUE) {
151                 if (le_feature_info.adv_inst_max > 1)
152                         return 0;
153                 else if (le_adv_slot[0].sender == NULL ||
154                         g_strcmp0(le_adv_slot[0].sender, sender) == 0)
155                         return 0;
156                 else
157                         return -1;
158         }
159
160         for (i = 0; i < le_feature_info.adv_inst_max; i++) {
161                 if (le_adv_slot[i].sender == NULL)
162                         continue;
163                 if (g_strcmp0(le_adv_slot[i].sender, sender) == 0)
164                         return i;
165         }
166
167         for (i = 0; i < le_feature_info.adv_inst_max; i++) {
168                 if (le_adv_slot[i].sender == NULL)
169                         return i;
170         }
171
172         return -1;
173 }
174
175 void __bt_register_adv_slot_owner(const char *sender, int slot_id)
176 {
177         if (le_adv_slot[slot_id].sender == NULL)
178                 le_adv_slot[slot_id].sender = strdup(sender);
179 }
180
181 void __bt_unregister_adv_slot_owner(int slot_id)
182 {
183         g_free(le_adv_slot[slot_id].sender);
184         le_adv_slot[slot_id].sender = NULL;
185         le_adv_slot[slot_id].is_advertising = FALSE;
186 }
187
188 const char* _bt_get_adv_slot_owner(int slot_id)
189 {
190         if (le_adv_slot == NULL)
191                 return NULL;
192
193         return le_adv_slot[slot_id].sender;
194 }
195
196 void _bt_set_advertising_status(int slot_id, gboolean mode)
197 {
198         le_adv_slot[slot_id].is_advertising = mode;
199 }
200
201 gboolean _bt_is_advertising(void)
202 {
203         gboolean status = FALSE;
204         int i;
205
206         for (i = 0; i < le_feature_info.adv_inst_max; i++) {
207                 if (le_adv_slot[i].is_advertising == TRUE)
208                         status = TRUE;
209         }
210
211         return status;
212 }
213
214 void _bt_stop_advertising_by_terminated_process(const char* terminated_name)
215 {
216         int i;
217
218         if (le_adv_slot == NULL)
219                 return;
220
221         for (i = 0; i < le_feature_info.adv_inst_max; i++) {
222                 if (le_adv_slot[i].sender != NULL) {
223                         if (strcasecmp(terminated_name, le_adv_slot[i].sender) == 0) {
224                                 BT_ERR("Stop advertising by terminated process(%s).", terminated_name);
225                                 _bt_set_advertising(FALSE, terminated_name, FALSE);
226                         }
227                 }
228         }
229 }
230
231 gboolean _bt_get_advertising_params(bluetooth_advertising_params_t *params)
232 {
233         if (params == NULL)
234                 return FALSE;
235
236         memcpy(params, &adv_params, sizeof(bluetooth_advertising_params_t));
237
238         return TRUE;
239 }
240
241 int _bt_set_advertising(gboolean enable, const char *sender, gboolean use_reserved_slot)
242 {
243         DBusGProxy *proxy;
244         GError *error = NULL;
245         int slot_id;
246
247         if (__bt_is_factory_test_mode()) {
248                 BT_ERR("Unable to start advertising in factory binary !!");
249                 return BLUETOOTH_ERROR_NOT_SUPPORT;
250         }
251
252         if (_bt_adapter_get_status() != BT_ACTIVATED &&
253                 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
254                 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
255         }
256
257         slot_id = __bt_get_available_adv_slot_id(sender, use_reserved_slot);
258         if (slot_id == -1) {
259                 BT_ERR("There is NO available slot!!");
260                 return BLUETOOTH_ERROR_NO_RESOURCES;
261         }
262
263         if (le_adv_slot[slot_id].is_advertising == TRUE && enable == TRUE)
264                 return BLUETOOTH_ERROR_IN_PROGRESS;
265
266         if (le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
267                 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
268
269         proxy = _bt_get_adapter_proxy();
270         retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
271
272         dbus_g_proxy_call(proxy, "SetAdvertising", &error,
273                         G_TYPE_BOOLEAN, enable,
274                         G_TYPE_INT, slot_id,
275                         G_TYPE_INVALID, G_TYPE_INVALID);
276
277         if (error) {
278                 BT_ERR("SetAdvertising Fail: %s", error->message);
279                 g_error_free(error);
280                 return BLUETOOTH_ERROR_INTERNAL;
281         }
282
283         le_adv_slot[slot_id].is_advertising = enable;
284
285         if (enable == TRUE)
286                 __bt_register_adv_slot_owner(sender, slot_id);
287         else
288                 __bt_unregister_adv_slot_owner(slot_id);
289
290         BT_INFO("Set advertising [%d]", enable);
291
292         return BLUETOOTH_ERROR_NONE;
293 }
294
295 int _bt_set_custom_advertising(gboolean enable, bluetooth_advertising_params_t *params,
296                                 const char *sender, gboolean use_reserved_slot)
297 {
298         DBusGProxy *proxy;
299         GError *error = NULL;
300         guint32 min = 0;
301         guint32 max = 0;
302         int slot_id;
303
304         BT_CHECK_PARAMETER(params, return);
305
306         if (__bt_is_factory_test_mode()) {
307                 BT_ERR("Unable to start advertising in factory binary !!");
308                 return BLUETOOTH_ERROR_NOT_SUPPORT;
309         }
310
311         if (_bt_adapter_get_status() != BT_ACTIVATED &&
312                 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
313                 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
314         }
315
316         if (le_adv_slot[slot_id].is_advertising == TRUE && enable == TRUE)
317                 return BLUETOOTH_ERROR_IN_PROGRESS;
318
319         if (le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
320                 return BLUETOOTH_ERROR_NOT_IN_OPERATION;
321
322         proxy = _bt_get_adapter_proxy();
323         retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
324
325         if (params->interval_min > params->interval_max ||
326                         params->interval_min < BT_ADV_INTERVAL_MIN ||
327                         params->interval_max > BT_ADV_INTERVAL_MAX)
328                 return BLUETOOTH_ERROR_INVALID_PARAM;
329
330         if (params->filter_policy > BLUETOOTH_ALLOW_SCAN_CONN_WHITE_LIST)
331                 return BLUETOOTH_ERROR_INVALID_PARAM;
332
333         if (params->type  == BLUETOOTH_ADV_CONNECTABLE_DIRECT_HIGH ||
334                         params->type == BLUETOOTH_ADV_CONNECTABLE_DIRECT_LOW ||
335                         params->type == BLUETOOTH_ADV_NON_CONNECTABLE)
336                 return BLUETOOTH_ERROR_NOT_SUPPORT;
337
338         min = params->interval_min / BT_ADV_INTERVAL_SPLIT;
339         max = params->interval_max / BT_ADV_INTERVAL_SPLIT;
340
341         slot_id = __bt_get_available_adv_slot_id(sender, use_reserved_slot);
342         if (slot_id == -1) {
343                 BT_ERR("There is NO available slot!!");
344                 return BLUETOOTH_ERROR_NO_RESOURCES;
345         }
346
347         dbus_g_proxy_call(proxy, "SetAdvertisingParameters", &error,
348                         G_TYPE_UINT, min,
349                         G_TYPE_UINT, max,
350                         G_TYPE_UINT, params->filter_policy,
351                         G_TYPE_UINT, params->type,
352                         G_TYPE_INT, slot_id,
353                         G_TYPE_INVALID, G_TYPE_INVALID);
354
355         if (error) {
356                 BT_ERR("SetAdvertisingParameters Fail: %s", error->message);
357                 g_error_free(error);
358                 return BLUETOOTH_ERROR_INTERNAL;
359         }
360
361         adv_params.interval_min = params->interval_min;
362         adv_params.interval_max = params->interval_max;
363         adv_params.filter_policy = params->filter_policy;
364         adv_params.type= params->type;
365
366         dbus_g_proxy_call(proxy, "SetAdvertising", &error,
367                         G_TYPE_BOOLEAN, enable,
368                         G_TYPE_INT, slot_id,
369                         G_TYPE_INVALID, G_TYPE_INVALID);
370
371         if (error) {
372                 BT_ERR("SetAdvertising Fail: %s", error->message);
373                 g_error_free(error);
374                 return BLUETOOTH_ERROR_INTERNAL;
375         }
376
377         le_adv_slot[slot_id].is_advertising = enable;
378
379         if (enable == TRUE)
380                 __bt_register_adv_slot_owner(sender, slot_id);
381         else
382                 __bt_unregister_adv_slot_owner(slot_id);
383
384         BT_INFO_C("Set advertising [%d]", enable);
385         return BLUETOOTH_ERROR_NONE;
386 }
387
388 static int __bt_get_ad_data_by_type(char *in_data, int in_len,
389                 char in_type, char **data, int *data_len)
390 {
391         if (in_data == NULL || data == NULL || data_len == NULL)
392                 return BLUETOOTH_ERROR_INTERNAL;
393
394         if (in_len < 0)
395                 return BLUETOOTH_ERROR_INTERNAL;
396
397         int i;
398         int len = 0;
399         int type = 0;
400
401         for (i = 0; i < in_len; i++) {
402                 len = in_data[i];
403                 if (len <= 0 || i + 1 >= in_len) {
404                         BT_ERR("Invalid advertising data");
405                         return BLUETOOTH_ERROR_INTERNAL;
406                 }
407
408                 type = in_data[i + 1];
409                 if (type == in_type) {
410                         i = i + 2;
411                         len--;
412                         break;
413                 }
414
415                 i += len;
416                 len = 0;
417         }
418
419         if (i + len > in_len) {
420                 BT_ERR("Invalid advertising data");
421                 return BLUETOOTH_ERROR_INTERNAL;
422         } else if (len == 0) {
423                 BT_DBG("AD Type 0x%02x data is not set", in_type);
424                 *data = NULL;
425                 *data_len = 0;
426                 return BLUETOOTH_ERROR_NONE;
427         }
428
429         *data = g_memdup(&in_data[i], len);
430         if (*data == NULL)
431                 return BLUETOOTH_ERROR_OUT_OF_MEMORY;
432         *data_len = len;
433
434         return BLUETOOTH_ERROR_NONE;
435 }
436
437 int _bt_get_advertising_data(bluetooth_advertising_data_t *adv, int *length)
438 {
439         BT_CHECK_PARAMETER(adv, return);
440         BT_CHECK_PARAMETER(length, return);
441
442         memcpy(adv, &adv_data, sizeof(adv_data));
443         *length = adv_data_len;
444
445         return BLUETOOTH_ERROR_NONE;
446 }
447
448 int _bt_set_advertising_data(bluetooth_advertising_data_t *adv, int length,
449                                 const char *sender, gboolean use_reserved_slot)
450 {
451         DBusGProxy *proxy;
452         GError *error = NULL;
453         GArray *arr;
454         int i;
455         char *old_mdata = NULL;
456         char *new_mdata = NULL;
457         int old_len = 0;
458         int new_len = 0;
459         int slot_id;
460
461         if (__bt_is_factory_test_mode()) {
462                 BT_ERR("Unable to set advertising data in factory binary !!");
463                 return BLUETOOTH_ERROR_NOT_SUPPORT;
464         }
465
466         BT_CHECK_PARAMETER(adv, return);
467
468         if (_bt_adapter_get_status() != BT_ACTIVATED &&
469                 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
470                 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
471         }
472
473         proxy = _bt_get_adapter_proxy();
474         retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
475
476         arr = g_array_new(TRUE, TRUE, sizeof(guint8));
477
478         for (i = 0; i < length; i++)
479                 g_array_append_vals(arr, &(adv->data[i]), sizeof(guint8));
480
481         slot_id = __bt_get_available_adv_slot_id(sender, use_reserved_slot);
482         if (slot_id == -1) {
483                 BT_ERR("There is NO available slot!!");
484                 return BLUETOOTH_ERROR_NO_RESOURCES;
485         }
486
487         dbus_g_proxy_call(proxy, "SetAdvertisingData", &error,
488                         DBUS_TYPE_G_UCHAR_ARRAY, arr,
489                         G_TYPE_INT, slot_id,
490                         G_TYPE_INVALID, G_TYPE_INVALID);
491
492         g_array_free(arr, TRUE);
493
494         if (error) {
495                 BT_ERR("SetAdvertisingData Fail: %s", error->message);
496                 g_error_free(error);
497                 return BLUETOOTH_ERROR_INTERNAL;
498         }
499
500         __bt_register_adv_slot_owner(sender, slot_id);
501
502         __bt_get_ad_data_by_type((char *)adv_data.data, adv_data_len, 0xff,
503                         &old_mdata, &old_len);
504         __bt_get_ad_data_by_type((char *)adv->data, length, 0xff,
505                         &new_mdata, &new_len);
506         if (old_len != new_len ||
507                         (old_mdata && new_mdata &&
508                          memcmp(old_mdata, new_mdata, new_len))) {
509                 _bt_send_event(BT_ADAPTER_EVENT,
510                                 BLUETOOTH_EVENT_ADVERTISING_MANUFACTURER_DATA_CHANGED,
511                                 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
512                                 &new_mdata, new_len,
513                                 DBUS_TYPE_INVALID);
514         }
515         g_free(new_mdata);
516         g_free(old_mdata);
517
518         memset(&adv_data, 0x00, sizeof(bluetooth_advertising_data_t));
519         memcpy(&adv_data, adv, length);
520         adv_data_len = length;
521
522         BT_INFO("Set advertising data");
523
524         return BLUETOOTH_ERROR_NONE;
525 }
526
527 int _bt_get_scan_response_data(bluetooth_scan_resp_data_t *response, int *length)
528 {
529         BT_CHECK_PARAMETER(response, return);
530         BT_CHECK_PARAMETER(length, return);
531
532         memcpy(response, &resp_data, sizeof(resp_data));
533         *length = resp_data_len;
534
535         return BLUETOOTH_ERROR_NONE;
536 }
537
538 int _bt_set_scan_response_data(bluetooth_scan_resp_data_t *response, int length,
539                                 const char *sender, gboolean use_reserved_slot)
540 {
541         DBusGProxy *proxy;
542         GError *error = NULL;
543         GArray *arr;
544         int i;
545         char *old_mdata = NULL;
546         char *new_mdata = NULL;
547         int old_len = 0;
548         int new_len = 0;
549         int slot_id;
550
551         if (__bt_is_factory_test_mode()) {
552                 BT_ERR("Unable to set scan response list in factory binary !!");
553                 return BLUETOOTH_ERROR_NOT_SUPPORT;
554         }
555
556         BT_CHECK_PARAMETER(response, return);
557
558         if (_bt_adapter_get_status() != BT_ACTIVATED &&
559                 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
560                 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
561         }
562
563         proxy = _bt_get_adapter_proxy();
564         retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
565
566         arr = g_array_new(TRUE, TRUE, sizeof(guint8));
567
568         for (i = 0; i < length; i++)
569                 g_array_append_vals(arr, &(response->data[i]), sizeof(guint8));
570
571         slot_id = __bt_get_available_adv_slot_id(sender, use_reserved_slot);
572         if (slot_id == -1) {
573                 BT_ERR("There is NO available slot!!");
574                 return BLUETOOTH_ERROR_NO_RESOURCES;
575         }
576
577         dbus_g_proxy_call(proxy, "SetScanRespData", &error,
578                         DBUS_TYPE_G_UCHAR_ARRAY, arr,
579                         G_TYPE_INT, slot_id,
580                         G_TYPE_INVALID, G_TYPE_INVALID);
581
582         g_array_free(arr, TRUE);
583
584         if (error) {
585                 BT_ERR("SetScanRespData Fail: %s", error->message);
586                 g_error_free(error);
587                 return BLUETOOTH_ERROR_INTERNAL;
588         }
589
590         __bt_register_adv_slot_owner(sender, slot_id);
591
592         /* Compare with previous scan resp data */
593         __bt_get_ad_data_by_type((char *)resp_data.data, resp_data_len, 0xff,
594                         &old_mdata, &old_len);
595         __bt_get_ad_data_by_type((char *)response->data, length, 0xff,
596                         &new_mdata, &new_len);
597         if (old_len != new_len ||
598                         (old_mdata && new_mdata &&
599                          memcmp(old_mdata, new_mdata, new_len))) {
600                 _bt_send_event(BT_ADAPTER_EVENT,
601                                 BLUETOOTH_EVENT_SCAN_RESPONSE_MANUFACTURER_DATA_CHANGED,
602                                 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
603                                 &new_mdata, new_len,
604                                 DBUS_TYPE_INVALID);
605         }
606         g_free(new_mdata);
607         g_free(old_mdata);
608
609         memset(&resp_data, 0x00, sizeof(bluetooth_scan_resp_data_t));
610         memcpy(&resp_data, response, length);
611         resp_data_len = length;
612
613         BT_INFO("Set scan response data");
614         return BLUETOOTH_ERROR_NONE;
615 }
616
617 int _bt_set_scan_parameters(bluetooth_le_scan_params_t *params)
618 {
619         DBusGProxy *proxy;
620         GError *error = NULL;
621         guint32 itv = 0;
622         guint32 win = 0;
623
624         BT_CHECK_PARAMETER(params, return);
625
626         if (_bt_adapter_get_status() != BT_ACTIVATED &&
627                 _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
628                 return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
629         }
630
631         proxy = _bt_get_adapter_proxy();
632         retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
633
634         if (params->interval < BT_LE_SCAN_INTERVAL_MIN || params->interval > BT_LE_SCAN_INTERVAL_MAX)
635                 return BLUETOOTH_ERROR_INVALID_PARAM;
636
637         if (params->window < BT_LE_SCAN_WINDOW_MIN || params->window > BT_LE_SCAN_WINDOW_MAX)
638                 return BLUETOOTH_ERROR_INVALID_PARAM;
639
640         if (params->window > params->interval)
641                 return BLUETOOTH_ERROR_INVALID_PARAM;
642
643         itv = params->interval / BT_ADV_INTERVAL_SPLIT;
644         win = params->window / BT_ADV_INTERVAL_SPLIT;
645
646         dbus_g_proxy_call(proxy, "SetScanParameters", &error,
647                         G_TYPE_UINT, params->type,
648                         G_TYPE_UINT, itv,
649                         G_TYPE_UINT, win,
650                         G_TYPE_INVALID, G_TYPE_INVALID);
651
652         if (error) {
653                 BT_ERR("SetScanParameters Fail: %s", error->message);
654                 g_error_free(error);
655                 return BLUETOOTH_ERROR_INTERNAL;
656         }
657
658         _bt_set_le_discovery_type(params->type);
659
660         BT_INFO("Set scan parameters");
661         return BLUETOOTH_ERROR_NONE;
662 }
663
664 int _bt_add_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type)
665 {
666         DBusGProxy *proxy;
667         char address[BT_ADDRESS_STRING_SIZE] = { 0 };
668         GError *error = NULL;
669
670         if (__bt_is_factory_test_mode()) {
671                 BT_ERR("Unable to add white list in factory binary !!");
672                 return BLUETOOTH_ERROR_NOT_SUPPORT;
673         }
674
675         BT_CHECK_PARAMETER(device_address, return);
676
677         if (address_type != BLUETOOTH_DEVICE_PUBLIC_ADDRESS &&
678                 address_type != BLUETOOTH_DEVICE_RANDOM_ADDRESS)
679                 return BLUETOOTH_ERROR_INVALID_PARAM;
680
681         _bt_convert_addr_type_to_string(address, device_address->addr);
682
683         proxy = _bt_get_adapter_proxy();
684         retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
685
686         dbus_g_proxy_call(proxy, "AddDeviceWhiteList", &error,
687                   G_TYPE_STRING, address,
688                   G_TYPE_UINT, address_type,
689                   G_TYPE_INVALID, G_TYPE_INVALID);
690
691         if (error) {
692                 BT_ERR("AddDeviceWhiteList Fail: %s", error->message);
693                 g_error_free(error);
694                 return BLUETOOTH_ERROR_INTERNAL;
695         }
696
697         BT_INFO("Add white list");
698
699         return BLUETOOTH_ERROR_NONE;
700 }
701
702 int _bt_remove_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type)
703 {
704         DBusGProxy *proxy;
705         char address[BT_ADDRESS_STRING_SIZE] = { 0 };
706         GError *error = NULL;
707
708         if (__bt_is_factory_test_mode()) {
709                 BT_ERR("Unable to remove white list in factory binary !!");
710                 return BLUETOOTH_ERROR_NOT_SUPPORT;
711         }
712
713         BT_CHECK_PARAMETER(device_address, return);
714
715         if (address_type != BLUETOOTH_DEVICE_PUBLIC_ADDRESS &&
716                 address_type != BLUETOOTH_DEVICE_RANDOM_ADDRESS)
717                 return BLUETOOTH_ERROR_INVALID_PARAM;
718
719         _bt_convert_addr_type_to_string(address, device_address->addr);
720
721         proxy = _bt_get_adapter_proxy();
722         retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
723
724         dbus_g_proxy_call(proxy, "RemoveDeviceWhiteList", &error,
725                   G_TYPE_STRING, address,
726                    G_TYPE_UINT, address_type,
727                   G_TYPE_INVALID, G_TYPE_INVALID);
728
729         if (error) {
730                 BT_ERR("RemoveDeviceWhiteList Fail: %s", error->message);
731                 g_error_free(error);
732                 return BLUETOOTH_ERROR_INTERNAL;
733         }
734
735         BT_INFO("Remove white list");
736
737         return BLUETOOTH_ERROR_NONE;
738 }
739
740 int _bt_clear_white_list(void)
741 {
742         DBusGProxy *proxy;
743         GError *error = NULL;
744
745         if (__bt_is_factory_test_mode()) {
746                 BT_ERR("Unable to clear white list in factory binary !!");
747                 return BLUETOOTH_ERROR_NOT_SUPPORT;
748         }
749
750         proxy = _bt_get_adapter_proxy();
751         retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
752
753         dbus_g_proxy_call(proxy, "ClearDeviceWhiteList", &error,
754                   G_TYPE_INVALID, G_TYPE_INVALID);
755
756         if (error) {
757                 BT_ERR("ClearDeviceWhiteList Fail: %s", error->message);
758                 g_error_free(error);
759                 return BLUETOOTH_ERROR_INTERNAL;
760         }
761
762         BT_INFO("Clear white list");
763
764         return BLUETOOTH_ERROR_NONE;
765 }
766