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.
22 #include <cynara-client.h>
23 #include <cynara-creds-gdbus.h>
25 #include "bluetooth-api.h"
26 #include "bt-service-common.h"
27 #include "bt-service-util.h"
28 #include "bt-service-event.h"
29 #include "bt-service-adapter.h"
30 #include "bt-service-adapter-le.h"
31 #include "bt-service-device.h"
32 #include "bt-service-hid.h"
33 #include "bt-service-network.h"
34 #include "bt-service-audio.h"
35 #include "bt-service-oob.h"
36 #include "bt-service-avrcp.h"
37 #include "bt-service-avrcp-controller.h"
38 #include "bt-service-opp-client.h"
39 #include "bt-service-obex-server.h"
40 #include "bt-service-rfcomm-client.h"
41 #include "bt-service-rfcomm-server.h"
42 #include "bt-request-handler.h"
43 #include "bt-service-pbap.h"
44 #include "bt-service-dpm.h"
46 static GDBusConnection *bt_service_conn;
47 static guint owner_id = 0;
49 cynara_configuration *conf;
51 static const gchar bt_service_introspection_xml[] =
52 "<node name='/org/projectx/bt_service'>"
53 " <interface name='org.projectx.bt'>"
54 " <method name='service_request'>"
55 /* Input Parameters */
56 " <arg type='i' name='service_type' direction='in' />"
57 " <arg type='i' name='service_function' direction='in' />"
58 " <arg type='i' name='request_type' direction='in' />"
59 " <arg type='ay' name='input_param1' direction='in' />"
60 " <arg type='ay' name='input_param2' direction='in' />"
61 " <arg type='ay' name='input_param3' direction='in' />"
62 " <arg type='ay' name='input_param4' direction='in' />"
63 " <arg type='ay' name='input_param5' direction='in' />"
64 /* Return Parameters */
65 " <arg type='i' name='output_param1' direction='out' />"
66 " <arg type='v' name='output_param2' direction='out' />"
71 GDBusNodeInfo *node_info = NULL;
73 static void __bt_service_method(GDBusConnection *connection,
75 const gchar *object_path,
76 const gchar *interface_name,
77 const gchar *method_name,
79 GDBusMethodInvocation *invocation,
82 int __bt_bluez_request(int function_name,
85 GDBusMethodInvocation *context,
91 int __bt_obexd_request(int function_name,
94 GDBusMethodInvocation *context,
100 GArray **out_param1);
101 int __bt_agent_request(int function_name,
104 GDBusMethodInvocation *context,
109 GArray **out_param1);
110 int __bt_core_request(int function_name,
113 GDBusMethodInvocation *context,
114 GVariant *in_param1);
116 gboolean __bt_service_check_privilege(int function_name,
118 const char *unique_name);
120 /* Function definitions*/
121 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
126 size = g_variant_get_size(var);
128 data = (char *)g_variant_get_data(var);
130 param = g_array_append_vals(param, data, size);
135 static void __bt_service_get_parameters(GVariant *in_param,
136 void *value, int size)
139 buf = (void *)g_variant_get_data(in_param);
140 memcpy(value, buf, size);
143 static void __bt_service_method(GDBusConnection *connection,
145 const gchar *object_path,
146 const gchar *interface_name,
147 const gchar *method_name,
148 GVariant *parameters,
149 GDBusMethodInvocation *invocation,
153 BT_DBG("Method[%s] Object Path[%s] Interface Name[%s]",
154 method_name, object_path, interface_name);
156 if (g_strcmp0(method_name, "service_request") == 0) {
158 int service_function;
160 GVariant *param1 = NULL;
161 GVariant *param2 = NULL;
162 GVariant *param3 = NULL;
163 GVariant *param4 = NULL;
164 GVariant *param5 = NULL;
165 GArray *out_param1 = NULL;
166 GVariant *out_var = NULL;
169 const char *sender = NULL;
171 g_variant_get(parameters, "(iii@ay@ay@ay@ay@ay)", &service_type,
172 &service_function, &request_type,
173 ¶m1, ¶m2, ¶m3, ¶m4, ¶m5);
175 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
177 sender = g_dbus_method_invocation_get_sender(invocation);
179 if (service_type == BT_CORE_SERVICE) {
180 BT_DBG("No need to check privilege from bt-core");
181 } else if (__bt_service_check_privilege(service_function,
182 service_type, (const char *)sender) == FALSE) {
183 BT_ERR("Client don't have the privilege to excute this function");
184 result = BLUETOOTH_ERROR_PERMISSION_DEINED;
188 if (request_type == BT_ASYNC_REQ
189 || service_function == BT_OBEX_SERVER_ACCEPT_CONNECTION) {
191 request_id = _bt_assign_request_id();
192 BT_DBG("Request ID: %d", request_id);
194 if (request_id < 0) {
195 BT_ERR("Fail to assign the request id");
196 result = BLUETOOTH_ERROR_INTERNAL;
202 BT_DBG("SERVICE TYPE [%d] SERVICE FUNC [%d]",
203 service_type, service_function);
204 switch (service_type) {
205 case BT_BLUEZ_SERVICE:
206 result = __bt_bluez_request(service_function,
207 request_type, request_id,
208 invocation, param1, param2,
209 param3, param4, &out_param1);
211 case BT_OBEX_SERVICE:
212 result = __bt_obexd_request(service_function,
213 request_type, request_id,
216 param4, param5, &out_param1);
218 case BT_AGENT_SERVICE:
219 result = __bt_agent_request(service_function,
220 request_type, request_id,
223 param4, &out_param1);
225 case BT_CORE_SERVICE:
226 result = __bt_core_request(service_function,
227 request_type, request_id,
230 case BT_CHECK_PRIVILEGE:
231 result = BLUETOOTH_ERROR_NONE;
234 BT_ERR("Unknown service type");
235 result = BLUETOOTH_ERROR_INTERNAL;
239 if (result != BLUETOOTH_ERROR_NONE) {
243 if ((request_type == BT_ASYNC_REQ ||
244 service_function == BT_OBEX_SERVER_ACCEPT_CONNECTION) &&
245 service_function != BT_OPP_PUSH_FILES) {
246 BT_DBG("INSERT INTO REQ LIST");
247 _bt_insert_request_list(request_id, service_function,
251 if (service_type == BT_CHECK_PRIVILEGE ||
252 service_function != BT_OPP_PUSH_FILES) {
253 out_var = g_variant_new_from_data((const GVariantType *)"ay",
254 out_param1->data, out_param1->len,
257 GVariant *temp = g_variant_new("(iv)", result, out_var);
258 g_dbus_method_invocation_return_value(invocation, temp);
260 g_array_free(out_param1, TRUE);
265 g_variant_unref(param1);
266 g_variant_unref(param2);
267 g_variant_unref(param3);
268 g_variant_unref(param4);
269 g_variant_unref(param5);
274 BT_ERR_C("Request is failed [%s] [%x]",
275 _bt_convert_error_to_string(result), result);
277 out_var = g_variant_new_from_data((const GVariantType *)"ay",
278 out_param1->data, out_param1->len,
281 GVariant *temp = g_variant_new("(iv)", result, out_var);
282 g_dbus_method_invocation_return_value(invocation, temp);
284 g_array_free(out_param1, TRUE);
287 if (request_type == BT_ASYNC_REQ)
288 _bt_delete_request_id(request_id);
290 g_variant_unref(param1);
291 g_variant_unref(param2);
292 g_variant_unref(param3);
293 g_variant_unref(param4);
294 g_variant_unref(param5);
303 static const GDBusInterfaceVTable method_table = {
309 int __bt_bluez_request(int function_name,
312 GDBusMethodInvocation *context,
319 int result = BLUETOOTH_ERROR_NONE;
321 switch (function_name) {
322 case BT_ENABLE_ADAPTER:
323 result = _bt_enable_adapter();
325 case BT_DISABLE_ADAPTER:
326 result = _bt_disable_adapter();
328 case BT_RECOVER_ADAPTER:
329 result = _bt_recover_adapter();
331 case BT_ENABLE_ADAPTER_LE:
332 result = _bt_enable_adapter_le();
334 case BT_DISABLE_ADAPTER_LE:
335 result = _bt_disable_adapter_le();
337 case BT_RESET_ADAPTER:
338 result = _bt_reset_adapter();
340 case BT_CHECK_ADAPTER: {
341 int enabled = BT_ADAPTER_DISABLED;
343 result = _bt_check_adapter(&enabled);
345 g_array_append_vals(*out_param1, &enabled,
349 case BT_GET_LOCAL_ADDRESS: {
350 bluetooth_device_address_t local_address = { {0} };
351 result = _bt_get_local_address(&local_address);
353 g_array_append_vals(*out_param1, &local_address,
354 sizeof(bluetooth_device_address_t));
357 case BT_GET_LOCAL_VERSION: {
358 bluetooth_version_t ver = { {0} };
359 result = _bt_get_local_version(&ver);
361 g_array_append_vals(*out_param1, &ver,
362 sizeof(bluetooth_version_t));
365 case BT_GET_LOCAL_NAME: {
366 bluetooth_device_name_t local_name = { {0} };
367 result = _bt_get_local_name(&local_name);
369 g_array_append_vals(*out_param1, &local_name,
370 sizeof(bluetooth_device_name_t));
374 case BT_SET_LOCAL_NAME: {
375 bluetooth_device_name_t local_name = { {0} };
376 __bt_service_get_parameters(in_param1,
377 &local_name, sizeof(bluetooth_device_name_t));
379 result = _bt_set_local_name(local_name.name);
383 case BT_IS_SERVICE_USED: {
385 gboolean used = FALSE;
387 uuid = (char *)g_variant_get_data(in_param1);
389 result = _bt_is_service_used(uuid, &used);
391 if (result == BLUETOOTH_ERROR_NONE) {
392 g_array_append_vals(*out_param1, &used,
397 case BT_GET_DISCOVERABLE_MODE: {
398 int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
400 result = _bt_get_discoverable_mode(&mode);
402 g_array_append_vals(*out_param1, &mode, sizeof(int));
405 case BT_SET_DISCOVERABLE_MODE: {
406 int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
409 __bt_service_get_parameters(in_param1, &mode, sizeof(int));
410 __bt_service_get_parameters(in_param2, &time, sizeof(int));
412 result = _bt_set_discoverable_mode(mode, time);
415 case BT_GET_DISCOVERABLE_TIME: {
418 result = _bt_get_timeout_value(&timeout);
420 g_array_append_vals(*out_param1, &timeout, sizeof(int));
423 case BT_START_DISCOVERY:
424 result = _bt_start_discovery();
427 case BT_START_CUSTOM_DISCOVERY: {
428 bt_discovery_role_type_t role;
430 __bt_service_get_parameters(in_param1,
431 &role, sizeof(bt_discovery_role_type_t));
432 result = _bt_start_custom_discovery(role);
436 case BT_CANCEL_DISCOVERY:
437 result = _bt_cancel_discovery();
439 case BT_IS_DISCOVERYING: {
440 gboolean discovering = FALSE;
441 discovering = _bt_is_discovering();
442 g_array_append_vals(*out_param1,
443 &discovering, sizeof(gboolean));
446 case BT_START_LE_DISCOVERY: {
449 sender = (char *)g_dbus_method_invocation_get_sender(context);
450 result = _bt_start_le_scan(sender);
454 case BT_STOP_LE_DISCOVERY: {
457 sender = (char *)g_dbus_method_invocation_get_sender(context);
458 result = _bt_stop_le_scan(sender);
462 case BT_IS_LE_DISCOVERYING: {
463 gboolean le_discovering = FALSE;
465 le_discovering = _bt_is_le_scanning();
466 g_array_append_vals(*out_param1,
467 &le_discovering, sizeof(gboolean));
471 case BT_REGISTER_SCAN_FILTER: {
473 bluetooth_le_scan_filter_t scan_filter;
476 sender = (char *)g_dbus_method_invocation_get_sender(context);
477 __bt_service_get_parameters(in_param1, &scan_filter,
478 sizeof(bluetooth_le_scan_filter_t));
479 BT_DBG("bluetooth_le_scan_filter_t [features : %.2x]",
480 scan_filter.added_features);
482 result = _bt_register_scan_filter(sender,
483 &scan_filter, &slot_id);
485 g_array_append_vals(*out_param1, &slot_id, sizeof(int));
488 case BT_UNREGISTER_SCAN_FILTER:{
492 sender = (char *)g_dbus_method_invocation_get_sender(context);
493 __bt_service_get_parameters(in_param1, &slot_id, sizeof(int));
494 BT_DBG("Remove scan filter [Slot ID : %d]", slot_id);
496 result = _bt_unregister_scan_filter(sender, slot_id);
500 case BT_UNREGISTER_ALL_SCAN_FILTERS:{
503 sender = (char *)g_dbus_method_invocation_get_sender(context);
505 BT_DBG("Remove all scan filters [Sender : %s]", sender);
507 result = _bt_unregister_all_scan_filters(sender);
511 case BT_ENABLE_RSSI: {
512 bluetooth_device_address_t bd_addr;
514 bt_rssi_threshold_t rssi_threshold;
516 int in_range_threshold;
519 BT_DBG("Enable RSSI");
521 __bt_service_get_parameters(in_param1,
522 &bd_addr, sizeof(bluetooth_device_address_t));
523 __bt_service_get_parameters(in_param2,
524 &link_type, sizeof(int));
525 __bt_service_get_parameters(in_param3,
526 &rssi_threshold, sizeof(bt_rssi_threshold_t));
528 low_threshold = rssi_threshold.low_threshold;
529 in_range_threshold = rssi_threshold.in_range_threshold;
530 high_threshold = rssi_threshold.high_threshold;
532 result = _bt_enable_rssi(&bd_addr,
533 link_type, low_threshold,
534 in_range_threshold, high_threshold);
539 bluetooth_device_address_t bd_addr;
541 BT_DBG("Get RSSI Strength");
543 __bt_service_get_parameters(in_param1,
544 &bd_addr, sizeof(bluetooth_device_address_t));
545 __bt_service_get_parameters(in_param2,
546 &link_type, sizeof(int));
548 result = _bt_get_rssi_strength(&bd_addr, link_type);
551 case BT_IS_CONNECTABLE: {
552 gboolean is_connectable;
554 is_connectable = _bt_is_connectable();
555 g_array_append_vals(*out_param1,
556 &is_connectable, sizeof(gboolean));
559 case BT_SET_CONNECTABLE: {
560 gboolean is_connectable;
562 __bt_service_get_parameters(in_param1,
563 &is_connectable, sizeof(gboolean));
564 result = _bt_set_connectable(is_connectable);
567 case BT_SET_ADVERTISING: {
570 gboolean enable = FALSE;
571 gboolean use_reserved_slot = FALSE;
573 __bt_service_get_parameters(in_param1,
574 &adv_handle, sizeof(int));
575 __bt_service_get_parameters(in_param2,
576 &enable, sizeof(gboolean));
577 __bt_service_get_parameters(in_param3,
578 &use_reserved_slot, sizeof(gboolean));
580 sender = (char *)g_dbus_method_invocation_get_sender(context);
582 result = _bt_set_advertising(sender, adv_handle,
583 enable, use_reserved_slot);
586 case BT_SET_CUSTOM_ADVERTISING: {
589 gboolean enable = FALSE;
590 bluetooth_advertising_params_t adv_params;
591 gboolean use_reserved_slot = FALSE;
593 sender = (char *)g_dbus_method_invocation_get_sender(context);
595 __bt_service_get_parameters(in_param1, &adv_handle,
597 __bt_service_get_parameters(in_param2, &enable,
599 __bt_service_get_parameters(in_param3, &adv_params,
600 sizeof(bluetooth_advertising_params_t));
601 __bt_service_get_parameters(in_param4, &use_reserved_slot,
604 BT_DBG("bluetooth_advertising_params_t [%f %f %d %d]",
605 adv_params.interval_min, adv_params.interval_max,
606 adv_params.filter_policy, adv_params.type);
607 result = _bt_set_custom_advertising(sender, adv_handle,
608 enable, &adv_params, use_reserved_slot);
611 case BT_GET_ADVERTISING_DATA: {
612 bluetooth_advertising_data_t adv = { {0} };
615 result = _bt_get_advertising_data(&adv, &length);
616 if (result == BLUETOOTH_ERROR_NONE) {
617 g_array_append_vals(*out_param1, adv.data, length);
621 case BT_SET_ADVERTISING_DATA: {
624 bluetooth_advertising_data_t adv = { {0} };
626 gboolean use_reserved_slot = FALSE;
628 sender = (char *)g_dbus_method_invocation_get_sender(context);
630 __bt_service_get_parameters(in_param1,
631 &adv_handle, sizeof(int));
632 __bt_service_get_parameters(in_param2,
633 &adv, sizeof(bluetooth_advertising_data_t));
634 __bt_service_get_parameters(in_param3,
635 &length, sizeof(int));
636 __bt_service_get_parameters(in_param4,
637 &use_reserved_slot, sizeof(gboolean));
639 result = _bt_set_advertising_data(sender, adv_handle,
640 &adv, length, use_reserved_slot);
643 case BT_GET_SCAN_RESPONSE_DATA: {
644 bluetooth_scan_resp_data_t rsp = { {0} };
647 result = _bt_get_scan_response_data(&rsp, &length);
648 if (result == BLUETOOTH_ERROR_NONE) {
649 g_array_append_vals(*out_param1, rsp.data, length);
654 case BT_SET_SCAN_RESPONSE_DATA: {
657 bluetooth_scan_resp_data_t rsp = { {0} };
659 gboolean use_reserved_slot = FALSE;
661 sender = (char *)g_dbus_method_invocation_get_sender(context);
663 __bt_service_get_parameters(in_param1,
664 &adv_handle, sizeof(int));
665 __bt_service_get_parameters(in_param2,
666 &rsp, sizeof(bluetooth_scan_resp_data_t));
667 __bt_service_get_parameters(in_param3,
668 &length, sizeof(int));
669 __bt_service_get_parameters(in_param4,
670 &use_reserved_slot, sizeof(gboolean));
672 result = _bt_set_scan_response_data(sender, adv_handle,
673 &rsp, length, use_reserved_slot);
677 case BT_SET_MANUFACTURER_DATA: {
678 bluetooth_manufacturer_data_t m_data = { 0 };
679 __bt_service_get_parameters(in_param1,
680 &m_data, sizeof(bluetooth_manufacturer_data_t));
682 result = _bt_set_manufacturer_data(&m_data);
685 case BT_SET_SCAN_PARAMETERS: {
686 bluetooth_le_scan_params_t scan_params;
687 __bt_service_get_parameters(in_param1, &scan_params,
688 sizeof(bluetooth_le_scan_params_t));
690 BT_DBG("bluetooth_le_scan_params_t [%f %f %d]",
691 scan_params.interval, scan_params.window,
694 result = _bt_set_scan_parameters(&scan_params);
697 case BT_LE_CONN_UPDATE: {
698 bluetooth_device_address_t local_address = { {0} };
699 bluetooth_le_connection_param_t parameters = {0};
701 __bt_service_get_parameters(in_param1, &local_address,
702 sizeof(bluetooth_device_address_t));
703 __bt_service_get_parameters(in_param2, ¶meters,
704 sizeof(bluetooth_le_connection_param_t));
706 result = _bt_le_conn_update(local_address.addr,
707 parameters.interval_min,
708 parameters.interval_max,
713 case BT_IS_ADVERTISING: {
714 gboolean advertising = FALSE;
715 advertising = _bt_is_advertising();
717 g_array_append_vals(*out_param1, &advertising,
721 case BT_ADD_WHITE_LIST: {
722 bluetooth_device_address_t address = { {0} };
725 __bt_service_get_parameters(in_param1, &address,
726 sizeof(bluetooth_device_address_t));
727 __bt_service_get_parameters(in_param2, &addr_type,
730 result = _bt_add_white_list(&address, addr_type);
733 case BT_REMOVE_WHITE_LIST: {
734 bluetooth_device_address_t address = { {0} };
737 __bt_service_get_parameters(in_param1,
738 &address, sizeof(bluetooth_device_address_t));
739 __bt_service_get_parameters(in_param2,
740 &addr_type, sizeof(int));
742 result = _bt_remove_white_list(&address, addr_type);
745 case BT_CLEAR_WHITE_LIST: {
746 result = _bt_clear_white_list();
749 case BT_GET_BONDED_DEVICES: {
750 result = _bt_get_bonded_devices(out_param1);
753 case BT_GET_BONDED_DEVICE: {
754 bluetooth_device_address_t address = { {0} };
755 bluetooth_device_info_t dev_info;
757 __bt_service_get_parameters(in_param1,
758 &address, sizeof(bluetooth_device_address_t));
760 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
761 result = _bt_get_bonded_device_info(&address, &dev_info);
763 if (result == BLUETOOTH_ERROR_NONE) {
764 g_array_append_vals(*out_param1, &dev_info,
765 sizeof(bluetooth_device_info_t));
769 case BT_BOND_DEVICE: {
770 bluetooth_device_address_t address = { {0} };
772 __bt_service_get_parameters(in_param1,
773 &address, sizeof(bluetooth_device_address_t));
775 result = _bt_bond_device(request_id, &address,
776 BLUETOOTH_DEV_CONN_DEFAULT, out_param1);
779 case BT_BOND_DEVICE_BY_TYPE: {
780 bluetooth_device_address_t address = { {0} };
781 unsigned short conn_type = 0;
783 __bt_service_get_parameters(in_param1,
784 &address, sizeof(bluetooth_device_address_t));
785 __bt_service_get_parameters(in_param2,
786 &conn_type, sizeof(unsigned short));
788 result = _bt_bond_device(request_id, &address,
789 conn_type, out_param1);
792 case BT_CANCEL_BONDING: {
793 result = _bt_cancel_bonding();
796 case BT_PASSKEY_REPLY: {
797 const char *passkey = NULL;
798 gboolean authentication_reply = FALSE;
800 passkey = g_variant_get_data(in_param1);
801 __bt_service_get_parameters(in_param2,
802 &authentication_reply, sizeof(gboolean));
803 result = _bt_passkey_reply(passkey, authentication_reply);
806 case BT_PASSKEY_CONFIRMATION_REPLY: {
807 gboolean confirmation_reply = FALSE;
809 __bt_service_get_parameters(in_param1,
810 &confirmation_reply, sizeof(gboolean));
811 result = _bt_passkey_confirmation_reply(confirmation_reply);
814 case BT_UNBOND_DEVICE: {
815 bluetooth_device_address_t address = { {0} };
817 __bt_service_get_parameters(in_param1,
818 &address, sizeof(bluetooth_device_address_t));
820 result = _bt_unbond_device(request_id, &address, out_param1);
825 bluetooth_device_address_t address = { {0} };
826 const char *local_name;
828 __bt_service_get_parameters(in_param1,
829 &address, sizeof(bluetooth_device_address_t));
830 local_name = (const char *)g_variant_get_data(in_param2);
832 result = _bt_set_alias(&address, local_name);
835 case BT_SEARCH_SERVICE: {
836 bluetooth_device_address_t address = { {0} };
838 __bt_service_get_parameters(in_param1,
839 &address, sizeof(bluetooth_device_address_t));
841 result = _bt_search_device(request_id, &address);
842 if (result != BLUETOOTH_ERROR_NONE) {
843 g_array_append_vals(*out_param1, &address,
844 sizeof(bluetooth_device_address_t));
848 case BT_CANCEL_SEARCH_SERVICE: {
849 result = _bt_cancel_search_device();
852 case BT_SET_AUTHORIZATION: {
853 bluetooth_device_address_t address = { {0} };
856 __bt_service_get_parameters(in_param1,
857 &address, sizeof(bluetooth_device_address_t));
858 __bt_service_get_parameters(in_param2,
859 &authorize, sizeof(gboolean));
861 result = _bt_set_authorization(&address, authorize);
864 case BT_IS_DEVICE_CONNECTED: {
865 bluetooth_device_address_t address = { {0} };
867 gboolean connected = FALSE;
869 __bt_service_get_parameters(in_param1,
870 &address, sizeof(bluetooth_device_address_t));
871 __bt_service_get_parameters(in_param2,
874 result = _bt_is_device_connected(&address, type, &connected);
875 BT_DBG("is_connected: %d", connected);
876 if (result == BLUETOOTH_ERROR_NONE) {
877 g_array_append_vals(*out_param1, &connected,
883 case BT_GET_CONNECTED_LINK_TYPE: {
884 bluetooth_device_address_t address = { {0} };
885 bluetooth_connected_link_t connected = BLUETOOTH_CONNECTED_LINK_NONE;
887 __bt_service_get_parameters(in_param1,
888 &address, sizeof(bluetooth_device_address_t));
890 result = _bt_get_connected_link(&address, &connected);
892 if (result == BLUETOOTH_ERROR_NONE) {
893 g_array_append_vals(*out_param1, &connected,
899 case BT_SET_PIN_CODE: {
900 bluetooth_device_address_t address = { {0} };
901 bluetooth_device_pin_code_t pin_code = { {0} };
903 __bt_service_get_parameters(in_param1,
904 &address, sizeof(bluetooth_device_address_t));
905 __bt_service_get_parameters(in_param2,
906 &pin_code, sizeof(bluetooth_device_pin_code_t));
908 result = _bt_set_pin_code(&address, &pin_code);
911 case BT_UNSET_PIN_CODE: {
912 bluetooth_device_address_t address = { {0} };
914 __bt_service_get_parameters(in_param1,
915 &address, sizeof(bluetooth_device_address_t));
917 result = _bt_unset_pin_code(&address);
920 case BT_UPDATE_LE_CONNECTION_MODE: {
921 bluetooth_device_address_t remote_address = { { 0 } };
922 bluetooth_le_connection_param_t param = { 0 };
923 bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED;
925 __bt_service_get_parameters(in_param1, &remote_address,
926 sizeof(bluetooth_device_address_t));
927 __bt_service_get_parameters(in_param2, &mode,
928 sizeof(bluetooth_le_connection_mode_t));
930 result = _bt_get_le_connection_parameter(mode, ¶m);
931 if (result != BLUETOOTH_ERROR_NONE)
934 result = _bt_le_conn_update(remote_address.addr,
942 case BT_HID_CONNECT: {
943 bluetooth_device_address_t address = { {0} };
945 __bt_service_get_parameters(in_param1,
946 &address, sizeof(bluetooth_device_address_t));
948 result = _bt_hid_connect(request_id, &address);
949 if (result != BLUETOOTH_ERROR_NONE) {
950 g_array_append_vals(*out_param1, &address,
951 sizeof(bluetooth_device_address_t));
955 case BT_HID_DISCONNECT: {
956 bluetooth_device_address_t address = { {0} };
958 __bt_service_get_parameters(in_param1,
959 &address, sizeof(bluetooth_device_address_t));
961 result = _bt_hid_disconnect(request_id, &address);
962 if (result != BLUETOOTH_ERROR_NONE) {
963 g_array_append_vals(*out_param1, &address,
964 sizeof(bluetooth_device_address_t));
968 case BT_NETWORK_ACTIVATE:
969 result = _bt_network_activate();
971 case BT_NETWORK_DEACTIVATE:
972 result = _bt_network_deactivate();
974 case BT_NETWORK_CONNECT: {
975 bluetooth_device_address_t address = { {0} };
978 __bt_service_get_parameters(in_param1,
979 &address, sizeof(bluetooth_device_address_t));
980 __bt_service_get_parameters(in_param2,
983 result = _bt_network_connect(request_id, role, &address);
984 if (result != BLUETOOTH_ERROR_NONE) {
985 g_array_append_vals(*out_param1, &address,
986 sizeof(bluetooth_device_address_t));
990 case BT_NETWORK_DISCONNECT: {
991 bluetooth_device_address_t address = { {0} };
993 __bt_service_get_parameters(in_param1,
994 &address, sizeof(bluetooth_device_address_t));
996 result = _bt_network_disconnect(request_id, &address);
997 if (result != BLUETOOTH_ERROR_NONE) {
998 g_array_append_vals(*out_param1, &address,
999 sizeof(bluetooth_device_address_t));
1003 case BT_NETWORK_SERVER_DISCONNECT: {
1004 bluetooth_device_address_t address = { {0} };
1006 __bt_service_get_parameters(in_param1,
1007 &address, sizeof(bluetooth_device_address_t));
1009 result = _bt_network_server_disconnect(request_id, &address);
1010 if (result != BLUETOOTH_ERROR_NONE) {
1011 g_array_append_vals(*out_param1, &address,
1012 sizeof(bluetooth_device_address_t));
1017 case BT_AUDIO_CONNECT: {
1018 bluetooth_device_address_t address = { {0} };
1020 __bt_service_get_parameters(in_param1,
1021 &address, sizeof(bluetooth_device_address_t));
1023 result = _bt_audio_connect(request_id, BT_AUDIO_ALL,
1024 &address, out_param1);
1027 case BT_AUDIO_DISCONNECT: {
1028 bluetooth_device_address_t address = { {0} };
1030 __bt_service_get_parameters(in_param1,
1031 &address, sizeof(bluetooth_device_address_t));
1033 result = _bt_audio_disconnect(request_id, BT_AUDIO_ALL,
1034 &address, out_param1);
1037 case BT_AG_CONNECT: {
1038 bluetooth_device_address_t address = { {0} };
1040 __bt_service_get_parameters(in_param1,
1041 &address, sizeof(bluetooth_device_address_t));
1043 result = _bt_audio_connect(request_id, BT_AUDIO_HSP,
1044 &address, out_param1);
1047 case BT_AG_DISCONNECT: {
1048 bluetooth_device_address_t address = { {0} };
1050 __bt_service_get_parameters(in_param1,
1051 &address, sizeof(bluetooth_device_address_t));
1053 result = _bt_audio_disconnect(request_id, BT_AUDIO_HSP,
1054 &address, out_param1);
1057 case BT_AV_CONNECT: {
1058 bluetooth_device_address_t address = { {0} };
1060 __bt_service_get_parameters(in_param1,
1061 &address, sizeof(bluetooth_device_address_t));
1063 result = _bt_audio_connect(request_id, BT_AUDIO_A2DP,
1064 &address, out_param1);
1067 case BT_AV_DISCONNECT: {
1068 bluetooth_device_address_t address = { {0} };
1070 __bt_service_get_parameters(in_param1,
1071 &address, sizeof(bluetooth_device_address_t));
1073 result = _bt_audio_disconnect(request_id, BT_AUDIO_A2DP,
1074 &address, out_param1);
1077 case BT_AVRCP_CONTROL_CONNECT: {
1078 bluetooth_device_address_t address = { {0} };
1080 __bt_service_get_parameters(in_param1,
1081 &address, sizeof(bluetooth_device_address_t));
1083 result = _bt_audio_connect(request_id, BT_AVRCP,
1084 &address, out_param1);
1087 case BT_AVRCP_CONTROL_DISCONNECT: {
1088 bluetooth_device_address_t address = { {0} };
1090 __bt_service_get_parameters(in_param1,
1091 &address, sizeof(bluetooth_device_address_t));
1093 result = _bt_audio_disconnect(request_id, BT_AVRCP,
1094 &address, out_param1);
1097 case BT_AV_SOURCE_CONNECT: {
1098 bluetooth_device_address_t address = { {0} };
1100 __bt_service_get_parameters(in_param1, &address,
1101 sizeof(bluetooth_device_address_t));
1103 result = _bt_audio_connect(request_id, BT_AUDIO_A2DP_SOURCE,
1104 &address, out_param1);
1107 case BT_AV_SOURCE_DISCONNECT: {
1108 bluetooth_device_address_t address = { {0} };
1110 __bt_service_get_parameters(in_param1, &address,
1111 sizeof(bluetooth_device_address_t));
1113 result = _bt_audio_disconnect(request_id, BT_AUDIO_A2DP_SOURCE,
1114 &address, out_param1);
1117 case BT_HF_CONNECT: {
1118 bluetooth_device_address_t address = { {0} };
1120 __bt_service_get_parameters(in_param1,
1121 &address, sizeof(bluetooth_device_address_t));
1123 result = _bt_hf_connect(request_id, &address, out_param1);
1126 case BT_HF_DISCONNECT: {
1127 bluetooth_device_address_t address = { {0} };
1129 __bt_service_get_parameters(in_param1,
1130 &address, sizeof(bluetooth_device_address_t));
1132 result = _bt_hf_disconnect(request_id, &address, out_param1);
1135 case BT_SET_CONTENT_PROTECT: {
1138 __bt_service_get_parameters(in_param1,
1139 &status, sizeof(gboolean));
1141 result = _bt_audio_set_content_protect(status);
1145 case BT_OOB_READ_LOCAL_DATA: {
1146 bt_oob_data_t local_oob_data;
1148 memset(&local_oob_data, 0x00, sizeof(bt_oob_data_t));
1149 result = _bt_oob_read_local_data(&local_oob_data);
1151 g_array_append_vals(*out_param1, &local_oob_data,
1152 sizeof(bt_oob_data_t));
1156 case BT_OOB_ADD_REMOTE_DATA: {
1157 bluetooth_device_address_t address = { {0} };
1158 bt_oob_data_t local_oob_data;
1160 __bt_service_get_parameters(in_param1,
1161 &address, sizeof(bluetooth_device_address_t));
1162 __bt_service_get_parameters(in_param2,
1163 &local_oob_data, sizeof(bt_oob_data_t));
1165 result = _bt_oob_add_remote_data(&address, &local_oob_data);
1169 case BT_OOB_REMOVE_REMOTE_DATA: {
1170 bluetooth_device_address_t address = { {0} };
1172 __bt_service_get_parameters(in_param1,
1173 &address, sizeof(bluetooth_device_address_t));
1175 result = _bt_oob_remove_remote_data(&address);
1179 case BT_AVRCP_SET_TRACK_INFO: {
1180 media_metadata_t data;
1181 media_metadata_attributes_t meta_data;
1183 memset(&data, 0x00, sizeof(media_metadata_t));
1184 memset(&meta_data, 0x00, sizeof(media_metadata_attributes_t));
1186 __bt_service_get_parameters(in_param1,
1187 &data, sizeof(media_metadata_t));
1189 meta_data.title = g_strdup(data.title);
1190 meta_data.artist = g_strdup(data.artist);
1191 meta_data.album = g_strdup(data.album);
1192 meta_data.genre = g_strdup(data.genre);
1193 meta_data.total_tracks = data.total_tracks;
1194 meta_data.number = data.number;
1195 meta_data.duration = (int64_t) data.duration;
1197 result = _bt_avrcp_set_track_info(&meta_data);
1199 g_free((gpointer)meta_data.title);
1200 g_free((gpointer)meta_data.artist);
1201 g_free((gpointer)meta_data.album);
1202 g_free((gpointer)meta_data.genre);
1206 case BT_AVRCP_SET_PROPERTY: {
1210 __bt_service_get_parameters(in_param1,
1211 &type, sizeof(int));
1212 __bt_service_get_parameters(in_param2,
1213 &value, sizeof(unsigned int));
1215 result = _bt_avrcp_set_property(type, value);
1219 case BT_AVRCP_SET_PROPERTIES: {
1220 media_player_settings_t properties;
1222 memset(&properties, 0x00, sizeof(media_player_settings_t));
1223 __bt_service_get_parameters(in_param1,
1224 &properties, sizeof(media_player_settings_t));
1226 result = _bt_avrcp_set_properties(&properties);
1230 case BT_AVRCP_HANDLE_CONTROL: {
1233 __bt_service_get_parameters(in_param1, &type, sizeof(int));
1235 result = _bt_avrcp_control_cmd(type);
1239 case BT_AVRCP_CONTROL_SET_PROPERTY: {
1243 __bt_service_get_parameters(in_param1,
1244 &type, sizeof(int));
1245 __bt_service_get_parameters(in_param2,
1246 &value, sizeof(unsigned int));
1248 result = _bt_avrcp_control_set_property(type, value);
1252 case BT_AVRCP_CONTROL_GET_PROPERTY: {
1256 __bt_service_get_parameters(in_param1, &type, sizeof(int));
1258 result = _bt_avrcp_control_get_property(type, &value);
1259 g_array_append_vals(*out_param1, &value, sizeof(int));
1263 case BT_AVRCP_GET_TRACK_INFO: {
1264 media_metadata_t meta_data;
1265 media_metadata_attributes_t metadata;
1267 memset(&meta_data, 0x00, sizeof(media_metadata_t));
1268 memset(&metadata, 0x00, sizeof(media_metadata_attributes_t));
1270 result = _bt_avrcp_control_get_track_info(&metadata);
1272 if (BLUETOOTH_ERROR_NONE != result)
1275 if (_bt_copy_utf8_string(meta_data.title, metadata.title,
1276 BT_META_DATA_MAX_LEN))
1277 BT_ERR("Error in copying Title\n");
1278 if (_bt_copy_utf8_string(meta_data.artist, metadata.artist,
1279 BT_META_DATA_MAX_LEN))
1280 BT_ERR("Error in copying Artist\n");
1281 if (_bt_copy_utf8_string(meta_data.album, metadata.album,
1282 BT_META_DATA_MAX_LEN))
1283 BT_ERR("Error in copying Album\n");
1284 if (_bt_copy_utf8_string(meta_data.genre, metadata.genre,
1285 BT_META_DATA_MAX_LEN))
1286 BT_ERR("Error in copying Genre\n");
1288 if (_bt_utf8_validate(meta_data.title) == FALSE)
1289 meta_data.title[0] = '\0';
1291 if (_bt_utf8_validate(meta_data.artist) == FALSE)
1292 meta_data.artist[0] = '\0';
1294 if (_bt_utf8_validate(meta_data.album) == FALSE)
1295 meta_data.album[0] = '\0';
1297 if (_bt_utf8_validate(meta_data.genre) == FALSE)
1298 meta_data.genre[0] = '\0';
1300 meta_data.total_tracks = metadata.total_tracks;
1301 meta_data.number = metadata.number;
1302 meta_data.duration = metadata.duration;
1304 g_free((gpointer)metadata.title);
1305 g_free((gpointer)metadata.artist);
1306 g_free((gpointer)metadata.album);
1307 g_free((gpointer)metadata.genre);
1309 g_array_append_vals(*out_param1, &meta_data,
1310 sizeof(media_metadata_t));
1313 case BT_RFCOMM_CLIENT_CONNECT: {
1314 #ifdef RFCOMM_DIRECT
1315 result = BLUETOOTH_ERROR_NONE;
1317 bluetooth_device_address_t address = { {0} };
1321 __bt_service_get_parameters(in_param1,
1322 &address, sizeof(bluetooth_device_address_t));
1324 input_string = &g_array_index(in_param2, char, 0);
1326 connect_type = g_array_index(in_param3, int, 0);
1328 if (connect_type == BT_RFCOMM_UUID) {
1329 result = _bt_rfcomm_connect_using_uuid(request_id,
1330 &address, input_string);
1332 result = _bt_rfcomm_connect_using_channel(request_id,
1333 &address, input_string);
1336 if (result != BLUETOOTH_ERROR_NONE) {
1337 g_array_append_vals(*out_param1, &address,
1338 sizeof(bluetooth_device_address_t));
1343 case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
1344 result = _bt_rfcomm_cancel_connect();
1346 case BT_RFCOMM_CLIENT_IS_CONNECTED: {
1347 gboolean connected = FALSE;
1348 result = _bt_rfcomm_is_connected(&connected);
1350 g_array_append_vals(*out_param1, &connected, sizeof(gboolean));
1353 case BT_RFCOMM_SOCKET_DISCONNECT: {
1354 #ifdef RFCOMM_DIRECT
1355 result = BLUETOOTH_ERROR_NONE;
1359 socket_fd = g_array_index(in_param1, int, 0);
1361 result = _bt_rfcomm_disconnect(socket_fd);
1365 case BT_RFCOMM_SOCKET_WRITE: {
1366 #ifdef RFCOMM_DIRECT
1367 result = BLUETOOTH_ERROR_NONE;
1373 socket_fd = g_array_index(in_param1, int, 0);
1374 length = g_array_index(in_param2, int, 0);
1375 buffer = &g_array_index(in_param3, char, 0);
1377 result = _bt_rfcomm_write(socket_fd, buffer, length);
1381 case BT_RFCOMM_CREATE_SOCKET: {
1382 #ifdef RFCOMM_DIRECT
1383 result = BLUETOOTH_ERROR_NONE;
1389 sender = (char *)g_dbus_method_invocation_get_sender(context);
1390 uuid = &g_array_index(in_param1, char, 0);
1392 result = _bt_rfcomm_create_socket(sender, uuid);
1396 result = BLUETOOTH_ERROR_NONE;
1399 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1405 case BT_RFCOMM_REMOVE_SOCKET: {
1406 #ifdef RFCOMM_DIRECT
1407 result = BLUETOOTH_ERROR_NONE;
1411 socket_fd = g_array_index(in_param1, int, 0);
1413 result = _bt_rfcomm_remove_socket(socket_fd);
1417 case BT_RFCOMM_LISTEN: {
1422 __bt_service_get_parameters(in_param1, &socket_fd,
1424 __bt_service_get_parameters(in_param2, &pending,
1426 __bt_service_get_parameters(in_param3, &is_native,
1429 result = _bt_rfcomm_listen(socket_fd, pending, is_native);
1432 case BT_RFCOMM_IS_UUID_AVAILABLE: {
1433 gboolean available = TRUE;
1436 uuid = (char *)g_variant_get_data(in_param1);
1438 result = _bt_rfcomm_is_uuid_available(uuid, &available);
1440 g_array_append_vals(*out_param1, &available, sizeof(gboolean));
1443 case BT_RFCOMM_ACCEPT_CONNECTION: {
1446 __bt_service_get_parameters(in_param1, &socket_fd, sizeof(int));
1447 BT_DBG(" socket fd %d", socket_fd);
1448 result = _bt_rfcomm_accept_connection();
1451 case BT_RFCOMM_REJECT_CONNECTION: {
1454 __bt_service_get_parameters(in_param1, &socket_fd, sizeof(int));
1455 BT_DBG(" socket fd %d", socket_fd);
1456 result = _bt_rfcomm_reject_connection();
1459 case BT_RFCOMM_CREATE_SOCKET_EX: {
1460 result = BLUETOOTH_ERROR_NONE;
1463 case BT_RFCOMM_REMOVE_SOCKET_EX: {
1464 result = BLUETOOTH_ERROR_NONE;
1467 case BT_CONNECT_LE: {
1468 bluetooth_device_address_t address = { {0} };
1469 gboolean auto_connect;
1471 __bt_service_get_parameters(in_param1,
1472 &address, sizeof(bluetooth_device_address_t));
1473 __bt_service_get_parameters(in_param2,
1474 &auto_connect, sizeof(gboolean));
1476 result = _bt_connect_le_device(request_id, &address, auto_connect);
1477 if (result != BLUETOOTH_ERROR_NONE) {
1478 g_array_append_vals(*out_param1, &address,
1479 sizeof(bluetooth_device_address_t));
1483 case BT_DISCONNECT_LE: {
1484 bluetooth_device_address_t address = { {0} };
1486 __bt_service_get_parameters(in_param1, &address,
1487 sizeof(bluetooth_device_address_t));
1489 result = _bt_disconnect_le_device(request_id, &address);
1490 if (result != BLUETOOTH_ERROR_NONE) {
1491 g_array_append_vals(*out_param1, &address,
1492 sizeof(bluetooth_device_address_t));
1496 case BT_SET_LE_PRIVACY: {
1497 gboolean set_privacy;
1499 __bt_service_get_parameters(in_param1, &set_privacy,
1502 result = _bt_set_le_privacy(set_privacy);
1506 case BT_HDP_CONNECT:
1507 case BT_HDP_DISCONNECT:
1508 case BT_HDP_SEND_DATA:
1510 case BT_GATT_GET_PRIMARY_SERVICES:
1511 case BT_GATT_DISCOVER_CHARACTERISTICS:
1512 case BT_GATT_SET_PROPERTY_REQUEST:
1513 case BT_GATT_READ_CHARACTERISTIC:
1514 case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
1515 /* Just call to check the privilege */
1517 #ifndef GATT_NO_RELAY
1518 case BT_GATT_WATCH_CHARACTERISTIC: {
1519 char *sender = NULL;
1521 sender = (char *)g_dbus_method_invocation_get_sender(context);
1523 result = _bt_insert_gatt_client_sender(sender);
1527 case BT_GATT_UNWATCH_CHARACTERISTIC: {
1528 char *sender = NULL;
1530 sender = (char *)g_dbus_method_invocation_get_sender(context);
1532 result = _bt_delete_gatt_client_sender(sender);
1537 case BT_LE_IPSP_INIT:
1538 result = _bt_initialize_ipsp();
1540 case BT_LE_IPSP_DEINIT:
1541 result = _bt_deinitialize_ipsp();
1543 case BT_LE_IPSP_CONNECT: {
1544 bluetooth_device_address_t address = { {0} };
1545 __bt_service_get_parameters(in_param1, &address,
1546 sizeof(bluetooth_device_address_t));
1548 result = _bt_connect_le_ipsp_device(&address);
1551 case BT_LE_IPSP_DISCONNECT: {
1552 bluetooth_device_address_t address = { {0} };
1554 __bt_service_get_parameters(in_param1, &address,
1555 sizeof(bluetooth_device_address_t));
1557 result = _bt_disconnect_le_ipsp_device(&address);
1560 case BT_LE_READ_MAXIMUM_DATA_LENGTH: {
1561 bluetooth_le_read_maximum_data_length_t max_le_datalength = {0};
1563 result = _bt_le_read_maximum_data_length(&max_le_datalength);
1565 g_array_append_vals(*out_param1, &max_le_datalength,
1566 sizeof(bluetooth_le_read_maximum_data_length_t));
1569 case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH: {
1570 unsigned int def_tx_Octects = 0;
1571 unsigned int def_tx_Time = 0;
1573 __bt_service_get_parameters(in_param1,
1574 &def_tx_Octects, sizeof(int));
1575 __bt_service_get_parameters(in_param2,
1576 &def_tx_Time, sizeof(int));
1578 result = _bt_le_write_host_suggested_default_data_length(
1579 def_tx_Octects, def_tx_Time);
1582 case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH: {
1583 bluetooth_le_read_host_suggested_data_length_t def_data_length = {0};
1585 result = _bt_le_read_host_suggested_default_data_length(&def_data_length);
1587 g_array_append_vals(*out_param1, &def_data_length,
1588 sizeof(bluetooth_le_read_host_suggested_data_length_t));
1592 case BT_LE_SET_DATA_LENGTH: {
1593 int max_tx_Octets = 0;
1594 int max_tx_Time = 0;
1595 bluetooth_device_address_t address = { {0} };
1597 __bt_service_get_parameters(in_param1, &address,
1598 sizeof(bluetooth_device_address_t));
1599 __bt_service_get_parameters(in_param2,
1600 &max_tx_Octets, sizeof(int));
1601 __bt_service_get_parameters(in_param3,
1602 &max_tx_Time, sizeof(int));
1604 result = _bt_le_set_data_length(&address, max_tx_Octets, max_tx_Time);
1607 case BT_DPM_SET_ALLOW_BT_MODE: {
1608 dpm_bt_allow_t value = DPM_BT_ERROR;
1610 __bt_service_get_parameters(in_param1, &value,
1613 result = _bt_dpm_set_allow_bluetooth_mode(value);
1616 case BT_DPM_GET_ALLOW_BT_MODE: {
1617 dpm_bt_allow_t value = DPM_BT_ERROR;
1619 value = _bt_dpm_get_allow_bluetooth_mode();
1620 result = DPM_RESULT_SUCCESS;
1621 g_array_append_vals(*out_param1, &value, sizeof(int));
1625 case BT_DPM_SET_DEVICE_RESTRITION: {
1626 dpm_status_t value = DPM_BT_ERROR;
1628 __bt_service_get_parameters(in_param1, &value,
1631 result = _bt_dpm_activate_bluetooth_device_restriction(value);
1634 case BT_DPM_GET_DEVICE_RESTRITION: {
1635 dpm_status_t value = DPM_BT_ERROR;
1637 value = _bt_dpm_is_bluetooth_device_restriction_active();
1638 result = DPM_RESULT_SUCCESS;
1639 g_array_append_vals(*out_param1, &value, sizeof(int));
1643 case BT_DPM_SET_UUID_RESTRITION: {
1644 dpm_status_t value = DPM_BT_ERROR;
1646 __bt_service_get_parameters(in_param1, &value,
1649 result = _bt_dpm_activate_bluetoooth_uuid_restriction(value);
1652 case BT_DPM_GET_UUID_RESTRITION: {
1653 dpm_status_t value = DPM_BT_ERROR;
1655 value = _bt_dpm_is_bluetooth_uuid_restriction_active();
1656 result = DPM_RESULT_SUCCESS;
1657 g_array_append_vals(*out_param1, &value, sizeof(int));
1661 case BT_DPM_ADD_DEVICES_BLACKLIST: {
1662 bluetooth_device_address_t address = { {0} };
1664 __bt_service_get_parameters(in_param1, &address,
1665 sizeof(bluetooth_device_address_t));
1667 result = _bt_dpm_add_bluetooth_devices_to_blacklist(&address);
1670 case BT_DPM_ADD_DEVICES_WHITELIST: {
1671 bluetooth_device_address_t address = { {0} };
1673 __bt_service_get_parameters(in_param1, &address,
1674 sizeof(bluetooth_device_address_t));
1676 result = _bt_dpm_add_bluetooth_devices_to_whitelist(&address);
1679 case BT_DPM_ADD_UUIDS_BLACKLIST: {
1680 const char *uuid = NULL;
1682 uuid = g_variant_get_data(in_param1);
1684 result = _bt_dpm_add_bluetooth_uuids_to_blacklist(uuid);
1687 case BT_DPM_ADD_UUIDS_WHITELIST: {
1688 const char *uuid = NULL;
1690 uuid = g_variant_get_data(in_param1);
1692 result = _bt_dpm_add_bluetooth_uuids_to_whitelist(uuid);
1695 case BT_DPM_CLEAR_DEVICES_BLACKLIST: {
1696 result = _bt_dpm_clear_bluetooth_devices_from_blacklist();
1699 case BT_DPM_CLEAR_DEVICES_WHITELIST: {
1700 result = _bt_dpm_clear_bluetooth_devices_from_whitelist();
1703 case BT_DPM_CLEAR_UUIDS_BLACKLIST: {
1704 result = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
1707 case BT_DPM_CLEAR_UUIDS_WHITELIST: {
1708 result = _bt_dpm_clear_bluetooth_uuids_from_whitelist();
1711 case BT_DPM_REMOVE_DEVICE_BLACKLIST: {
1712 bluetooth_device_address_t address = { {0} };
1714 __bt_service_get_parameters(in_param1, &address,
1715 sizeof(bluetooth_device_address_t));
1717 result = _bt_dpm_remove_bluetooth_devices_from_blacklist(&address);
1720 case BT_DPM_REMOVE_DEVICE_WHITELIST: {
1721 bluetooth_device_address_t address = { {0} };
1723 __bt_service_get_parameters(in_param1, &address,
1724 sizeof(bluetooth_device_address_t));
1726 result = _bt_dpm_remove_bluetooth_devices_from_whitelist(&address);
1729 case BT_DPM_REMOVE_UUID_BLACKLIST: {
1730 const char *uuid = NULL;
1732 uuid = g_variant_get_data(in_param1);
1734 result = _bt_dpm_remove_bluetooth_uuids_from_blacklist(uuid);
1737 case BT_DPM_REMOVE_UUID_WHITELIST: {
1738 const char *uuid = NULL;
1740 uuid = g_variant_get_data(in_param1);
1742 result = _bt_dpm_remove_bluetooth_uuids_from_whitelist(uuid);
1746 case BT_DPM_GET_DEVICES_BLACKLIST: {
1747 result = _bt_dpm_get_bluetooth_devices_from_blacklist(out_param1);
1750 case BT_DPM_GET_DEVICES_WHITELIST: {
1751 result = _bt_dpm_get_bluetooth_devices_from_whitelist(out_param1);
1754 case BT_DPM_GET_UUIDS_BLACKLIST: {
1755 result = _bt_dpm_get_bluetooth_uuids_from_blacklist(out_param1);
1758 case BT_DPM_GET_UUIDS_WHITELIST: {
1759 result = _bt_dpm_get_bluetooth_uuids_from_whitelist(out_param1);
1762 case BT_DPM_SET_ALLOW_OUTGOING_CALL: {
1763 dpm_status_t value = DPM_BT_ERROR;
1765 __bt_service_get_parameters(in_param1, &value,
1768 result = _bt_dpm_set_allow_bluetooth_outgoing_call(value);
1772 case BT_DPM_GET_ALLOW_OUTGOING_CALL: {
1773 dpm_status_t value = DPM_BT_ERROR;
1775 value = _bt_dpm_get_allow_bluetooth_outgoing_call();
1776 result = DPM_RESULT_SUCCESS;
1777 g_array_append_vals(*out_param1, &value, sizeof(int));
1781 case BT_DPM_SET_PAIRING_STATE: {
1782 dpm_status_t value = DPM_BT_ERROR;
1784 __bt_service_get_parameters(in_param1, &value,
1787 result = _bt_dpm_set_bluetooth_pairing_state(value);
1791 case BT_DPM_GET_PAIRING_STATE: {
1792 dpm_status_t value = DPM_BT_ERROR;
1794 value = _bt_dpm_get_bluetooth_pairing_state();
1795 result = DPM_RESULT_SUCCESS;
1796 g_array_append_vals(*out_param1, &value, sizeof(int));
1800 case BT_DPM_SET_PROFILE_STATE: {
1801 dpm_status_t value = DPM_BT_ERROR;
1802 dpm_profile_t profile = DPM_PROFILE_NONE;
1804 __bt_service_get_parameters(in_param1, &profile,
1806 __bt_service_get_parameters(in_param2, &value,
1809 result = _bt_dpm_set_bluetooth_profile_state(profile, value);
1813 case BT_DPM_GET_PROFILE_STATE: {
1814 dpm_status_t value = DPM_BT_ERROR;
1815 dpm_profile_t profile = DPM_PROFILE_NONE;
1817 __bt_service_get_parameters(in_param2, &profile,
1820 value = _bt_dpm_get_bluetooth_profile_state(profile);
1821 result = DPM_RESULT_SUCCESS;
1822 g_array_append_vals(*out_param1, &value, sizeof(int));
1826 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE: {
1827 dpm_status_t value = DPM_BT_ERROR;
1829 __bt_service_get_parameters(in_param1, &value,
1832 result = _bt_dpm_set_bluetooth_desktop_connectivity_state(value);
1836 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE: {
1837 dpm_status_t value = DPM_BT_ERROR;
1839 value = _bt_dpm_get_bluetooth_desktop_connectivity_state();
1840 result = DPM_RESULT_SUCCESS;
1841 g_array_append_vals(*out_param1, &value, sizeof(int));
1845 case BT_DPM_SET_DISCOVERABLE_STATE: {
1846 dpm_status_t value = DPM_BT_ERROR;
1848 __bt_service_get_parameters(in_param1, &value,
1851 result = _bt_dpm_set_bluetooth_discoverable_state(value);
1855 case BT_DPM_GET_DISCOVERABLE_STATE: {
1856 dpm_status_t value = DPM_BT_ERROR;
1858 value = _bt_dpm_get_bluetooth_discoverable_state();
1859 result = DPM_RESULT_SUCCESS;
1860 g_array_append_vals(*out_param1, &value, sizeof(int));
1864 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE: {
1865 dpm_status_t value = DPM_BT_ERROR;
1867 __bt_service_get_parameters(in_param1, &value,
1870 result = _bt_dpm_set_bluetooth_limited_discoverable_state(value);
1874 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE: {
1875 dpm_status_t value = DPM_BT_ERROR;
1877 value = _bt_dpm_get_bluetooth_limited_discoverable_state();
1878 result = DPM_RESULT_SUCCESS;
1879 g_array_append_vals(*out_param1, &value, sizeof(int));
1883 case BT_DPM_SET_DATA_TRANSFER_STATE: {
1884 dpm_status_t value = DPM_BT_ERROR;
1886 __bt_service_get_parameters(in_param1, &value,
1889 result = _bt_dpm_set_bluetooth_data_transfer_state(value);
1893 case BT_DPM_GET_DATA_TRANSFER_STATE: {
1894 dpm_status_t value = DPM_BT_ERROR;
1896 value = _bt_dpm_get_allow_bluetooth_data_transfer_state();
1897 result = DPM_RESULT_SUCCESS;
1898 g_array_append_vals(*out_param1, &value, sizeof(int));
1903 result = BLUETOOTH_ERROR_INTERNAL;
1910 int __bt_obexd_request(int function_name,
1913 GDBusMethodInvocation *context,
1914 GVariant *in_param1,
1915 GVariant *in_param2,
1916 GVariant *in_param3,
1917 GVariant *in_param4,
1918 GVariant *in_param5,
1919 GArray **out_param1)
1925 BT_DBG("function_name : %x", function_name);
1927 switch (function_name) {
1928 case BT_OPP_PUSH_FILES: {
1929 BT_DBG("BT_OPP_PUSH_FILES");
1931 bluetooth_device_address_t address = { {0} };
1932 bt_file_path_t path;
1935 GDBusProxy *process_proxy;
1936 guint owner_pid = 0;
1937 int opp_server_pid = 0;
1938 const gchar *owner_sender_name = NULL;
1939 GDBusConnection *owner_connection = NULL;
1940 GVariant *val_get = NULL;
1941 GError *error_connection = NULL;
1942 GError *errro_proxy = NULL;
1945 __bt_service_get_parameters(in_param1, &address,
1946 sizeof(bluetooth_device_address_t));
1947 __bt_service_get_parameters(in_param3, &file_count,
1950 file_path = g_new0(char *, file_count + 1);
1952 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
1953 __bt_fill_garray_from_variant(in_param2, param2);
1955 for (i = 0; i < file_count; i++) {
1956 path = g_array_index(param2, bt_file_path_t, i);
1957 file_path[i] = g_strdup(path.path);
1960 owner_connection = g_dbus_method_invocation_get_connection(context);
1961 owner_sender_name = g_dbus_method_invocation_get_sender(context);
1963 BT_DBG("sender = %s", owner_sender_name);
1965 process_proxy = g_dbus_proxy_new_sync(owner_connection,
1966 G_DBUS_PROXY_FLAGS_NONE,
1968 "org.freedesktop.DBus",
1969 "/org/freedesktop/DBus",
1970 "org.freedesktop.DBus",
1971 NULL, &error_connection);
1973 if(process_proxy == NULL)
1974 BT_DBG("Fail to get process_proxy");
1976 if (error_connection) {
1977 BT_DBG("Fail to get proxy : %s", error_connection->message);
1978 g_error_free(error_connection);
1979 error_connection = NULL;
1982 if (process_proxy) {
1983 val_get = g_dbus_proxy_call_sync(process_proxy,
1984 "GetConnectionUnixProcessID",
1985 g_variant_new("(s)", owner_sender_name),
1986 G_DBUS_CALL_FLAGS_NONE,
1990 if (val_get == NULL) {
1991 BT_DBG("Fail to get pid");
1993 g_variant_get(val_get, "(u)", &owner_pid);
1994 BT_DBG("request is from pid %d\n", owner_pid);
1998 g_error("Unable to get PID for %s: %s",
1999 owner_sender_name, errro_proxy->message);
2000 g_error_free(errro_proxy);
2004 BT_DBG("fail to get proxy");
2007 opp_server_pid = _bt_obex_get_native_pid();
2009 BT_DBG("owner_pid, agent_info.native_server->app_pid = %d, %d",
2010 owner_pid, opp_server_pid);
2011 if (opp_server_pid == owner_pid) {
2012 BT_DBG("The exception case : _bt_opp_client_push_files");
2013 result = _bt_opp_client_push_files(request_id, context,
2014 &address, file_path,
2017 BT_DBG("normal case");
2018 result = _bt_opp_client_push_files(request_id, context,
2019 &address, file_path,
2023 for (i = 0; i < file_count; i++) {
2024 g_free(file_path[i]);
2027 g_array_free(param2, TRUE);
2029 g_object_unref(process_proxy);
2032 case BT_OPP_CANCEL_PUSH: {
2033 result = _bt_opp_client_cancel_push();
2037 case BT_OPP_IS_PUSHING_FILES: {
2038 gboolean is_sending = FALSE;
2040 result = _bt_opp_client_is_sending(&is_sending);
2042 g_array_append_vals(*out_param1, &is_sending,
2046 case BT_OBEX_SERVER_ALLOCATE: {
2052 sender = (char *)g_dbus_method_invocation_get_sender(context);
2054 path = (char *)g_variant_get_data(in_param1);
2055 __bt_service_get_parameters(in_param2, &is_native,
2057 __bt_service_get_parameters(in_param3, &app_pid,
2059 result = _bt_obex_server_allocate(sender,
2060 path, app_pid, is_native);
2064 case BT_OBEX_SERVER_DEALLOCATE: {
2068 __bt_service_get_parameters(in_param1, &is_native,
2070 __bt_service_get_parameters(in_param2, &app_pid,
2073 result = _bt_obex_server_deallocate(app_pid, is_native);
2076 case BT_OBEX_SERVER_IS_ACTIVATED: {
2077 gboolean is_activated = FALSE;
2079 result = _bt_obex_server_is_activated(&is_activated);
2081 g_array_append_vals(*out_param1, &is_activated,
2086 case BT_OBEX_SERVER_ACCEPT_CONNECTION: {
2087 result = _bt_obex_server_accept_connection(request_id);
2091 case BT_OBEX_SERVER_REJECT_CONNECTION: {
2092 result = _bt_obex_server_reject_connection();
2096 case BT_OBEX_SERVER_ACCEPT_FILE: {
2099 file_name = (char *)g_variant_get_data(in_param1);
2100 result = _bt_obex_server_accept_authorize(file_name, TRUE);
2104 case BT_OBEX_SERVER_REJECT_FILE: {
2105 result = _bt_obex_server_reject_authorize();
2109 case BT_OBEX_SERVER_SET_PATH: {
2111 char *destination_path;
2113 destination_path = (char *)g_variant_get_data(in_param1);
2114 __bt_service_get_parameters(in_param2, &is_native,
2117 result = _bt_obex_server_set_destination_path(
2118 destination_path, is_native);
2122 case BT_OBEX_SERVER_SET_ROOT: {
2125 root = (char *)g_variant_get_data(in_param1);
2127 result = _bt_obex_server_set_root(root);
2131 case BT_OBEX_SERVER_CANCEL_TRANSFER: {
2134 __bt_service_get_parameters(in_param1, &transfer_id,
2137 result = _bt_obex_server_cancel_transfer(transfer_id);
2141 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS: {
2142 result = _bt_obex_server_cancel_all_transfers();
2146 case BT_OBEX_SERVER_IS_RECEIVING: {
2147 gboolean is_receiving = FALSE;
2149 result = _bt_obex_server_is_receiving(&is_receiving);
2151 g_array_append_vals(*out_param1, &is_receiving,
2155 case BT_PBAP_CONNECT: {
2156 bluetooth_device_address_t address = { {0} };
2158 __bt_service_get_parameters(in_param1, &address,
2159 sizeof(bluetooth_device_address_t));
2161 result = _bt_pbap_connect(&address);
2164 case BT_PBAP_DISCONNECT: {
2165 bluetooth_device_address_t address = { {0} };
2167 __bt_service_get_parameters(in_param1, &address,
2168 sizeof(bluetooth_device_address_t));
2170 result = _bt_pbap_disconnect(&address);
2173 case BT_PBAP_GET_PHONEBOOK_SIZE: {
2174 bluetooth_device_address_t address = { {0} };
2175 bt_pbap_folder_t folder = { 0, };
2177 __bt_service_get_parameters(in_param1, &address,
2178 sizeof(bluetooth_device_address_t));
2179 __bt_service_get_parameters(in_param2, &folder,
2180 sizeof(bt_pbap_folder_t));
2182 result = _bt_pbap_get_phonebook_size(&address,
2183 folder.addressbook, folder.folder_type);
2186 case BT_PBAP_GET_PHONEBOOK: {
2187 bluetooth_device_address_t address = { {0} };
2188 bt_pbap_folder_t folder = { 0, };
2189 bt_pbap_pull_parameters_t app_param = { 0, };
2191 __bt_service_get_parameters(in_param1, &address,
2192 sizeof(bluetooth_device_address_t));
2193 __bt_service_get_parameters(in_param2, &folder,
2194 sizeof(bt_pbap_folder_t));
2195 __bt_service_get_parameters(in_param3, &app_param,
2196 sizeof(bt_pbap_pull_parameters_t));
2198 result = _bt_pbap_get_phonebook(&address, folder.addressbook,
2199 folder.folder_type, &app_param);
2202 case BT_PBAP_GET_LIST: {
2203 bluetooth_device_address_t address = { {0} };
2204 bt_pbap_folder_t folder = { 0, };
2205 bt_pbap_list_parameters_t app_param = { 0, };
2207 __bt_service_get_parameters(in_param1, &address,
2208 sizeof(bluetooth_device_address_t));
2209 __bt_service_get_parameters(in_param2, &folder,
2210 sizeof(bt_pbap_folder_t));
2211 __bt_service_get_parameters(in_param3, &app_param,
2212 sizeof(bt_pbap_list_parameters_t));
2214 result = _bt_pbap_get_list(&address, folder.addressbook,
2215 folder.folder_type, &app_param);
2218 case BT_PBAP_PULL_VCARD: {
2219 bluetooth_device_address_t address = { {0} };
2220 bt_pbap_folder_t folder = { 0, };
2221 bt_pbap_pull_vcard_parameters_t app_param = { 0, };
2223 __bt_service_get_parameters(in_param1, &address,
2224 sizeof(bluetooth_device_address_t));
2225 __bt_service_get_parameters(in_param2, &folder,
2226 sizeof(bt_pbap_folder_t));
2227 __bt_service_get_parameters(in_param3, &app_param,
2228 sizeof(bt_pbap_pull_vcard_parameters_t));
2230 result = _bt_pbap_pull_vcard(&address, folder.addressbook,
2231 folder.folder_type, &app_param);
2234 case BT_PBAP_PHONEBOOK_SEARCH: {
2235 bluetooth_device_address_t address = { {0} };
2236 bt_pbap_folder_t folder = { 0, };
2237 bt_pbap_search_parameters_t app_param = { 0, };
2239 __bt_service_get_parameters(in_param1, &address,
2240 sizeof(bluetooth_device_address_t));
2241 __bt_service_get_parameters(in_param2, &folder,
2242 sizeof(bt_pbap_folder_t));
2243 __bt_service_get_parameters(in_param3, &app_param,
2244 sizeof(bt_pbap_search_parameters_t));
2246 result = _bt_pbap_phonebook_search(&address, folder.addressbook,
2247 folder.folder_type, &app_param);
2252 BT_ERR("Unknown function!");
2253 result = BLUETOOTH_ERROR_INTERNAL;
2262 int __bt_agent_request(int function_name,
2265 GDBusMethodInvocation *context,
2266 GVariant *in_param1,
2267 GVariant *in_param2,
2268 GVariant *in_param3,
2269 GVariant *in_param4,
2270 GArray **out_param1)
2273 switch (function_name) {
2274 case BT_SET_AUTHORIZATION: {
2280 __bt_service_get_parameters(in_param1, &type, sizeof(int));
2281 uuid = (char *)g_variant_get_data(in_param2);
2282 path = (char *)g_variant_get_data(in_param3);
2283 __bt_service_get_parameters(in_param4, &fd, sizeof(int));
2285 result = _bt_register_osp_server_in_agent(type, uuid, path, fd);
2288 case BT_UNSET_AUTHORIZATION: {
2292 __bt_service_get_parameters(in_param1, &type, sizeof(int));
2293 uuid = (char *)g_variant_get_data(in_param2);
2295 result = _bt_unregister_osp_server_in_agent(type, uuid);
2299 BT_ERR("Unknown function!");
2300 result = BLUETOOTH_ERROR_INTERNAL;
2307 int __bt_core_request(int function_name,
2310 GDBusMethodInvocation *context,
2311 GVariant *in_param1)
2315 switch (function_name) {
2316 case BT_ENABLE_ADAPTER:
2320 status = _bt_adapter_get_status();
2322 if (status == BT_ACTIVATING) {
2323 BT_DBG("Enabling in progress");
2324 result = BLUETOOTH_ERROR_IN_PROGRESS;
2325 } else if (status == BT_ACTIVATED) {
2326 BT_DBG("Already enabled");
2327 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
2329 _bt_adapter_set_status(BT_ACTIVATING);
2330 _bt_adapter_start_enable_timer();
2331 result = BLUETOOTH_ERROR_NONE;
2336 case BT_DISABLE_ADAPTER:
2340 status = _bt_adapter_get_status();
2341 if (status == BT_DEACTIVATING) {
2342 BT_DBG("Disabling in progress");
2343 result = BLUETOOTH_ERROR_IN_PROGRESS;
2344 } else if (status == BT_DEACTIVATED) {
2345 BT_DBG("Already disabled");
2346 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
2348 _bt_adapter_set_status(BT_DEACTIVATING);
2349 result = BLUETOOTH_ERROR_NONE;
2354 case BT_ENABLE_ADAPTER_LE:
2356 bt_le_status_t le_status;
2358 le_status = _bt_adapter_get_le_status();
2359 if (le_status == BT_LE_ACTIVATING) {
2360 BT_DBG("Enabling in progress");
2361 result = BLUETOOTH_ERROR_IN_PROGRESS;
2362 } else if (le_status == BT_LE_ACTIVATED) {
2363 BT_DBG("Already enabled");
2364 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
2366 _bt_adapter_set_le_status(BT_LE_ACTIVATING);
2367 _bt_adapter_start_le_enable_timer();
2368 result = BLUETOOTH_ERROR_NONE;
2373 case BT_DISABLE_ADAPTER_LE:
2375 bt_le_status_t le_status;
2377 le_status = _bt_adapter_get_le_status();
2378 if (le_status == BT_LE_DEACTIVATING) {
2379 BT_DBG("Disabling in progress");
2380 result = BLUETOOTH_ERROR_IN_PROGRESS;
2381 } else if (le_status == BT_LE_DEACTIVATED) {
2382 BT_DBG("Already disabled");
2383 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
2385 _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
2386 result = BLUETOOTH_ERROR_NONE;
2392 BT_ERR("Unknown function!");
2393 result = BLUETOOTH_ERROR_INTERNAL;
2400 gboolean __bt_service_check_privilege(int function_name,
2402 const char *unique_name)
2405 gboolean result = TRUE;
2406 char *client_creds = NULL;
2407 char *user_creds = NULL;
2408 char *client_session = "";
2409 enum cynara_client_creds client_creds_method = CLIENT_METHOD_SMACK;
2410 enum cynara_user_creds user_creds_method = USER_METHOD_UID;
2411 char err_msg[256] = {0, };
2413 retv_if(unique_name == NULL, FALSE);
2415 BT_DBG("unique_name: %s", unique_name);
2417 retv_if(bt_service_conn == NULL, FALSE);
2419 ret_val = cynara_creds_get_default_client_method(&client_creds_method);
2420 if (ret_val != CYNARA_API_SUCCESS) {
2421 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
2422 BT_ERR("Fail to get default client method: %s", err_msg);
2426 ret_val = cynara_creds_get_default_user_method(&user_creds_method);
2427 if (ret_val != CYNARA_API_SUCCESS) {
2428 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
2429 BT_ERR("Fail to get default user method: %s", err_msg);
2433 ret_val = cynara_creds_gdbus_get_client(bt_service_conn, unique_name, client_creds_method, &client_creds);
2434 if (ret_val != CYNARA_API_SUCCESS) {
2435 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
2436 BT_ERR("Fail to get client credential: %s", err_msg);
2440 BT_DBG("client_creds: %s", client_creds);
2442 ret_val = cynara_creds_gdbus_get_user(bt_service_conn, unique_name, user_creds_method, &user_creds);
2443 if (ret_val != CYNARA_API_SUCCESS) {
2444 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
2445 BT_ERR("Fail to get user credential: %s", err_msg);
2451 BT_DBG("user_creds: %s", user_creds);
2453 switch (function_name) {
2454 case BT_SET_LOCAL_NAME:
2455 case BT_START_DISCOVERY:
2456 case BT_START_CUSTOM_DISCOVERY:
2457 case BT_CANCEL_DISCOVERY:
2458 case BT_OOB_ADD_REMOTE_DATA:
2459 case BT_OOB_REMOVE_REMOTE_DATA:
2460 case BT_SET_ADVERTISING:
2461 case BT_SET_CUSTOM_ADVERTISING:
2462 case BT_SET_ADVERTISING_PARAMETERS:
2463 case BT_START_LE_DISCOVERY:
2464 case BT_STOP_LE_DISCOVERY:
2466 case BT_BOND_DEVICE:
2467 case BT_CANCEL_BONDING:
2468 case BT_UNBOND_DEVICE:
2470 case BT_SET_AUTHORIZATION:
2471 case BT_UNSET_AUTHORIZATION:
2472 case BT_SEARCH_SERVICE:
2474 case BT_RFCOMM_CLIENT_CONNECT:
2475 case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
2476 case BT_RFCOMM_SOCKET_DISCONNECT:
2477 case BT_RFCOMM_SOCKET_WRITE:
2478 case BT_RFCOMM_CREATE_SOCKET:
2479 case BT_RFCOMM_REMOVE_SOCKET:
2481 case BT_OPP_PUSH_FILES:
2482 case BT_OPP_CANCEL_PUSH:
2484 case BT_OBEX_SERVER_ACCEPT_CONNECTION:
2485 case BT_OBEX_SERVER_REJECT_CONNECTION:
2486 case BT_OBEX_SERVER_ACCEPT_FILE:
2487 case BT_OBEX_SERVER_REJECT_FILE:
2488 case BT_OBEX_SERVER_SET_PATH:
2489 case BT_OBEX_SERVER_SET_ROOT:
2490 case BT_OBEX_SERVER_CANCEL_TRANSFER:
2491 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS:
2493 case BT_AUDIO_CONNECT:
2494 case BT_AUDIO_DISCONNECT:
2496 case BT_AG_DISCONNECT:
2498 case BT_AV_DISCONNECT:
2499 case BT_AV_SOURCE_CONNECT:
2500 case BT_AV_SOURCE_DISCONNECT:
2501 case BT_AVRCP_CONTROL_CONNECT:
2502 case BT_AVRCP_CONTROL_DISCONNECT:
2504 case BT_HF_DISCONNECT:
2506 case BT_HID_CONNECT:
2507 case BT_HID_DISCONNECT:
2510 case BT_DISCONNECT_LE:
2512 case BT_SET_ADVERTISING_DATA:
2513 case BT_SET_SCAN_RESPONSE_DATA:
2515 case BT_HDP_CONNECT:
2516 case BT_HDP_DISCONNECT:
2517 case BT_HDP_SEND_DATA:
2519 case BT_DPM_SET_ALLOW_BT_MODE:
2520 case BT_DPM_GET_ALLOW_BT_MODE:
2521 case BT_DPM_SET_DEVICE_RESTRITION:
2522 case BT_DPM_GET_DEVICE_RESTRITION:
2523 case BT_DPM_SET_UUID_RESTRITION:
2524 case BT_DPM_GET_UUID_RESTRITION:
2525 case BT_DPM_ADD_DEVICES_BLACKLIST:
2526 case BT_DPM_ADD_DEVICES_WHITELIST:
2527 case BT_DPM_ADD_UUIDS_BLACKLIST:
2528 case BT_DPM_ADD_UUIDS_WHITELIST:
2529 case BT_DPM_CLEAR_DEVICES_BLACKLIST:
2530 case BT_DPM_CLEAR_DEVICES_WHITELIST:
2531 case BT_DPM_CLEAR_UUIDS_BLACKLIST:
2532 case BT_DPM_CLEAR_UUIDS_WHITELIST:
2533 case BT_DPM_REMOVE_DEVICE_BLACKLIST:
2534 case BT_DPM_REMOVE_DEVICE_WHITELIST:
2535 case BT_DPM_REMOVE_UUID_BLACKLIST:
2536 case BT_DPM_REMOVE_UUID_WHITELIST:
2537 case BT_DPM_GET_DEVICES_BLACKLIST:
2538 case BT_DPM_GET_DEVICES_WHITELIST:
2539 case BT_DPM_GET_UUIDS_BLACKLIST:
2540 case BT_DPM_GET_UUIDS_WHITELIST:
2541 case BT_DPM_SET_ALLOW_OUTGOING_CALL:
2542 case BT_DPM_GET_ALLOW_OUTGOING_CALL:
2543 case BT_DPM_SET_PAIRING_STATE:
2544 case BT_DPM_GET_PAIRING_STATE:
2545 case BT_DPM_SET_PROFILE_STATE:
2546 case BT_DPM_GET_PROFILE_STATE:
2547 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE:
2548 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE:
2549 case BT_DPM_SET_DISCOVERABLE_STATE:
2550 case BT_DPM_GET_DISCOVERABLE_STATE:
2551 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE:
2552 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE:
2553 case BT_DPM_SET_DATA_TRANSFER_STATE:
2554 case BT_DPM_GET_DATA_TRANSFER_STATE:
2556 case BT_NETWORK_ACTIVATE:
2557 case BT_NETWORK_DEACTIVATE:
2558 case BT_NETWORK_CONNECT:
2559 case BT_NETWORK_DISCONNECT:
2560 case BT_NETWORK_SERVER_DISCONNECT:
2562 case BT_GATT_GET_PRIMARY_SERVICES:
2563 case BT_GATT_DISCOVER_CHARACTERISTICS:
2564 case BT_GATT_SET_PROPERTY_REQUEST:
2565 case BT_GATT_READ_CHARACTERISTIC:
2566 case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
2567 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
2568 BT_PRIVILEGE_PUBLIC);
2570 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
2571 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PUBLIC);
2576 case BT_ENABLE_ADAPTER:
2577 case BT_DISABLE_ADAPTER:
2578 case BT_RESET_ADAPTER:
2579 case BT_RECOVER_ADAPTER:
2580 case BT_ENABLE_ADAPTER_LE:
2581 case BT_DISABLE_ADAPTER_LE:
2582 case BT_SET_CONNECTABLE:
2583 case BT_SET_DISCOVERABLE_MODE:
2584 case BT_ADD_WHITE_LIST:
2585 case BT_REMOVE_WHITE_LIST:
2586 case BT_CLEAR_WHITE_LIST:
2587 case BT_SET_MANUFACTURER_DATA:
2588 case BT_SET_SCAN_PARAMETERS:
2590 case BT_CANCEL_SEARCH_SERVICE:
2591 case BT_ENABLE_RSSI:
2593 case BT_RFCOMM_ACCEPT_CONNECTION:
2594 case BT_RFCOMM_REJECT_CONNECTION:
2595 case BT_RFCOMM_LISTEN:
2597 case BT_AVRCP_SET_TRACK_INFO:
2598 case BT_AVRCP_SET_PROPERTY:
2599 case BT_AVRCP_SET_PROPERTIES:
2600 case BT_AVRCP_HANDLE_CONTROL:
2601 case BT_AVRCP_CONTROL_SET_PROPERTY:
2602 case BT_AVRCP_CONTROL_GET_PROPERTY:
2603 case BT_AVRCP_GET_TRACK_INFO:
2605 case BT_SET_CONTENT_PROTECT:
2606 case BT_BOND_DEVICE_BY_TYPE:
2607 case BT_SET_LE_PRIVACY:
2608 case BT_LE_CONN_UPDATE:
2609 case BT_LE_READ_MAXIMUM_DATA_LENGTH:
2610 case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH:
2611 case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH:
2612 case BT_LE_SET_DATA_LENGTH:
2613 case BT_PBAP_CONNECT:
2614 case BT_PBAP_DISCONNECT:
2615 case BT_PBAP_GET_PHONEBOOK_SIZE:
2616 case BT_PBAP_GET_PHONEBOOK:
2617 case BT_PBAP_GET_LIST:
2618 case BT_PBAP_PULL_VCARD:
2619 case BT_PBAP_PHONEBOOK_SEARCH:
2620 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
2621 BT_PRIVILEGE_PLATFORM);
2623 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
2624 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PLATFORM);
2629 case BT_CHECK_ADAPTER:
2632 case BT_GET_LOCAL_NAME:
2633 case BT_GET_LOCAL_ADDRESS:
2634 case BT_GET_LOCAL_VERSION:
2635 case BT_IS_SERVICE_USED:
2636 case BT_GET_DISCOVERABLE_MODE:
2637 case BT_GET_DISCOVERABLE_TIME:
2638 case BT_IS_DISCOVERYING:
2639 case BT_IS_LE_DISCOVERYING:
2640 case BT_IS_CONNECTABLE:
2641 case BT_GET_BONDED_DEVICES:
2642 case BT_GET_BONDED_DEVICE:
2643 case BT_IS_DEVICE_CONNECTED:
2644 case BT_GET_SPEAKER_GAIN:
2645 case BT_SET_SPEAKER_GAIN:
2646 case BT_OOB_READ_LOCAL_DATA:
2647 case BT_RFCOMM_CLIENT_IS_CONNECTED:
2648 case BT_RFCOMM_IS_UUID_AVAILABLE:
2649 case BT_GET_ADVERTISING_DATA:
2650 case BT_GET_SCAN_RESPONSE_DATA:
2651 case BT_IS_ADVERTISING:
2653 case BT_OBEX_SERVER_ALLOCATE:
2654 case BT_OBEX_SERVER_DEALLOCATE:
2656 /* Non-privilege control */
2659 BT_ERR("Unknown function!");
2673 GDBusNodeInfo *__bt_service_create_method_node_info
2674 (const gchar *introspection_data)
2677 GDBusNodeInfo *node_info = NULL;
2679 if (introspection_data == NULL) {
2680 ERR("Introspection XML not present");
2684 node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
2687 ERR("Unable to create node: %s", err->message);
2688 g_clear_error(&err);
2693 int __bt_service_register_object(GDBusConnection *conn,
2694 GDBusNodeInfo *node_info, gboolean reg)
2696 static guint service_id = 0;
2697 GError *error = NULL;
2700 if (node_info == NULL)
2703 service_id = g_dbus_connection_register_object(conn,
2705 node_info->interfaces[0],
2707 NULL, NULL, &error);
2708 if (service_id == 0)
2711 if (service_id > 0) {
2712 g_dbus_connection_unregister_object(conn,
2721 int _bt_service_register(void)
2723 GDBusConnection *conn;
2727 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
2728 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
2730 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
2732 G_BUS_NAME_OWNER_FLAGS_NONE,
2735 BT_DBG("owner_id is [%d]", owner_id);
2739 node_info = __bt_service_create_method_node_info(
2740 bt_service_introspection_xml);
2742 if (node_info == NULL)
2745 result = __bt_service_register_object(conn, node_info, TRUE);
2746 g_dbus_node_info_unref(node_info);
2749 if (result != BLUETOOTH_ERROR_NONE)
2752 bt_service_conn = conn;
2754 return BLUETOOTH_ERROR_NONE;
2757 if (bt_service_conn) {
2758 g_object_unref(bt_service_conn);
2759 bt_service_conn = NULL;
2762 return BLUETOOTH_ERROR_INTERNAL;
2765 void _bt_service_unregister(void)
2767 if (bt_service_conn) {
2768 __bt_service_register_object(bt_service_conn, NULL, FALSE);
2769 if (bt_service_conn) {
2770 g_object_unref(bt_service_conn);
2771 bt_service_conn = NULL;
2774 g_dbus_node_info_unref(node_info);
2778 g_bus_unown_name(owner_id);
2784 int _bt_service_cynara_init(void)
2787 char err_msg[256] = {0, };
2789 retv_if(p_cynara != NULL, BLUETOOTH_ERROR_ALREADY_INITIALIZED);
2791 result = cynara_initialize(&p_cynara, conf);
2793 if (result != CYNARA_API_SUCCESS) {
2794 cynara_strerror(result, err_msg, sizeof(err_msg));
2795 BT_ERR("Fail to initialize cynara: [%s]", err_msg);
2796 return BLUETOOTH_ERROR_INTERNAL;
2799 return BLUETOOTH_ERROR_NONE;
2802 void _bt_service_cynara_deinit(void)
2805 char err_msg[256] = {0, };
2807 ret_if(p_cynara == NULL);
2809 result = cynara_finish(p_cynara);
2811 if (result != CYNARA_API_SUCCESS) {
2812 cynara_strerror(result, err_msg, sizeof(err_msg));
2813 BT_ERR("Fail to finish cynara: [%s]", err_msg);