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.
23 #include <gio/gunixfdlist.h>
24 #include <cynara-client.h>
25 #include <cynara-creds-gdbus.h>
26 #include <systemd/sd-daemon.h>
29 #include "bluetooth-api.h"
30 #include "bluetooth-audio-api.h"
31 #include "bluetooth-gatt-server-api.h"
32 #include "bluetooth-mesh-api.h"
33 #include "bt-request-handler.h"
34 #include "bt-service-common.h"
35 #include "bt-service-util.h"
37 #include "bt-service-core-adapter.h"
38 #include "bt-service-core-adapter-le.h"
39 #include "bt-service-core-device.h"
41 #include "bt-service-audio-common.h"
42 #include "bt-service-avrcp-tg.h"
43 #include "bt-service-avrcp-ctrl.h"
44 #include "bt-service-gatt.h"
45 #include "bt-service-mesh-main.h"
46 #include "bt-service-mesh-util.h"
47 #include "bt-service-mesh-network.h"
48 #include "bt-service-mesh-config-client.h"
49 #include "bt-service-mesh-model.h"
50 #include "bt-service-dpm.h"
51 #include "bt-service-hidhost.h"
52 #include "bt-service-rfcomm.h"
53 #include "bt-service-hdp.h"
54 #include "bt-service-tds.h"
57 #include "bt-service-obex-server.h"
58 #include "bt-service-opp-client.h"
59 #include "bt-service-map-client.h"
60 #include "bt-service-pbap.h"
61 #include "bt-service-oob.h"
63 #include "bt-service-battery-monitor.h"
65 #include "bt-service-l2cap-le.h"
67 #ifdef TIZEN_FEATURE_BT_PAN_NAP
68 #include "bt-service-network.h"
71 #ifdef TIZEN_FEATURE_BT_IPSP
72 #include "bt-service-ipsp.h"
74 /* For maintaining Application Sync API call requests */
75 static GSList *invocation_list = NULL;
77 #ifdef TIZEN_FEATURE_BT_CONTAINER
80 gboolean is_container;
82 static GSList *nspid_list = NULL;
85 static GDBusConnection *bt_service_conn;
86 static guint owner_id = 0;
87 static guint owner_sig_id = 0;
88 static gboolean is_le_intended = FALSE;
90 static cynara *p_cynara;
91 static cynara_configuration *conf;
92 static const char *requester_unique_creds = NULL;
94 static const gchar bt_service_introspection_xml[] =
95 "<node name='/org/projectx/bt_service'>"
96 " <interface name='org.projectx.bt'>"
97 " <method name='service_request'>"
98 /* Input Parameters */
99 " <arg type='i' name='service_type' direction='in' />"
100 " <arg type='i' name='service_function' direction='in' />"
101 " <arg type='i' name='request_type' direction='in' />"
102 " <arg type='ay' name='input_param1' direction='in' />"
103 " <arg type='ay' name='input_param2' direction='in' />"
104 " <arg type='ay' name='input_param3' direction='in' />"
105 " <arg type='ay' name='input_param4' direction='in' />"
106 " <arg type='ay' name='input_param5' direction='in' />"
107 /* Return Parameters */
108 " <arg type='i' name='output_param1' direction='out' />"
109 " <arg type='v' name='output_param2' direction='out' />"
111 " <method name='get_avc_mode'>"
113 " <arg type='u' name='avc_mode' direction='out' />"
118 static gboolean name_acquired = FALSE;
120 static char *current_sender_playing = NULL;
122 GDBusNodeInfo *node_info_g = NULL;
124 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param);
126 static void __bt_service_method(GDBusConnection *connection,
128 const gchar *object_path,
129 const gchar *interface_name,
130 const gchar *method_name,
131 GVariant *parameters,
132 GDBusMethodInvocation *invocation,
135 int __bt_bluez_request(int function_name,
138 GDBusMethodInvocation *context,
143 GArray **out_param1);
144 int __bt_obexd_request(int function_name,
147 GDBusMethodInvocation *context,
152 GArray **out_param1);
153 int __bt_agent_request(int function_name,
156 GDBusMethodInvocation *context,
161 GArray **out_param1);
162 int __bt_core_request(int function_name,
165 GDBusMethodInvocation *context,
166 GVariant *in_param1);
168 gboolean __bt_service_check_privilege(int function_name,
170 const char *unique_name);
172 /* Function definitions*/
173 GSList *_bt_get_invocation_list(void)
175 return invocation_list;
178 void _bt_free_info_from_invocation_list(invocation_info_t *req_info)
180 ret_if(NULL == req_info);
181 invocation_list = g_slist_remove(invocation_list, req_info);
182 g_free(req_info->sender);
183 g_free(req_info->user_data);
187 void _bt_set_le_intended_status(gboolean value)
189 is_le_intended = value;
192 static void __bt_service_get_parameters(GVariant *in_param,
193 void *value, int size)
196 buf = (void *)g_variant_get_data(in_param);
197 memcpy(value, buf, size);
200 static gboolean __bt_is_sync_function(int service_function)
202 /*TODO: Keep adding sync methods with expect replies from bluetooth service */
203 if (service_function == BT_GET_LOCAL_ADDRESS
204 || service_function == BT_GET_LOCAL_NAME
205 || service_function == BT_GET_LOCAL_VERSION
206 || service_function == BT_GET_BONDED_DEVICES
207 || service_function == BT_GET_BONDED_DEVICE
208 || service_function == BT_GET_PROFILE_CONNECTED_DEVICES
209 || service_function == BT_GET_IS_ALIAS_SET
210 || service_function == BT_GET_CONNECTED_LINK_TYPE
211 || service_function == BT_IS_SERVICE_USED
212 || service_function == BT_RFCOMM_LISTEN_AND_ACCEPT
213 || service_function == BT_RFCOMM_LISTEN
214 || service_function == BT_HDP_REGISTER_SINK_APP
215 || service_function == BT_HDP_UNREGISTER_SINK_APP
216 || service_function == BT_HDP_GET_FD
217 || service_function == BT_AVRCP_GET_TRACK_INFO
218 || service_function == BT_AVRCP_CONTROL_GET_PROPERTY
219 || service_function == BT_SET_ADVERTISING_DATA
220 || service_function == BT_SET_SCAN_RESPONSE_DATA
221 || service_function == BT_SET_ADVERTISING
222 || service_function == BT_SET_CUSTOM_ADVERTISING
223 || service_function == BT_GATT_SERVER_REGISTER
224 || service_function == BT_GATT_SERVER_ADD_SERVICE
225 || service_function == BT_GATT_SERVER_ADD_CHARACTERISTIC
226 || service_function == BT_GATT_SERVER_ADD_DESCRIPTOR
227 || service_function == BT_GATT_SERVER_START_SERVICE
228 || service_function == BT_GATT_SERVER_STOP_SERVICE
229 || service_function == BT_GATT_SERVER_DELETE_SERVICE
230 || service_function == BT_START_LE_DISCOVERY
231 || service_function == BT_STOP_LE_DISCOVERY
232 || service_function == BT_GET_CONNECTABLE
233 || service_function == BT_GATT_CLIENT_REGISTER
234 || service_function == BT_GATT_GET_PRIMARY_SERVICES
235 || service_function == BT_GATT_GET_SERVICE_PROPERTIES
236 || service_function == BT_GATT_GET_INCLUDED_SERVICES
237 || service_function == BT_GATT_GET_CHARACTERISTIC_PROPERTIES
238 || service_function == BT_GATT_WATCH_CHARACTERISTIC
239 || service_function == BT_GATT_ACQUIRE_WRITE
240 || service_function == BT_AUDIO_SELECT_ROLE
242 || service_function == BT_MESH_INIT
243 || service_function == BT_MESH_NETWORK_CREATE
244 || service_function == BT_MESH_NETWORK_DESTROY
245 || service_function == BT_MESH_NETWORK_LOAD
246 || service_function == BT_MESH_NETWORK_SCAN
247 || service_function == BT_MESH_NETWORK_ADD_NETKEY
248 || service_function == BT_MESH_NETWORK_DELETE_NETKEY
249 || service_function == BT_MESH_NETWORK_UPDATE_NETKEY
250 || service_function == BT_MESH_NETWORK_ADD_APPKEY
251 || service_function == BT_MESH_NETWORK_DELETE_APPKEY
252 || service_function == BT_MESH_NETWORK_UPDATE_APPKEY
253 || service_function == BT_L2CAP_LE_LISTEN_AND_ACCEPT
254 || service_function == BT_L2CAP_LE_LISTEN)
260 void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
261 char *sender, int service_function,
262 gpointer invocation_data)
264 invocation_info_t *info;
265 info = g_malloc0(sizeof(invocation_info_t));
266 info->context = invocation;
267 info->result = result;
268 info->sender = g_strdup(sender);
269 info->service_function = service_function;
270 info->user_data = invocation_data;
271 invocation_list = g_slist_append(invocation_list, info);
275 static int __bt_service_get_sender_pid(const char *unique_name, pid_t *pid)
278 char err_msg[256] = {0, };
280 retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
282 ret = cynara_creds_gdbus_get_pid(bt_service_conn, unique_name, pid);
283 if (ret != CYNARA_API_SUCCESS) {
284 cynara_strerror(ret, err_msg, sizeof(err_msg));
285 BT_ERR("Fail to get user credential: %s", err_msg);
287 return BLUETOOTH_ERROR_INTERNAL;
290 return BLUETOOTH_ERROR_NONE;
293 static int __bt_bm_request_data(_bt_battery_data_t *latest)
295 int ret = _bt_bm_read_data(latest);
296 if (ret == BLUETOOTH_ERROR_NONE) {
297 BT_DBG("Received data from bluetooth battery monitor: %ld %ld %d %d",
298 latest->session_start_time, latest->session_end_time,
299 latest->session_scan_time, latest->session_connected_time);
301 if (latest->atm_list == NULL) {
302 BT_DBG("No app data transaction for this session");
306 for (GSList *l = latest->atm_list; l != NULL; l = g_slist_next(l)) {
307 _bt_battery_app_data_t *t = (_bt_battery_app_data_t *)(l->data);
308 BT_DBG("%ld %ld %d %d", (long int)(t->uid), (long int)(t->pid), t->rx_bytes, t->tx_bytes);
312 BT_ERR("Error encountered");
316 static void __bt_service_method(GDBusConnection *connection,
318 const gchar *object_path,
319 const gchar *interface_name,
320 const gchar *method_name,
321 GVariant *parameters,
322 GDBusMethodInvocation *invocation,
327 BT_DBG("Method[%s] Object Path[%s] Interface Name[%s]",
328 method_name, object_path, interface_name);
330 if (g_strcmp0(method_name, "service_request") == 0) {
332 int service_function;
334 GVariant *param1 = NULL;
335 GVariant *param2 = NULL;
336 GVariant *param3 = NULL;
337 GVariant *param4 = NULL;
338 GVariant *param5 = NULL;
339 GArray *out_param1 = NULL;
340 GVariant *out_var = NULL;
341 GVariant *temp = NULL;
344 const char *unique_name = NULL;
346 g_variant_get(parameters, "(iii@ay@ay@ay@ay@ay)", &service_type,
347 &service_function, &request_type,
348 ¶m1, ¶m2, ¶m3, ¶m4, ¶m5);
350 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
352 #ifdef TIZEN_FEATURE_BT_CONTAINER
353 /* In case of the bt-service in container, only privilege check request is coming
354 * from the bt-service in host. At this time, the original sender's privilege
355 * should be checked not bt-service's privilege */
356 if (_bt_service_is_container() == TRUE)
357 unique_name = (const char *)g_variant_get_data(param1);
359 unique_name = sender;
361 unique_name = sender;
364 if (service_type == BT_CORE_SERVICE) {
365 BT_DBG("No need to check privilege from bt-core");
366 } else if (__bt_service_check_privilege(service_function,
367 service_type, unique_name) == FALSE) {
368 BT_ERR("Client don't have the privilege to excute this function");
369 result = BLUETOOTH_ERROR_PERMISSION_DEINED;
373 BT_DBG("SERVICE TYPE [%d] SERVICE FUNC [%d]",
374 service_type, service_function);
375 switch (service_type) {
376 case BT_BLUEZ_SERVICE:
377 result = __bt_bluez_request(service_function,
378 request_type, request_id,
379 invocation, param1, param2,
380 param3, param4, &out_param1);
382 case BT_OBEX_SERVICE:
383 result = __bt_obexd_request(service_function,
384 request_type, request_id,
387 param4, &out_param1);
389 case BT_AGENT_SERVICE:
390 result = __bt_agent_request(service_function,
391 request_type, request_id,
394 param4, &out_param1);
396 case BT_CORE_SERVICE:
397 result = __bt_core_request(service_function,
398 request_type, request_id,
401 case BT_CHECK_PRIVILEGE:
402 result = BLUETOOTH_ERROR_NONE;
405 BT_ERR("Unknown service type");
406 result = BLUETOOTH_ERROR_INTERNAL;
410 if (result != BLUETOOTH_ERROR_NONE)
413 if (service_type == BT_CHECK_PRIVILEGE)
416 if (service_function == BT_OPP_PUSH_FILES)
419 if (request_type == BT_ASYNC_REQ ||
420 __bt_is_sync_function(service_function)) {
421 /* Do not send reply to bt-api over dbus,
422 Invocation context is already saved in service_function */
427 out_var = g_variant_new_from_data((const GVariantType *)"ay",
428 out_param1->data, out_param1->len,
431 temp = g_variant_new("(iv)", result, out_var);
432 g_dbus_method_invocation_return_value(invocation, temp);
433 g_array_free(out_param1, TRUE);
437 g_variant_unref(param1);
438 g_variant_unref(param2);
439 g_variant_unref(param3);
440 g_variant_unref(param4);
441 g_variant_unref(param5);
445 BT_ERR_C("Request is failed [%s] [0x%x]",
446 _bt_convert_error_to_string(result), result);
448 out_var = g_variant_new_from_data((const GVariantType *)"ay",
449 out_param1->data, out_param1->len,
452 temp = g_variant_new("(iv)", result, out_var);
453 g_dbus_method_invocation_return_value(invocation, temp);
455 g_array_free(out_param1, TRUE);
458 g_variant_unref(param1);
459 g_variant_unref(param2);
460 g_variant_unref(param3);
461 g_variant_unref(param4);
462 g_variant_unref(param5);
464 else if (g_strcmp0(method_name, "get_avc_mode") == 0) {
465 unsigned int mode = 0;
467 if (_bt_audio_get_avc_mode(&mode) != BLUETOOTH_ERROR_NONE)
468 BT_ERR("Fail to get the avc mode");
470 BT_DBG("Absolute Volume Control mode: %d", mode);
472 g_dbus_method_invocation_return_value(invocation,
473 g_variant_new("(u)", mode));
481 static const GDBusInterfaceVTable method_table = {
488 int __bt_bluez_request(int function_name,
491 GDBusMethodInvocation *context,
498 int result = BLUETOOTH_ERROR_NONE;
501 switch (function_name) {
502 case BT_ENABLE_ADAPTER: {
503 result = _bt_enable_adapter();
504 _bt_adapter_start_enable_timer();
507 case BT_DISABLE_ADAPTER: {
508 result = _bt_disable_adapter();
511 case BT_RECOVER_ADAPTER:
512 result = _bt_recover_adapter();
514 case BT_RESET_ADAPTER:
515 result = _bt_reset_adapter();
517 case BT_BATTERY_READ_DATA: {
518 _bt_battery_data_t *data = NULL;
519 data = g_malloc0(sizeof(_bt_battery_data_t));
520 result = __bt_bm_request_data(data);
522 bt_battery_dbus_data_t dbus_data;
523 memset(&dbus_data, 0, sizeof(bt_battery_dbus_data_t));
524 dbus_data.session_start_time = data->session_start_time;
525 dbus_data.session_end_time = data->session_end_time;
526 dbus_data.session_scan_time = data->session_scan_time;
527 dbus_data.session_connected_time = data->session_connected_time;
528 dbus_data.tx_time = data->tx_time;
529 dbus_data.rx_time = data->rx_time;
530 dbus_data.idle_time = data->idle_time;
532 /*Populating app data*/
534 for (GSList *l = data->atm_list; l != NULL; l = g_slist_next(l)) {
535 bt_battery_app_data *t = (bt_battery_app_data *)(l->data);
536 memcpy(&dbus_data.app_data[n], t, sizeof(bt_battery_app_data));
539 dbus_data.num_app = n;
540 g_array_append_vals(*out_param1, &dbus_data, sizeof(bt_battery_dbus_data_t));
541 g_slist_free_full(data->atm_list, g_free);
546 case BT_CHECK_ADAPTER: {
547 int enabled = BT_ADAPTER_DISABLED;
548 result = _bt_check_adapter(&enabled);
550 g_array_append_vals(*out_param1, &enabled,
554 case BT_ENABLE_ADAPTER_LE:
555 _bt_set_le_intended_status(TRUE);
556 result = _bt_enable_adapter_le();
558 case BT_DISABLE_ADAPTER_LE:
559 _bt_set_le_intended_status(FALSE);
560 result = _bt_disable_adapter_le();
562 case BT_START_DISCOVERY: {
563 unsigned short max_response;
564 unsigned short discovery_duration;
565 unsigned int classOfDeviceMask;
568 __bt_service_get_parameters(in_param1,
569 &max_response, sizeof(unsigned short));
570 __bt_service_get_parameters(in_param2,
571 &discovery_duration, sizeof(unsigned short));
572 __bt_service_get_parameters(in_param3,
573 &classOfDeviceMask, sizeof(unsigned int));
574 __bt_service_get_parameters(in_param4, &uid, sizeof(uid_t));
576 result = _bt_start_discovery(max_response, discovery_duration, classOfDeviceMask);
578 if (result == BLUETOOTH_ERROR_NONE) {
581 sender = (char*)g_dbus_method_invocation_get_sender(context);
583 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
584 BT_ERR("Fail to get the sender pid");
586 BT_DBG("Remeber pid / uid for the scan operation");
587 _bt_bm_add_scan_app(SCAN_REGACY, uid, pid);
592 case BT_START_CUSTOM_DISCOVERY: {
593 bt_discovery_role_type_t role;
595 __bt_service_get_parameters(in_param1,
596 &role, sizeof(bt_discovery_role_type_t));
597 result = _bt_start_custom_discovery(role);
601 case BT_CANCEL_DISCOVERY:
602 result = _bt_cancel_discovery();
604 case BT_IS_DISCOVERYING: {
605 gboolean discovering = FALSE;
606 discovering = _bt_is_discovering();
607 g_array_append_vals(*out_param1,
608 &discovering, sizeof(gboolean));
611 case BT_GET_LOCAL_ADDRESS: {
612 result = _bt_get_local_address();
614 /* Save invocation */
615 if (result == BLUETOOTH_ERROR_NONE) {
616 sender = (char*)g_dbus_method_invocation_get_sender(context);
617 _bt_save_invocation_context(context, result, sender,
618 function_name, NULL);
622 case BT_GET_LOCAL_VERSION: {
623 result = _bt_get_local_version();
625 /* Save invocation */
626 if (result == BLUETOOTH_ERROR_NONE) {
627 sender = (char*)g_dbus_method_invocation_get_sender(context);
628 _bt_save_invocation_context(context, result, sender,
629 function_name, NULL);
633 case BT_GET_LOCAL_NAME: {
634 result = _bt_get_local_name();
636 /* Save invocation */
637 if (result == BLUETOOTH_ERROR_NONE) {
638 sender = (char*)g_dbus_method_invocation_get_sender(context);
639 _bt_save_invocation_context(context, result, sender,
640 function_name, NULL);
644 case BT_SET_LOCAL_NAME: {
645 bluetooth_device_name_t local_name = { {0} };
646 __bt_service_get_parameters(in_param1,
647 &local_name, sizeof(bluetooth_device_name_t));
648 result = _bt_set_local_name(local_name.name);
651 case BT_GET_DISCOVERABLE_MODE: {
652 int discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
653 result = _bt_get_discoverable_mode(&discoverable_mode);
654 g_array_append_vals(*out_param1, &discoverable_mode, sizeof(int));
657 case BT_GET_DISCOVERABLE_TIME: {
660 result = _bt_get_timeout_value(&timeout);
661 g_array_append_vals(*out_param1, &timeout, sizeof(int));
664 case BT_SET_DISCOVERABLE_MODE: {
665 int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
668 __bt_service_get_parameters(in_param1, &mode, sizeof(int));
669 __bt_service_get_parameters(in_param2, &time, sizeof(int));
671 result = _bt_set_discoverable_mode(mode, time);
674 case BT_IS_CONNECTABLE: {
675 gboolean is_connectable = FALSE;
677 is_connectable = _bt_is_connectable();
678 g_array_append_vals(*out_param1, &is_connectable, sizeof(gboolean));
681 case BT_GET_CONNECTABLE: {
682 result = _bt_get_connectable();
684 /* Save invocation */
685 if (result == BLUETOOTH_ERROR_NONE) {
686 sender = (char*)g_dbus_method_invocation_get_sender(context);
687 _bt_save_invocation_context(context, result, sender,
688 function_name, NULL);
692 case BT_SET_CONNECTABLE: {
693 gboolean is_connectable;
695 __bt_service_get_parameters(in_param1,
696 &is_connectable, sizeof(gboolean));
697 result = _bt_set_connectable(is_connectable);
700 case BT_IS_SERVICE_USED: {
703 uuid = (char *)g_variant_get_data(in_param1);
704 BT_INFO("UUID to be searched [%s]", uuid);
705 result = _bt_is_service_used();
707 /* Save invocation */
708 if (result == BLUETOOTH_ERROR_NONE) {
709 sender = (char*)g_dbus_method_invocation_get_sender(context);
710 _bt_save_invocation_context(context, result, sender,
711 function_name, g_strdup(uuid));
715 case BT_GET_BONDED_DEVICES: {
716 result = _bt_get_bonded_devices();
717 /* Save invocation */
718 if (result == BLUETOOTH_ERROR_NONE) {
719 sender = (char*)g_dbus_method_invocation_get_sender(context);
720 _bt_save_invocation_context(context, result, sender,
721 function_name, NULL);
725 case BT_GET_BONDED_DEVICE: {
726 bluetooth_device_address_t address = { {0} };
728 __bt_service_get_parameters(in_param1,
729 &address, sizeof(bluetooth_device_address_t));
731 result = _bt_get_bonded_device_info(&address);
732 /* Save invocation */
733 if (result == BLUETOOTH_ERROR_NONE) {
734 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
736 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
740 _bt_convert_addr_type_to_string(addr, address.addr);
741 sender = (char*)g_dbus_method_invocation_get_sender(context);
742 _bt_save_invocation_context(context, result, sender,
743 function_name, addr);
747 case BT_GET_PROFILE_CONNECTED_DEVICES: {
749 uuid = (char *)g_variant_get_data(in_param1);
750 result = _bt_get_profile_connected_devices(uuid);
752 /* Save invocation */
753 if (result == BLUETOOTH_ERROR_NONE) {
754 sender = (char *)g_dbus_method_invocation_get_sender(context);
755 _bt_save_invocation_context(context, result, sender,
756 function_name, NULL);
761 bluetooth_device_address_t address = { {0} };
762 const char *local_name;
764 __bt_service_get_parameters(in_param1,
765 &address, sizeof(bluetooth_device_address_t));
766 local_name = (const char *)g_variant_get_data(in_param2);
768 result = _bt_set_alias(&address, local_name);
771 case BT_BOND_DEVICE: {
772 bluetooth_device_address_t address = { {0} };
774 __bt_service_get_parameters(in_param1,
775 &address, sizeof(bluetooth_device_address_t));
776 result = _bt_bond_device(&address, BLUETOOTH_DEV_CONN_DEFAULT, out_param1);
778 /* Save invocation */
779 if (result == BLUETOOTH_ERROR_NONE) {
780 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
781 _bt_convert_addr_type_to_string(addr, address.addr);
782 sender = (char*)g_dbus_method_invocation_get_sender(context);
783 _bt_save_invocation_context(context, result, sender,
784 function_name, (gpointer)addr);
786 bluetooth_device_info_t dev_info;
788 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
789 memcpy(&dev_info.device_address, &address,
790 sizeof(bluetooth_device_address_t));
791 g_array_append_vals(*out_param1, &dev_info,
792 sizeof(bluetooth_device_info_t));
796 case BT_BOND_DEVICE_BY_TYPE: {
797 bluetooth_device_address_t address = { {0} };
798 unsigned short conn_type = 0;
800 __bt_service_get_parameters(in_param1,
801 &address, sizeof(bluetooth_device_address_t));
802 __bt_service_get_parameters(in_param2,
803 &conn_type, sizeof(unsigned short));
805 result = _bt_bond_device(&address, conn_type, out_param1);
806 /* Save invocation */
807 if (result == BLUETOOTH_ERROR_NONE) {
808 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
809 _bt_convert_addr_type_to_string(addr, address.addr);
810 sender = (char*)g_dbus_method_invocation_get_sender(context);
811 _bt_save_invocation_context(context, result, sender,
812 function_name, (gpointer)addr);
814 bluetooth_device_info_t dev_info;
816 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
817 memcpy(&dev_info.device_address, &address,
818 sizeof(bluetooth_device_address_t));
819 g_array_append_vals(*out_param1, &dev_info,
820 sizeof(bluetooth_device_info_t));
824 case BT_UNBOND_DEVICE: {
825 bluetooth_device_address_t address = { {0} };
827 __bt_service_get_parameters(in_param1,
828 &address, sizeof(bluetooth_device_address_t));
829 result = _bt_unbond_device(&address, out_param1);
831 /* Save invocation */
832 if (result == BLUETOOTH_ERROR_NONE) {
833 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
834 _bt_convert_addr_type_to_string(addr, address.addr);
835 sender = (char*)g_dbus_method_invocation_get_sender(context);
836 _bt_save_invocation_context(context, result, sender,
837 function_name, (gpointer)addr);
839 g_array_append_vals(*out_param1, &address,
840 sizeof(bluetooth_device_address_t));
844 case BT_CANCEL_BONDING:{
845 result = _bt_cancel_bonding();
848 case BT_SEARCH_SERVICE: {
849 bluetooth_device_address_t address = { {0} };
850 __bt_service_get_parameters(in_param1,
851 &address, sizeof(bluetooth_device_address_t));
852 result = _bt_search_device(&address);
853 /* Save invocation */
854 if (result == BLUETOOTH_ERROR_NONE) {
855 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
856 _bt_convert_addr_type_to_string(addr, address.addr);
857 sender = (char*)g_dbus_method_invocation_get_sender(context);
858 _bt_save_invocation_context(context, result, sender,
859 function_name, (gpointer)addr);
861 bt_sdp_info_t sdp_info;
863 memset(&sdp_info, 0x00, sizeof(bt_sdp_info_t));
864 memcpy(&sdp_info.device_addr, &address,
865 sizeof(bluetooth_device_address_t));
866 g_array_append_vals(*out_param1, &sdp_info, sizeof(bt_sdp_info_t));
870 case BT_CANCEL_SEARCH_SERVICE: {
871 result = _bt_cancel_search_device();
874 case BT_SET_PASSKEY_NOTIFICATION: {
878 sender = (char *)g_dbus_method_invocation_get_sender(context);
879 __bt_service_get_parameters(in_param1,
880 &enable, sizeof(gboolean));
882 result = _bt_set_passkey_notification(sender, enable);
885 case BT_SET_PIN_CODE: {
886 bluetooth_device_address_t address = { {0} };
887 bluetooth_device_pin_code_t pin_code = { {0} };
889 __bt_service_get_parameters(in_param1,
890 &address, sizeof(bluetooth_device_address_t));
891 __bt_service_get_parameters(in_param2,
892 &pin_code, sizeof(bluetooth_device_pin_code_t));
894 result = _bt_set_pin_code(&address, &pin_code);
897 case BT_UNSET_PIN_CODE: {
898 bluetooth_device_address_t address = { {0} };
900 __bt_service_get_parameters(in_param1,
901 &address, sizeof(bluetooth_device_address_t));
903 result = _bt_unset_pin_code(&address);
906 case BT_PASSKEY_REPLY: {
907 const char *passkey = NULL;
908 gboolean authentication_reply = FALSE;
909 passkey = g_variant_get_data(in_param1);
910 __bt_service_get_parameters(in_param2,
911 &authentication_reply, sizeof(gboolean));
912 result = _bt_passkey_reply(passkey, authentication_reply);
915 case BT_PASSKEY_CONFIRMATION_REPLY: {
916 gboolean confirmation_reply = FALSE;
917 __bt_service_get_parameters(in_param1,
918 &confirmation_reply, sizeof(gboolean));
919 result = _bt_passkey_confirmation_reply(confirmation_reply);
922 case BT_GET_IS_ALIAS_SET: {
923 bluetooth_device_address_t address = { {0} };
925 __bt_service_get_parameters(in_param1,
926 &address, sizeof(bluetooth_device_address_t));
928 result = _bt_is_alias_set(&address);
929 if (result == BLUETOOTH_ERROR_NONE) {
930 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
932 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
936 _bt_convert_addr_type_to_string(addr, address.addr);
937 sender = (char*)g_dbus_method_invocation_get_sender(context);
938 _bt_save_invocation_context(context, result, sender,
939 function_name, addr);
943 case BT_SET_AUTHORIZATION: {
944 bluetooth_device_address_t address = { {0} };
946 __bt_service_get_parameters(in_param1,
947 &address, sizeof(bluetooth_device_address_t));
948 __bt_service_get_parameters(in_param2,
949 &authorize, sizeof(gboolean));
950 result = _bt_set_authorization(&address, authorize);
953 case BT_SET_LE_PRIVACY: {
954 gboolean set_privacy;
955 __bt_service_get_parameters(in_param1, &set_privacy,
957 result = _bt_set_le_privacy(set_privacy);
960 case BT_ADD_ALLOW_LIST: {
961 bluetooth_device_address_t address = { {0} };
962 int address_type = 0;
964 __bt_service_get_parameters(in_param1,
965 &address, sizeof(bluetooth_device_address_t));
966 __bt_service_get_parameters(in_param2,
967 &address_type, sizeof(int));
968 result = _bt_set_allow_list(&address, address_type, is_add);
971 case BT_REMOVE_ALLOW_LIST: {
972 bluetooth_device_address_t address = { {0} };
973 int address_type = 0;
975 __bt_service_get_parameters(in_param1,
976 &address, sizeof(bluetooth_device_address_t));
977 __bt_service_get_parameters(in_param2,
978 &address_type, sizeof(int));
979 result = _bt_set_allow_list(&address, address_type, is_add);
982 case BT_UPDATE_LE_CONNECTION_MODE: {
984 bluetooth_device_address_t remote_address = { { 0 } };
985 bluetooth_le_connection_param_t parameters = { 0 };
986 bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED;
988 __bt_service_get_parameters(in_param1, &remote_address,
989 sizeof(bluetooth_device_address_t));
990 __bt_service_get_parameters(in_param2, &mode,
991 sizeof(bluetooth_le_connection_mode_t));
993 result = _bt_get_le_connection_parameter(mode, ¶meters);
994 if (result != BLUETOOTH_ERROR_NONE)
997 sender = (char *)g_dbus_method_invocation_get_sender(context);
999 result = _bt_le_connection_update(sender,
1000 remote_address.addr,
1001 parameters.interval_min,
1002 parameters.interval_max,
1004 parameters.timeout);
1007 case BT_SET_MANUFACTURER_DATA: {
1008 bluetooth_manufacturer_data_t m_data = { 0 };
1009 __bt_service_get_parameters(in_param1,
1010 &m_data, sizeof(bluetooth_manufacturer_data_t));
1011 result = _bt_set_manufacturer_data(&m_data);
1015 case BT_IS_DEVICE_CONNECTED: {
1016 bluetooth_device_address_t address = { {0} };
1017 gboolean connected = FALSE;
1020 __bt_service_get_parameters(in_param1,
1021 &address, sizeof(bluetooth_device_address_t));
1022 __bt_service_get_parameters(in_param2,
1023 &service_type, sizeof(int));
1025 #if defined(TIZEN_FEATURE_BT_PAN_NAP)
1026 if ((service_type == BLUETOOTH_NAP_SERVICE) || (service_type == BLUETOOTH_NAP_SERVER_SERVICE))
1027 connected = _bt_is_nap_panu_device_connected(&address, service_type);
1029 connected = _bt_is_device_connected(&address, service_type);
1031 connected = _bt_is_device_connected(&address, service_type);
1033 BT_INFO("is_connected: %d", connected);
1034 g_array_append_vals(*out_param1, &connected, sizeof(gboolean));
1037 case BT_GET_CONNECTED_LINK_TYPE: {
1038 bluetooth_device_address_t address = { {0} };
1040 __bt_service_get_parameters(in_param1,
1041 &address, sizeof(bluetooth_device_address_t));
1043 result = _bt_get_connected_link(&address);
1044 if (result == BLUETOOTH_ERROR_NONE) {
1045 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
1047 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
1051 _bt_convert_addr_type_to_string(addr, address.addr);
1052 sender = (char*)g_dbus_method_invocation_get_sender(context);
1053 _bt_save_invocation_context(context, result, sender,
1054 function_name, addr);
1058 case BT_IS_SCAN_FILTER_SUPPORTED:{
1059 int is_supported = 0;
1061 if (_bt_is_scan_filter_supported() == TRUE)
1064 g_array_append_vals(*out_param1,
1065 &is_supported, sizeof(int));
1069 case BT_ENABLE_RSSI: {
1070 bluetooth_device_address_t bd_addr;
1072 bt_rssi_threshold_t rssi_threshold;
1074 int in_range_threshold;
1077 BT_DBG("Enable RSSI");
1079 __bt_service_get_parameters(in_param1,
1080 &bd_addr, sizeof(bluetooth_device_address_t));
1081 __bt_service_get_parameters(in_param2,
1082 &link_type, sizeof(int));
1083 __bt_service_get_parameters(in_param3,
1084 &rssi_threshold, sizeof(bt_rssi_threshold_t));
1086 low_threshold = rssi_threshold.low_threshold;
1087 in_range_threshold = rssi_threshold.in_range_threshold;
1088 high_threshold = rssi_threshold.high_threshold;
1090 result = _bt_enable_rssi(&bd_addr, link_type, low_threshold,
1091 in_range_threshold, high_threshold);
1096 bluetooth_device_address_t bd_addr;
1098 BT_DBG("Get RSSI Strength");
1100 __bt_service_get_parameters(in_param1,
1101 &bd_addr, sizeof(bluetooth_device_address_t));
1102 __bt_service_get_parameters(in_param2,
1103 &link_type, sizeof(int));
1105 result = _bt_get_rssi_strength(&bd_addr, link_type);
1108 case BT_SET_PROFILE_TRUSTED: {
1109 bluetooth_device_address_t bd_addr = { {0} };
1113 __bt_service_get_parameters(in_param1, &bd_addr,
1114 sizeof(bluetooth_device_address_t));
1115 __bt_service_get_parameters(in_param2, &profile, sizeof(int));
1116 __bt_service_get_parameters(in_param3, &trust, sizeof(int));
1118 result = _bt_set_trust_profile(&bd_addr, profile, trust);
1121 case BT_GET_PROFILE_TRUSTED: {
1122 bluetooth_device_address_t bd_addr = { {0} };
1124 guint trusted_profile = 0;
1126 __bt_service_get_parameters(in_param1, &bd_addr,
1127 sizeof(bluetooth_device_address_t));
1128 __bt_service_get_parameters(in_param2, &profile, sizeof(int));
1130 result = _bt_get_trust_profile(&bd_addr, profile, &trusted_profile);
1131 BT_DBG("TRUST %d", trusted_profile);
1132 if (result == BLUETOOTH_ERROR_NONE) {
1133 g_array_append_vals(*out_param1, &trusted_profile,
1139 case BT_HID_CONNECT: {
1140 bluetooth_device_address_t address = { {0} };
1142 __bt_service_get_parameters(in_param1,
1143 &address, sizeof(bluetooth_device_address_t));
1145 result = _bt_hid_connect(&address);
1146 if (result != BLUETOOTH_ERROR_NONE) {
1147 g_array_append_vals(*out_param1, &address,
1148 sizeof(bluetooth_device_address_t));
1150 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1151 _bt_convert_addr_type_to_string(addr, address.addr);
1152 sender = (char*)g_dbus_method_invocation_get_sender(context);
1153 _bt_save_invocation_context(context, result, sender,
1154 function_name, (gpointer)addr);
1158 case BT_HID_DISCONNECT: {
1159 bluetooth_device_address_t address = { {0} };
1161 __bt_service_get_parameters(in_param1,
1162 &address, sizeof(bluetooth_device_address_t));
1164 result = _bt_hid_disconnect(&address);
1165 if (result != BLUETOOTH_ERROR_NONE) {
1166 g_array_append_vals(*out_param1, &address,
1167 sizeof(bluetooth_device_address_t));
1169 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1170 _bt_convert_addr_type_to_string(addr, address.addr);
1171 sender = (char*)g_dbus_method_invocation_get_sender(context);
1172 _bt_save_invocation_context(context, result, sender,
1173 function_name, (gpointer)addr);
1177 case BT_DPM_SET_ALLOW_BT_MODE: {
1178 dpm_bt_allow_t value = DPM_BT_ERROR;
1180 __bt_service_get_parameters(in_param1, &value,
1183 result = _bt_dpm_set_allow_bluetooth_mode(value);
1186 case BT_DPM_GET_ALLOW_BT_MODE: {
1187 int value = DPM_BT_ERROR;
1189 result = _bt_dpm_get_allow_bluetooth_mode(&value);
1190 g_array_append_vals(*out_param1, &value, sizeof(int));
1193 case BT_DPM_SET_DEVICE_RESTRITION: {
1194 dpm_status_t value = DPM_STATUS_ERROR;
1196 __bt_service_get_parameters(in_param1, &value,
1199 result = _bt_dpm_activate_bluetooth_device_restriction(value);
1202 case BT_DPM_GET_DEVICE_RESTRITION: {
1203 int value = DPM_STATUS_ERROR;
1205 result = _bt_dpm_is_bluetooth_device_restriction_active(&value);
1206 g_array_append_vals(*out_param1, &value, sizeof(int));
1209 case BT_DPM_SET_UUID_RESTRITION: {
1210 dpm_status_t value = DPM_STATUS_ERROR;
1212 __bt_service_get_parameters(in_param1, &value,
1215 result = _bt_dpm_activate_bluetoooth_uuid_restriction(value);
1218 case BT_DPM_GET_UUID_RESTRITION: {
1219 int value = DPM_STATUS_ERROR;
1221 result = _bt_dpm_is_bluetooth_uuid_restriction_active(&value);
1222 g_array_append_vals(*out_param1, &value, sizeof(int));
1225 case BT_DPM_ADD_DEVICES_BLOCKLIST: {
1226 bluetooth_device_address_t address = { {0} };
1228 __bt_service_get_parameters(in_param1, &address,
1229 sizeof(bluetooth_device_address_t));
1231 result = _bt_dpm_add_bluetooth_devices_to_blocklist(&address);
1234 case BT_DPM_ADD_DEVICES_ALLOWLIST: {
1235 bluetooth_device_address_t address = { {0} };
1237 __bt_service_get_parameters(in_param1, &address,
1238 sizeof(bluetooth_device_address_t));
1240 result = _bt_dpm_add_bluetooth_devices_to_allowlist(&address);
1243 case BT_DPM_ADD_UUIDS_BLOCKLIST: {
1244 const char *uuid = NULL;
1246 uuid = g_variant_get_data(in_param1);
1248 result = _bt_dpm_add_bluetooth_uuids_to_blocklist(uuid);
1251 case BT_DPM_ADD_UUIDS_ALLOWLIST: {
1252 const char *uuid = NULL;
1254 uuid = g_variant_get_data(in_param1);
1256 result = _bt_dpm_add_bluetooth_uuids_to_allowlist(uuid);
1259 case BT_DPM_CLEAR_DEVICES_BLOCKLIST: {
1260 result = _bt_dpm_clear_bluetooth_devices_from_blocklist();
1263 case BT_DPM_CLEAR_DEVICES_ALLOWLIST: {
1264 result = _bt_dpm_clear_bluetooth_devices_from_allowlist();
1267 case BT_DPM_CLEAR_UUIDS_BLOCKLIST: {
1268 result = _bt_dpm_clear_bluetooth_uuids_from_blocklist();
1271 case BT_DPM_CLEAR_UUIDS_ALLOWLIST: {
1272 result = _bt_dpm_clear_bluetooth_uuids_from_allowlist();
1275 case BT_DPM_REMOVE_DEVICE_BLOCKLIST: {
1276 bluetooth_device_address_t address = { {0} };
1278 __bt_service_get_parameters(in_param1, &address,
1279 sizeof(bluetooth_device_address_t));
1281 result = _bt_dpm_remove_bluetooth_devices_from_blocklist(&address);
1284 case BT_DPM_REMOVE_DEVICE_ALLOWLIST: {
1285 bluetooth_device_address_t address = { {0} };
1287 __bt_service_get_parameters(in_param1, &address,
1288 sizeof(bluetooth_device_address_t));
1290 result = _bt_dpm_remove_bluetooth_devices_from_allowlist(&address);
1293 case BT_DPM_REMOVE_UUID_BLOCKLIST: {
1294 const char *uuid = NULL;
1296 uuid = g_variant_get_data(in_param1);
1298 result = _bt_dpm_remove_bluetooth_uuids_from_blocklist(uuid);
1301 case BT_DPM_REMOVE_UUID_ALLOWLIST: {
1302 const char *uuid = NULL;
1304 uuid = g_variant_get_data(in_param1);
1306 result = _bt_dpm_remove_bluetooth_uuids_from_allowlist(uuid);
1310 case BT_DPM_GET_DEVICES_BLOCKLIST: {
1311 result = _bt_dpm_get_bluetooth_devices_from_blocklist(out_param1);
1314 case BT_DPM_GET_DEVICES_ALLOWLIST: {
1315 result = _bt_dpm_get_bluetooth_devices_from_allowlist(out_param1);
1319 case BT_DPM_GET_UUIDS_BLOCKLIST: {
1320 result = _bt_dpm_get_bluetooth_uuids_from_blocklist(out_param1);
1323 case BT_DPM_GET_UUIDS_ALLOWLIST: {
1324 result = _bt_dpm_get_bluetooth_uuids_from_allowlist(out_param1);
1327 case BT_DPM_SET_ALLOW_OUTGOING_CALL: {
1328 dpm_status_t value = DPM_STATUS_ERROR;
1330 __bt_service_get_parameters(in_param1, &value,
1333 result = _bt_dpm_set_allow_bluetooth_outgoing_call(value);
1337 case BT_DPM_GET_ALLOW_OUTGOING_CALL: {
1338 int value = DPM_STATUS_ERROR;
1340 result = _bt_dpm_get_allow_bluetooth_outgoing_call(&value);
1341 g_array_append_vals(*out_param1, &value, sizeof(int));
1344 case BT_DPM_SET_PAIRING_STATE: {
1345 dpm_status_t value = DPM_STATUS_ERROR;
1347 __bt_service_get_parameters(in_param1, &value,
1350 result = _bt_dpm_set_bluetooth_pairing_state(value);
1354 case BT_DPM_GET_PAIRING_STATE: {
1355 int value = DPM_STATUS_ERROR;
1357 result = _bt_dpm_get_bluetooth_pairing_state(&value);
1358 g_array_append_vals(*out_param1, &value, sizeof(int));
1361 case BT_DPM_SET_PROFILE_STATE: {
1362 int value = DPM_STATUS_ERROR;
1363 int profile = DPM_PROFILE_NONE;
1365 __bt_service_get_parameters(in_param1, &profile,
1367 __bt_service_get_parameters(in_param2, &value,
1370 result = _bt_dpm_set_bluetooth_profile_state(profile, value);
1374 case BT_DPM_GET_PROFILE_STATE: {
1375 int value = DPM_STATUS_ERROR;
1376 int profile = DPM_PROFILE_NONE;
1378 __bt_service_get_parameters(in_param1, &profile,
1381 result = _bt_dpm_get_bluetooth_profile_state(profile, &value);
1382 g_array_append_vals(*out_param1, &value, sizeof(int));
1385 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE: {
1386 int value = DPM_BT_ERROR;
1388 __bt_service_get_parameters(in_param1, &value,
1391 result = _bt_dpm_set_bluetooth_desktop_connectivity_state(value);
1395 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE: {
1396 int value = DPM_STATUS_ERROR;
1398 result = _bt_dpm_get_bluetooth_desktop_connectivity_state(&value);
1399 g_array_append_vals(*out_param1, &value, sizeof(int));
1402 case BT_DPM_SET_DISCOVERABLE_STATE: {
1403 int value = DPM_STATUS_ERROR;
1405 __bt_service_get_parameters(in_param1, &value,
1408 result = _bt_dpm_set_bluetooth_discoverable_state(value);
1412 case BT_DPM_GET_DISCOVERABLE_STATE: {
1413 int value = DPM_STATUS_ERROR;
1415 result = _bt_dpm_get_bluetooth_discoverable_state(&value);
1416 g_array_append_vals(*out_param1, &value, sizeof(int));
1419 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE: {
1420 int value = DPM_STATUS_ERROR;
1422 __bt_service_get_parameters(in_param1, &value,
1425 result = _bt_dpm_set_bluetooth_limited_discoverable_state(value);
1429 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE: {
1430 int value = DPM_STATUS_ERROR;
1432 result = _bt_dpm_get_bluetooth_limited_discoverable_state(&value);
1433 g_array_append_vals(*out_param1, &value, sizeof(int));
1436 case BT_DPM_SET_DATA_TRANSFER_STATE: {
1437 int value = DPM_STATUS_ERROR;
1439 __bt_service_get_parameters(in_param1, &value,
1442 result = _bt_dpm_set_bluetooth_data_transfer_state(value);
1446 case BT_DPM_GET_DATA_TRANSFER_STATE: {
1447 int value = DPM_STATUS_ERROR;
1449 result = _bt_dpm_get_allow_bluetooth_data_transfer_state(&value);
1450 g_array_append_vals(*out_param1, &value, sizeof(int));
1453 case BT_RFCOMM_CLIENT_CONNECT: {
1454 bluetooth_device_address_t address = { {0} };
1458 __bt_service_get_parameters(in_param1,
1459 &address, sizeof(bluetooth_device_address_t));
1460 input_string = (char *)g_variant_get_data(in_param2);
1461 __bt_service_get_parameters(in_param3, &connect_type, sizeof(int));
1463 if (connect_type == BT_RFCOMM_UUID)
1464 result = _bt_rfcomm_connect_using_uuid(&address, input_string);
1466 result = _bt_rfcomm_connect_using_channel(&address, input_string);
1468 if (result != BLUETOOTH_ERROR_NONE) {
1469 bluetooth_rfcomm_connection_t conn_info;
1471 BT_ERR("BT_RFCOMM_CLIENT_CONNECT failed, send error");
1472 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
1473 if (connect_type == BT_RFCOMM_UUID)
1474 g_strlcpy(conn_info.uuid, input_string, BLUETOOTH_UUID_STRING_MAX);
1476 g_strlcpy(conn_info.uuid, "not_used", BLUETOOTH_UUID_STRING_MAX);
1478 conn_info.device_role = RFCOMM_ROLE_CLIENT;
1479 conn_info.socket_fd = -1;
1480 memcpy(&conn_info.device_addr, &address, sizeof(bluetooth_device_address_t));
1481 g_array_append_vals(*out_param1, &conn_info,
1482 sizeof(bluetooth_rfcomm_connection_t));
1484 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1485 _bt_convert_addr_type_to_string(addr, address.addr);
1486 sender = (char*)g_dbus_method_invocation_get_sender(context);
1487 _bt_save_invocation_context(context, result, sender, function_name, addr);
1491 case BT_RFCOMM_SOCKET_DISCONNECT: {
1493 * Bluetooth RFCOMM socket disconnection will be done from bt-api, call to bt-service
1494 * is only used for privilege check, so return BLUETOOTH_ERROR_NONE from here.
1496 result = BLUETOOTH_ERROR_NONE;
1499 case BT_RFCOMM_SOCKET_WRITE: {
1501 * This call to bt-service is only used for privilege check, so return
1502 * BLUETOOTH_ERROR_NONE from here.
1504 result = BLUETOOTH_ERROR_NONE;
1507 case BT_RFCOMM_CREATE_SOCKET: {
1509 * This call to bt-service is only used for privilege check, so return
1510 * BLUETOOTH_ERROR_NONE from here.
1512 result = BLUETOOTH_ERROR_NONE;
1515 case BT_RFCOMM_LISTEN_AND_ACCEPT: {
1519 sender = (char *)g_dbus_method_invocation_get_sender(context);
1520 uuid = (char *)g_variant_get_data(in_param1);
1522 result = _bt_rfcomm_socket_listen(sender, uuid, true);
1524 result = BLUETOOTH_ERROR_NONE;
1525 _bt_save_invocation_context(context,
1526 result, sender, function_name, NULL);
1528 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1532 case BT_RFCOMM_LISTEN: {
1536 sender = (char *)g_dbus_method_invocation_get_sender(context);
1537 uuid = (char *)g_variant_get_data(in_param1);
1539 result = _bt_rfcomm_socket_listen(sender, uuid, false);
1541 result = BLUETOOTH_ERROR_NONE;
1542 _bt_save_invocation_context(context,
1543 result, sender, function_name, NULL);
1545 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1549 case BT_RFCOMM_ACCEPT_CONNECTION: {
1552 address = (char *)g_variant_get_data(in_param1);
1553 result = _bt_socket_reply_conn_authorization(address, TRUE);
1556 case BT_RFCOMM_REJECT_CONNECTION: {
1559 address = (char *)g_variant_get_data(in_param1);
1560 result = _bt_socket_reply_conn_authorization(address, FALSE);
1563 case BT_RFCOMM_REMOVE_SOCKET: {
1565 * This call to bt-service is only used for privilege check, so return
1566 * BLUETOOTH_ERROR_NONE from here.
1568 result = BLUETOOTH_ERROR_NONE;
1571 case BT_RFCOMM_SEND_RX_DETAILS: {
1575 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
1576 __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t));
1577 __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int));
1578 _bt_bm_add_transaction_details(uid, pid, size, RX_DATA);
1581 case BT_RFCOMM_SEND_TX_DETAILS: {
1585 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
1586 __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t));
1587 __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int));
1588 _bt_bm_add_transaction_details(uid, pid, size, TX_DATA);
1591 case BT_RFCOMM_UPDATE_CONNECTION_INFO: {
1592 gboolean connected = FALSE;
1594 int role = RFCOMM_ROLE_SERVER;
1596 sender = (char *)g_dbus_method_invocation_get_sender(context);
1598 __bt_service_get_parameters(in_param1, &role, sizeof(int));
1599 __bt_service_get_parameters(in_param2, &connected, sizeof(gboolean));
1600 __bt_service_get_parameters(in_param3, &socket_fd, sizeof(int));
1602 if (connected == TRUE)
1603 result = _bt_rfcomm_conn_added(sender, role, socket_fd);
1605 result = _bt_rfcomm_conn_removed(sender, role, socket_fd);
1609 case BT_AUDIO_SELECT_ROLE: {
1610 bluetooth_audio_role_t role;
1612 __bt_service_get_parameters(in_param1,
1613 &role, sizeof(bluetooth_audio_role_t));
1615 result = _bt_audio_select_role(role);
1616 if (result == BLUETOOTH_ERROR_NONE) {
1617 sender = (char*)g_dbus_method_invocation_get_sender(context);
1618 _bt_save_invocation_context(context, result, sender,
1619 function_name, NULL);
1623 case BT_AUDIO_SET_ABSOLUTE_VOLUME: {
1624 unsigned int volume = 0;
1626 __bt_service_get_parameters(in_param1,
1627 &volume, sizeof(unsigned int));
1629 result = _bt_audio_set_absolute_volume(volume);
1632 case BT_AUDIO_GET_ABSOLUTE_VOLUME: {
1633 unsigned int volume = 0;
1635 result = _bt_audio_get_absolute_volume(&volume);
1636 g_array_append_vals(*out_param1, &volume, sizeof(unsigned int));
1639 case BT_AUDIO_IS_AVC_ACTIVATED: {
1642 result = _bt_audio_is_avc_activated(&activated);
1643 g_array_append_vals(*out_param1, &activated, sizeof(bool));
1646 case BT_AV_CONNECT: {
1647 bluetooth_device_address_t address = { {0} };
1648 __bt_service_get_parameters(in_param1,
1649 &address, sizeof(bluetooth_device_address_t));
1651 result = _bt_audio_is_profile_connection_in_progress(BT_AV_CONNECT, &address);
1653 if (result == BLUETOOTH_ERROR_NONE)
1654 result = _bt_audio_connect(BT_AUDIO_A2DP, &address);
1656 if (result != BLUETOOTH_ERROR_NONE) {
1657 BT_ERR("AV Connect Request has failed to execute");
1658 char addr[BT_ADDRESS_STRING_SIZE];
1659 _bt_convert_addr_type_to_string(addr, address.addr);
1660 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1662 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1663 _bt_convert_addr_type_to_string(addr, address.addr);
1664 sender = (char*)g_dbus_method_invocation_get_sender(context);
1665 _bt_save_invocation_context(context, result, sender,
1666 function_name, (gpointer)addr);
1670 case BT_AUDIO_CONNECT: {
1671 bluetooth_device_address_t address = { {0} };
1672 __bt_service_get_parameters(in_param1,
1673 &address, sizeof(bluetooth_device_address_t));
1675 result = _bt_audio_is_profile_connection_in_progress(BT_AUDIO_CONNECT, &address);
1677 if (result == BLUETOOTH_ERROR_NONE)
1678 result = _bt_audio_connect(BT_AUDIO_ALL, &address);
1680 if (result != BLUETOOTH_ERROR_NONE) {
1681 BT_ERR("Audio All Connect Request has failed to execute");
1682 char addr[BT_ADDRESS_STRING_SIZE];
1683 _bt_convert_addr_type_to_string(addr, address.addr);
1684 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1686 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1687 _bt_convert_addr_type_to_string(addr, address.addr);
1688 sender = (char*)g_dbus_method_invocation_get_sender(context);
1689 _bt_save_invocation_context(context, result, sender,
1690 function_name, (gpointer)addr);
1694 case BT_AUDIO_DISCONNECT: {
1695 bluetooth_device_address_t address = { {0} };
1696 __bt_service_get_parameters(in_param1,
1697 &address, sizeof(bluetooth_device_address_t));
1699 result = _bt_audio_disconnect(BT_AUDIO_ALL, &address);
1701 if (result != BLUETOOTH_ERROR_NONE) {
1702 char addr[BT_ADDRESS_STRING_SIZE];
1703 _bt_convert_addr_type_to_string(addr, address.addr);
1704 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1706 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1707 _bt_convert_addr_type_to_string(addr, address.addr);
1708 sender = (char*)g_dbus_method_invocation_get_sender(context);
1709 _bt_save_invocation_context(context, result, sender,
1710 function_name, (gpointer)addr);
1714 case BT_AV_DISCONNECT: {
1715 bluetooth_device_address_t address = { {0} };
1716 __bt_service_get_parameters(in_param1,
1717 &address, sizeof(bluetooth_device_address_t));
1719 result = _bt_audio_disconnect(BT_AUDIO_A2DP, &address);
1721 if (result != BLUETOOTH_ERROR_NONE) {
1722 char addr[BT_ADDRESS_STRING_SIZE];
1723 _bt_convert_addr_type_to_string(addr, address.addr);
1724 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1726 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1727 _bt_convert_addr_type_to_string(addr, address.addr);
1728 sender = (char*)g_dbus_method_invocation_get_sender(context);
1729 _bt_save_invocation_context(context, result, sender,
1730 function_name, (gpointer)addr);
1734 case BT_AG_CONNECT: {
1735 bluetooth_device_address_t address = { {0} };
1736 __bt_service_get_parameters(in_param1,
1737 &address, sizeof(bluetooth_device_address_t));
1739 result = _bt_audio_is_profile_connection_in_progress(BT_AG_CONNECT, &address);
1741 if (result == BLUETOOTH_ERROR_NONE)
1742 result = _bt_audio_connect(BT_AUDIO_HSP, &address);
1744 if (result != BLUETOOTH_ERROR_NONE) {
1745 BT_ERR("AG Connect Request has failed to execute");
1746 char addr[BT_ADDRESS_STRING_SIZE];
1747 _bt_convert_addr_type_to_string(addr, address.addr);
1748 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1750 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1751 _bt_convert_addr_type_to_string(addr, address.addr);
1752 sender = (char*)g_dbus_method_invocation_get_sender(context);
1753 _bt_save_invocation_context(context, result, sender,
1754 function_name, (gpointer)addr);
1758 case BT_AG_DISCONNECT: {
1759 bluetooth_device_address_t address = { {0} };
1761 __bt_service_get_parameters(in_param1,
1762 &address, sizeof(bluetooth_device_address_t));
1764 result = _bt_audio_disconnect(BT_AUDIO_HSP, &address);
1766 if (result != BLUETOOTH_ERROR_NONE) {
1767 char addr[BT_ADDRESS_STRING_SIZE];
1768 _bt_convert_addr_type_to_string(addr, address.addr);
1769 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1771 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1772 _bt_convert_addr_type_to_string(addr, address.addr);
1773 sender = (char*)g_dbus_method_invocation_get_sender(context);
1774 _bt_save_invocation_context(context, result, sender,
1775 function_name, (gpointer)addr);
1779 case BT_AV_SOURCE_CONNECT: {
1780 bluetooth_device_address_t address = { {0} };
1782 __bt_service_get_parameters(in_param1,
1783 &address, sizeof(bluetooth_device_address_t));
1785 result = _bt_audio_is_profile_connection_in_progress(BT_AV_SOURCE_CONNECT,
1788 if (result == BLUETOOTH_ERROR_NONE)
1789 result = _bt_audio_connect(BT_AUDIO_A2DP_SOURCE, &address);
1791 if (result != BLUETOOTH_ERROR_NONE) {
1792 BT_ERR("A2DP Source Connect Request has failed to execute");
1793 char addr[BT_ADDRESS_STRING_SIZE];
1794 _bt_convert_addr_type_to_string(addr, address.addr);
1795 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1797 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1798 _bt_convert_addr_type_to_string(addr, address.addr);
1799 sender = (char*)g_dbus_method_invocation_get_sender(context);
1800 _bt_save_invocation_context(context, result, sender,
1801 function_name, (gpointer)addr);
1805 case BT_AV_SOURCE_DISCONNECT: {
1806 bluetooth_device_address_t address = { {0} };
1808 __bt_service_get_parameters(in_param1,
1809 &address, sizeof(bluetooth_device_address_t));
1811 result = _bt_audio_disconnect(BT_AUDIO_A2DP_SOURCE, &address);
1812 if (result != BLUETOOTH_ERROR_NONE) {
1813 char addr[BT_ADDRESS_STRING_SIZE];
1814 _bt_convert_addr_type_to_string(addr, address.addr);
1815 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1817 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1818 _bt_convert_addr_type_to_string(addr, address.addr);
1819 sender = (char*)g_dbus_method_invocation_get_sender(context);
1820 _bt_save_invocation_context(context, result, sender,
1821 function_name, (gpointer)addr);
1825 case BT_HF_CONNECT: {
1826 bluetooth_device_address_t address = { {0} };
1828 __bt_service_get_parameters(in_param1,
1829 &address, sizeof(bluetooth_device_address_t));
1831 result = _bt_audio_is_profile_connection_in_progress(BT_HF_CONNECT,
1834 if (result == BLUETOOTH_ERROR_NONE)
1835 result = _bt_hf_connect(&address);
1837 if (result != BLUETOOTH_ERROR_NONE) {
1838 BT_ERR("HF Connect Request has failed to execute");
1839 char addr[BT_ADDRESS_STRING_SIZE];
1840 _bt_convert_addr_type_to_string(addr, address.addr);
1841 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1843 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1844 _bt_convert_addr_type_to_string(addr, address.addr);
1845 sender = (char*)g_dbus_method_invocation_get_sender(context);
1846 _bt_save_invocation_context(context, result, sender,
1847 function_name, (gpointer)addr);
1851 case BT_HF_DISCONNECT: {
1852 bluetooth_device_address_t address = { {0} };
1854 __bt_service_get_parameters(in_param1,
1855 &address, sizeof(bluetooth_device_address_t));
1857 result = _bt_hf_disconnect(&address);
1858 if (result != BLUETOOTH_ERROR_NONE) {
1859 char addr[BT_ADDRESS_STRING_SIZE];
1860 _bt_convert_addr_type_to_string(addr, address.addr);
1861 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1863 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1864 _bt_convert_addr_type_to_string(addr, address.addr);
1865 sender = (char*)g_dbus_method_invocation_get_sender(context);
1866 _bt_save_invocation_context(context, result, sender,
1867 function_name, (gpointer)addr);
1871 case BT_AVRCP_TARGET_CONNECT: {
1872 bluetooth_device_address_t address = { {0} };
1874 __bt_service_get_parameters(in_param1,
1875 &address, sizeof(bluetooth_device_address_t));
1877 result = _bt_audio_is_profile_connection_in_progress(BT_AVRCP_TARGET_CONNECT,
1880 if (result == BLUETOOTH_ERROR_NONE)
1881 result = _bt_audio_connect(BT_AVRCP_TARGET, &address);
1883 if (result != BLUETOOTH_ERROR_NONE) {
1884 BT_ERR("AVRCP Target Connect Request has failed to execute");
1885 char addr[BT_ADDRESS_STRING_SIZE];
1886 _bt_convert_addr_type_to_string(addr, address.addr);
1887 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1889 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1890 _bt_convert_addr_type_to_string(addr, address.addr);
1891 sender = (char*)g_dbus_method_invocation_get_sender(context);
1892 _bt_save_invocation_context(context, result, sender,
1893 function_name, (gpointer)addr);
1897 case BT_AVRCP_TARGET_DISCONNECT: {
1898 bluetooth_device_address_t address = { {0} };
1900 __bt_service_get_parameters(in_param1,
1901 &address, sizeof(bluetooth_device_address_t));
1903 result = _bt_audio_disconnect(BT_AVRCP_TARGET, &address);
1904 if (result != BLUETOOTH_ERROR_NONE) {
1905 char addr[BT_ADDRESS_STRING_SIZE];
1906 _bt_convert_addr_type_to_string(addr, address.addr);
1907 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1909 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1910 _bt_convert_addr_type_to_string(addr, address.addr);
1911 sender = (char*)g_dbus_method_invocation_get_sender(context);
1912 _bt_save_invocation_context(context, result, sender,
1913 function_name, (gpointer)addr);
1917 case BT_AVRCP_CONTROL_CONNECT: {
1918 bluetooth_device_address_t address = { {0} };
1920 __bt_service_get_parameters(in_param1,
1921 &address, sizeof(bluetooth_device_address_t));
1923 result = _bt_audio_is_profile_connection_in_progress(BT_AVRCP_CONTROL_CONNECT,
1926 if (result == BLUETOOTH_ERROR_NONE)
1927 result = _bt_audio_connect(BT_AVRCP, &address);
1929 if (result != BLUETOOTH_ERROR_NONE) {
1930 BT_ERR("AVRCP Control Connect Request has failed to execute");
1931 char addr[BT_ADDRESS_STRING_SIZE];
1932 _bt_convert_addr_type_to_string(addr, address.addr);
1933 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1935 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1936 _bt_convert_addr_type_to_string(addr, address.addr);
1937 sender = (char*)g_dbus_method_invocation_get_sender(context);
1938 _bt_save_invocation_context(context, result, sender,
1939 function_name, (gpointer)addr);
1943 case BT_AVRCP_CONTROL_DISCONNECT: {
1944 bluetooth_device_address_t address = { {0} };
1946 __bt_service_get_parameters(in_param1,
1947 &address, sizeof(bluetooth_device_address_t));
1949 result = _bt_audio_disconnect(BT_AVRCP, &address);
1950 if (result != BLUETOOTH_ERROR_NONE) {
1951 char addr[BT_ADDRESS_STRING_SIZE];
1952 _bt_convert_addr_type_to_string(addr, address.addr);
1953 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1955 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1956 _bt_convert_addr_type_to_string(addr, address.addr);
1957 sender = (char*)g_dbus_method_invocation_get_sender(context);
1958 _bt_save_invocation_context(context, result, sender,
1959 function_name, (gpointer)addr);
1963 case BT_AVRCP_HANDLE_CONTROL: {
1965 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1966 result = _bt_avrcp_control_cmd(key_code);
1969 case BT_AVRCP_HANDLE_CONTROL_TO_DEST: {
1971 bluetooth_device_address_t address = { { 0 } };
1973 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1974 __bt_service_get_parameters(in_param2,
1975 &address, sizeof(bluetooth_device_address_t));
1977 result = _bt_avrcp_control_cmd_to_dest(key_code, &address);
1980 case BT_AVRCP_CONTROL_SET_PROPERTY: {
1984 __bt_service_get_parameters(in_param1,
1985 &type, sizeof(int));
1986 __bt_service_get_parameters(in_param2,
1987 &value, sizeof(unsigned int));
1989 result = _bt_avrcp_control_set_property(type, value);
1992 case BT_AVRCP_TRANSPORT_SET_PROPERTY: {
1997 __bt_service_get_parameters(in_param1,
1998 &type, sizeof(int));
1999 __bt_service_get_parameters(in_param2,
2000 &value, sizeof(unsigned int));
2002 result = _bt_avrcp_transport_set_property(type, value);
2006 case BT_AVRCP_CONTROL_GET_PROPERTY: {
2009 __bt_service_get_parameters(in_param1, &type, sizeof(int));
2011 result = _bt_avrcp_control_get_property(type);
2012 /* Save invocation */
2013 if (result == BLUETOOTH_ERROR_NONE) {
2014 sender = (char*)g_dbus_method_invocation_get_sender(context);
2015 _bt_save_invocation_context(context, result, sender,
2016 function_name, g_memdup2(&type, sizeof(int)));
2020 case BT_AVRCP_GET_TRACK_INFO: {
2021 result = _bt_avrcp_control_get_track_info();
2022 /* Save invocation */
2023 if (result == BLUETOOTH_ERROR_NONE) {
2024 sender = (char*)g_dbus_method_invocation_get_sender(context);
2025 _bt_save_invocation_context(context, result, sender,
2026 function_name, NULL);
2030 case BT_HDP_REGISTER_SINK_APP: {
2031 unsigned short data_type;
2032 bt_hdp_role_type_t role;
2033 bt_hdp_qos_type_t channel_type;
2034 int *app_id = g_new0(int, 1);
2036 __bt_service_get_parameters(in_param1,
2037 &data_type, sizeof(short));
2038 __bt_service_get_parameters(in_param2,
2039 &role, sizeof(bt_hdp_role_type_t));
2040 __bt_service_get_parameters(in_param3,
2041 &channel_type, sizeof(bt_hdp_qos_type_t));
2042 sender = (char*)g_dbus_method_invocation_get_sender(context);
2044 result = _bt_hdp_app_register(role,
2045 channel_type, data_type, sender, app_id);
2046 if (result != BLUETOOTH_ERROR_NONE) {
2047 g_array_append_vals(*out_param1, &app_id, sizeof(app_id));
2050 _bt_save_invocation_context(context, result, sender,
2051 function_name, (gpointer)app_id);
2055 case BT_HDP_UNREGISTER_SINK_APP: {
2057 int *app_id = g_new0(int, 1);
2059 app_handle = (char *)g_variant_get_data(in_param1);
2060 sscanf(app_handle, "health_app_%d", app_id);
2061 result = _bt_hdp_app_unregister(*app_id);
2062 if (result != BLUETOOTH_ERROR_NONE) {
2065 sender = (char*)g_dbus_method_invocation_get_sender(context);
2066 _bt_save_invocation_context(context, result, sender,
2067 function_name, (gpointer)app_id);
2071 case BT_HDP_CONNECT: {
2075 bt_hdp_connected_t *conn_info = NULL;
2077 conn_info = g_malloc0(sizeof(bt_hdp_connected_t));
2079 app_handle = (char *)g_variant_get_data(in_param1);
2080 conn_info->app_handle = app_handle;
2081 sscanf(app_handle, "health_app_%d", &app_id);
2083 __bt_service_get_parameters(in_param2,
2084 &(conn_info->type), sizeof(bt_hdp_qos_type_t));
2085 __bt_service_get_parameters(in_param3,
2086 &(conn_info->device_address),
2087 sizeof(bluetooth_device_address_t));
2089 result = _bt_hdp_connect(app_id, &(conn_info->device_address),
2090 conn_info->type, (int *)(&(conn_info->channel_id)));
2091 if (result != BLUETOOTH_ERROR_NONE) {
2092 g_array_append_vals(*out_param1, conn_info,
2093 sizeof(bt_hdp_connected_t));
2096 sender = (char*)g_dbus_method_invocation_get_sender(context);
2097 _bt_save_invocation_context(context, result, sender,
2098 function_name, (gpointer)conn_info);
2102 case BT_HDP_DISCONNECT: {
2103 bt_hdp_disconnected_t *hdp_disconn_info = NULL;
2105 hdp_disconn_info = g_malloc0(sizeof(bt_hdp_disconnected_t));
2107 __bt_service_get_parameters(in_param1,
2108 &(hdp_disconn_info->channel_id), sizeof(int));
2109 __bt_service_get_parameters(in_param2,
2110 &(hdp_disconn_info->device_address),
2111 sizeof(bluetooth_device_address_t));
2113 result = _bt_hdp_disconnect(hdp_disconn_info->channel_id);
2114 if (result != BLUETOOTH_ERROR_NONE) {
2115 g_array_append_vals(*out_param1, hdp_disconn_info,
2116 sizeof(bt_hdp_disconnected_t));
2117 g_free(hdp_disconn_info);
2119 sender = (char*)g_dbus_method_invocation_get_sender(context);
2120 _bt_save_invocation_context(context, result, sender,
2121 function_name, (gpointer)hdp_disconn_info);
2125 case BT_HDP_GET_FD: {
2126 int *channel_id = g_new0(int, 1);
2128 __bt_service_get_parameters(in_param1, channel_id, sizeof(int));
2130 result = _bt_hdp_get_fd(*channel_id);
2131 if (result != BLUETOOTH_ERROR_NONE) {
2134 sender = (char*)g_dbus_method_invocation_get_sender(context);
2135 _bt_save_invocation_context(context, result, sender,
2136 function_name, (gpointer)channel_id);
2140 case BT_HDP_SEND_DATA: {
2142 * This call to bt-service is only used for privilege check, so return
2143 * BLUETOOTH_ERROR_NONE from here.
2145 result = BLUETOOTH_ERROR_NONE;
2148 case BT_OOB_READ_LOCAL_DATA: { //208
2149 bt_oob_data_t local_oob_data;
2151 memset(&local_oob_data, 0x00, sizeof(bt_oob_data_t));
2152 result = _bt_oob_read_local_data(&local_oob_data);
2154 g_array_append_vals(*out_param1, &local_oob_data,
2155 sizeof(bt_oob_data_t));
2159 case BT_OOB_ADD_REMOTE_DATA: { //209
2160 bluetooth_device_address_t address = { {0} };
2161 unsigned short address_type;
2162 bt_oob_data_t remote_oob_data;
2164 __bt_service_get_parameters(in_param1,
2165 &address, sizeof(bluetooth_device_address_t));
2166 __bt_service_get_parameters(in_param2,
2167 &address_type, sizeof(unsigned short));
2168 __bt_service_get_parameters(in_param3,
2169 &remote_oob_data, sizeof(bt_oob_data_t));
2171 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2175 case BT_OOB_REMOVE_REMOTE_DATA: { //210
2176 bluetooth_device_address_t address = { {0} };
2178 __bt_service_get_parameters(in_param1,
2179 &address, sizeof(bluetooth_device_address_t));
2181 result = _bt_oob_remove_remote_data(&address);
2185 case BT_LE_OOB_READ_LOCAL_DATA: {
2186 bt_oob_data_t local_oob_data;
2187 bt_oob_data_t *local_oob_cache_data;
2189 local_oob_cache_data = _bt_le_oob_get_local_cache_data();
2190 if (local_oob_cache_data && local_oob_cache_data->eir_len) {
2191 g_array_append_vals(*out_param1, local_oob_cache_data,
2192 sizeof(bt_oob_data_t));
2193 return BLUETOOTH_ERROR_NONE;
2196 /* We should modify this logic in later */
2197 if (_bt_is_le_static_random_address_enabled() == false) {
2198 /* Seperate BT & LE address */
2199 _bt_set_le_static_random_address(TRUE);
2202 result = _bt_le_oob_read_local_data(&local_oob_data);
2203 _bt_le_oob_set_local_cache_data(&local_oob_data);
2205 g_array_append_vals(*out_param1, &local_oob_data,
2206 sizeof(bt_oob_data_t));
2210 case BT_LE_OOB_ADD_REMOTE_DATA: {
2211 bluetooth_device_address_t address = { {0} };
2212 unsigned short address_type;
2213 bt_oob_data_t remote_oob_data;
2215 __bt_service_get_parameters(in_param1,
2216 &address, sizeof(bluetooth_device_address_t));
2217 __bt_service_get_parameters(in_param2,
2218 &address_type, sizeof(unsigned short));
2219 __bt_service_get_parameters(in_param3,
2220 &remote_oob_data, sizeof(bt_oob_data_t));
2222 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2226 case BT_AVRCP_SET_TRACK_INFO: {
2227 media_metadata_t data;
2228 media_metadata_attributes_t meta_data;
2230 memset(&data, 0x00, sizeof(media_metadata_t));
2231 memset(&meta_data, 0x00, sizeof(media_metadata_attributes_t));
2233 __bt_service_get_parameters(in_param1,
2234 &data, sizeof(media_metadata_t));
2236 meta_data.title = g_strdup(data.title);
2237 meta_data.artist = g_strdup(data.artist);
2238 meta_data.album = g_strdup(data.album);
2239 meta_data.genre = g_strdup(data.genre);
2240 meta_data.total_tracks = data.total_tracks;
2241 meta_data.number = data.number;
2242 meta_data.duration = (int64_t) data.duration;
2244 result = _bt_avrcp_set_track_info(&meta_data);
2246 g_free((gpointer)meta_data.title);
2247 g_free((gpointer)meta_data.artist);
2248 g_free((gpointer)meta_data.album);
2249 g_free((gpointer)meta_data.genre);
2253 case BT_AVRCP_SET_PROPERTY: {
2257 sender = (char *)g_dbus_method_invocation_get_sender(context);
2259 __bt_service_get_parameters(in_param1,
2260 &type, sizeof(int));
2261 __bt_service_get_parameters(in_param2,
2262 &value, sizeof(unsigned int));
2264 if (value == STATUS_PLAYING) {
2265 if (current_sender_playing)
2266 g_free(current_sender_playing);
2267 current_sender_playing = g_strdup(sender);
2269 if (g_strcmp0(sender, current_sender_playing) == 0 ||
2270 current_sender_playing == NULL) {
2271 BT_INFO("Current Player Status %d type %d Sender %s", value, type, sender);
2273 BT_INFO("Current Player and this sender (%s) are different", sender);
2274 result = BLUETOOTH_ERROR_NONE;
2277 result = _bt_avrcp_set_property(type, value);
2281 case BT_AVRCP_SET_PROPERTIES: {
2282 media_player_settings_t properties;
2284 memset(&properties, 0x00, sizeof(media_player_settings_t));
2285 __bt_service_get_parameters(in_param1,
2286 &properties, sizeof(media_player_settings_t));
2288 result = _bt_avrcp_set_properties(&properties);
2292 case BT_SET_ADVERTISING_DATA: {
2295 bluetooth_advertising_data_t adv = { {0} };
2297 bluetooth_le_slot_and_adv_type_t rs_at;
2298 rs_at.is_legacy = TRUE;
2299 rs_at.use_reserved_slot = FALSE;
2301 app = (char *)g_dbus_method_invocation_get_sender(context);
2302 adv_handle = g_malloc0(sizeof(int));
2304 __bt_service_get_parameters(in_param1,
2305 adv_handle, sizeof(int));
2306 __bt_service_get_parameters(in_param3,
2307 &length, sizeof(int));
2308 __bt_service_get_parameters(in_param2,
2310 __bt_service_get_parameters(in_param4,
2311 &rs_at, sizeof(bluetooth_le_slot_and_adv_type_t));
2312 result = _bt_set_advertising_data(app, *adv_handle,
2313 &adv, length, &rs_at);
2314 if (result != BLUETOOTH_ERROR_NONE) {
2315 BT_ERR("Set Advertising data failed!!");
2318 _bt_save_invocation_context(context, result, app,
2319 function_name, (gpointer)adv_handle);
2323 case BT_SET_SCAN_RESPONSE_DATA: {
2326 bluetooth_scan_resp_data_t rsp = { {0} };
2328 gboolean use_reserved_slot = FALSE;
2330 app = (char *)g_dbus_method_invocation_get_sender(context);
2331 adv_handle = g_malloc0(sizeof(int));
2333 __bt_service_get_parameters(in_param1,
2334 adv_handle, sizeof(int));
2335 __bt_service_get_parameters(in_param3,
2336 &length, sizeof(int));
2337 __bt_service_get_parameters(in_param2,
2339 __bt_service_get_parameters(in_param4,
2340 &use_reserved_slot, sizeof(gboolean));
2342 result = _bt_set_scan_response_data(app, *adv_handle,
2343 &rsp, length, use_reserved_slot);
2345 if (result != BLUETOOTH_ERROR_NONE) {
2346 BT_ERR("Set Scan Response Data failed!!");
2349 _bt_save_invocation_context(context, result, app,
2350 function_name, (gpointer)adv_handle);
2354 case BT_SET_ADVERTISING: {
2357 gboolean enable = FALSE;
2358 gboolean use_reserved_slot = FALSE;
2360 adv_handle = g_malloc0(sizeof(int));
2361 __bt_service_get_parameters(in_param1,
2362 adv_handle, sizeof(int));
2363 __bt_service_get_parameters(in_param2,
2364 &enable, sizeof(gboolean));
2365 __bt_service_get_parameters(in_param3,
2366 &use_reserved_slot, sizeof(gboolean));
2368 app = (char *)g_dbus_method_invocation_get_sender(context);
2370 result = _bt_set_advertising(app, *adv_handle,
2371 enable, use_reserved_slot);
2372 if (result != BLUETOOTH_ERROR_NONE) {
2373 BT_ERR("Start Advertising failed!!");
2376 _bt_save_invocation_context(context, result, app,
2377 function_name, (gpointer)adv_handle);
2381 case BT_SET_CUSTOM_ADVERTISING: {
2384 gboolean enable = FALSE;
2385 bluetooth_advertising_params_t adv_params;
2386 gboolean use_reserved_slot = FALSE;
2388 app = (char *)g_dbus_method_invocation_get_sender(context);
2389 adv_handle = g_malloc0(sizeof(int));
2391 __bt_service_get_parameters(in_param1, adv_handle,
2393 __bt_service_get_parameters(in_param2, &enable,
2395 __bt_service_get_parameters(in_param3, &adv_params,
2396 sizeof(bluetooth_advertising_params_t));
2397 __bt_service_get_parameters(in_param4, &use_reserved_slot,
2400 BT_DBG("bluetooth_advertising_params_t [%d %d %d %d %d]",
2401 adv_params.interval_min, adv_params.interval_max,
2402 adv_params.filter_policy, adv_params.type, adv_params.tx_power_level);
2403 result = _bt_set_custom_advertising(app, *adv_handle,
2404 enable, &adv_params, use_reserved_slot);
2405 if (result != BLUETOOTH_ERROR_NONE) {
2406 BT_ERR("Start Custom Advertising failed!!");
2409 _bt_save_invocation_context(context, result, app,
2410 function_name, (gpointer)adv_handle);
2414 case BT_GET_SCAN_RESPONSE_DATA: {
2415 bluetooth_scan_resp_data_t rsp = { {0} };
2419 app = (char *)g_dbus_method_invocation_get_sender(context);
2421 __bt_service_get_parameters(in_param1, &adv_handle,
2424 result = _bt_get_scan_response_data(app, adv_handle, &rsp, &length);
2425 if (result == BLUETOOTH_ERROR_NONE)
2426 g_array_append_vals(*out_param1, rsp.data, length);
2430 case BT_GET_ADVERTISING_DATA: {
2431 bluetooth_advertising_data_t adv = { {0} };
2435 app = (char *)g_dbus_method_invocation_get_sender(context);
2437 __bt_service_get_parameters(in_param1, &adv_handle,
2440 result = _bt_get_advertising_data(app, adv_handle, &adv, &length);
2441 if (result == BLUETOOTH_ERROR_NONE)
2442 g_array_append_vals(*out_param1, adv.data, length);
2446 case BT_GATT_REGISTER_APPLICATION: {
2447 BT_DBG("Register GATT application:Unhandled!!");
2450 case BT_GATT_SERVER_REGISTER: {
2451 BT_DBG("GATT Server instance initialization");
2454 app = (char *)g_dbus_method_invocation_get_sender(context);
2455 BT_DBG("GATT Server Unique Name [%s]", app);
2457 /* No ADV handle: Set 0 */
2458 result = _bt_register_server_instance(app, 0);
2460 if (result != BLUETOOTH_ERROR_NONE) {
2461 BT_ERR("GATT Server registration failed. result %d", result);
2463 _bt_save_invocation_context(context, result, app,
2464 function_name, NULL);
2468 case BT_GATT_SERVER_DEREGISTER: {
2470 app = (char*)g_dbus_method_invocation_get_sender(context);
2472 result = _bt_unregister_server_instance(app, 0/* Adv Handle*/);
2475 case BT_GATT_SERVER_ADD_SERVICE: {
2476 BT_DBG("GATT Server Add Service");
2482 int *tmp_inst_id = NULL;
2484 app = (char *)g_dbus_method_invocation_get_sender(context);
2486 __bt_service_get_parameters(in_param1, &service_type,
2488 __bt_service_get_parameters(in_param2, &num_handles,
2490 svc_uuid = (char *)g_variant_get_data(in_param3);
2491 __bt_service_get_parameters(in_param4, &instance_id,
2494 result = _bt_gatt_server_add_service(app, service_type, num_handles, svc_uuid, instance_id);
2495 if (result != BLUETOOTH_ERROR_NONE) {
2496 BT_ERR("GATT Server Add Service failed!!");
2498 tmp_inst_id = g_malloc0(sizeof(int));
2499 *tmp_inst_id = instance_id;
2500 _bt_save_invocation_context(context, result, app,
2501 function_name, (gpointer)tmp_inst_id);
2505 case BT_GATT_SERVER_ADD_CHARACTERISTIC: {
2506 BT_DBG("GATT Server Add Characteristic");
2509 int *tmp_inst_id = NULL;
2510 bluetooth_gatt_server_attribute_params_t param;
2511 memset(¶m, 0, sizeof(bluetooth_gatt_server_attribute_params_t));
2513 app = (char*)g_dbus_method_invocation_get_sender(context);
2515 __bt_service_get_parameters(in_param1, ¶m,
2516 sizeof(bluetooth_gatt_server_attribute_params_t));
2517 char_uuid = (char *)g_variant_get_data(in_param2);
2519 result = _bt_gatt_server_add_characteristic(app, char_uuid, ¶m);
2520 if (result != BLUETOOTH_ERROR_NONE) {
2521 BT_ERR("GATT Server Add Service failed!!");
2523 tmp_inst_id = g_malloc0(sizeof(int));
2524 *tmp_inst_id = param.instance_id;
2526 _bt_save_invocation_context(context, result, app,
2527 function_name, (gpointer)tmp_inst_id);
2531 case BT_GATT_SERVER_ADD_DESCRIPTOR: {
2532 BT_DBG("GATT Server Add Descriptor");
2536 bt_gatt_permission_t perm;
2538 int *tmp_inst_id = NULL;
2539 memset(&perm, 0, sizeof(bt_gatt_permission_t));
2541 app = (char *)g_dbus_method_invocation_get_sender(context);
2543 __bt_service_get_parameters(in_param1, &service_handle,
2545 __bt_service_get_parameters(in_param2, &instance_id,
2547 desc_uuid = (char *)g_variant_get_data(in_param4);
2548 __bt_service_get_parameters(in_param3, &perm,
2549 sizeof(bt_gatt_permission_t));
2551 result = _bt_gatt_server_add_descriptor(app, desc_uuid, &perm, service_handle, instance_id);
2552 if (result != BLUETOOTH_ERROR_NONE) {
2553 BT_ERR("GATT Server Add Service failed!!");
2555 tmp_inst_id = g_malloc0(sizeof(int));
2556 *tmp_inst_id = instance_id;
2557 _bt_save_invocation_context(context, result, app,
2558 function_name, (gpointer)tmp_inst_id);
2562 case BT_GATT_SERVER_START_SERVICE: {
2567 int *tmp_inst_id = NULL;
2568 app = (char*)g_dbus_method_invocation_get_sender(context);
2570 __bt_service_get_parameters(in_param1, &service_handle,
2572 __bt_service_get_parameters(in_param2, &instance_id,
2575 result = _bt_gatt_server_start_service(app, service_handle, instance_id);
2577 if (BLUETOOTH_ERROR_NONE == result) {
2578 tmp_inst_id = g_malloc0(sizeof(int));
2579 *tmp_inst_id = instance_id;
2580 _bt_save_invocation_context(context, result, app,
2581 function_name, (gpointer)tmp_inst_id);
2585 case BT_GATT_SERVER_STOP_SERVICE: {
2589 int *tmp_inst_id = NULL;
2590 app = (char*)g_dbus_method_invocation_get_sender(context);
2592 __bt_service_get_parameters(in_param1, &service_handle,
2594 __bt_service_get_parameters(in_param2, &instance_id,
2597 result = _bt_gatt_server_stop_service(app, service_handle, instance_id);
2599 if (BLUETOOTH_ERROR_NONE == result) {
2600 tmp_inst_id = g_malloc0(sizeof(int));
2601 *tmp_inst_id = instance_id;
2602 _bt_save_invocation_context(context, result, app,
2603 function_name, (gpointer)tmp_inst_id);
2607 case BT_GATT_SERVER_DELETE_SERVICE: {
2610 int *tmp_inst_id = NULL;
2612 app = (char*)g_dbus_method_invocation_get_sender(context);
2614 __bt_service_get_parameters(in_param1, &service_handle,
2616 __bt_service_get_parameters(in_param2, &instance_id,
2619 result = _bt_gatt_server_delete_service(app, service_handle, instance_id);
2621 if (BLUETOOTH_ERROR_NONE == result) {
2622 tmp_inst_id = g_malloc0(sizeof(int));
2623 *tmp_inst_id = instance_id;
2624 _bt_save_invocation_context(context, result, app,
2625 function_name, (gpointer)tmp_inst_id);
2629 case BT_GATT_SERVER_SET_SERVICE_PERSISTENCE: {
2631 uuid = (char *)g_variant_get_data(in_param1);
2632 result = _bt_gatt_server_set_service_persistence(uuid);
2635 case BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE: {
2637 uuid = (char *)g_variant_get_data(in_param1);
2638 result = _bt_gatt_server_unset_service_persistence(uuid);
2641 case BT_GATT_SERVER_SEND_RESPONSE: {
2642 bluetooth_gatt_server_response_params_t param;
2643 bluetooth_gatt_att_data_t data;
2646 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_response_params_t));
2647 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2649 app = (char*)g_dbus_method_invocation_get_sender(context);
2651 __bt_service_get_parameters(in_param1, &data,
2652 sizeof(bluetooth_gatt_att_data_t));
2653 __bt_service_get_parameters(in_param2, ¶m,
2654 sizeof(bluetooth_gatt_server_response_params_t));
2656 result = _bt_gatt_server_send_response(app, &data, ¶m);
2660 case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE: {
2662 bluetooth_gatt_server_acquire_response_params_t param;
2665 msg = g_dbus_method_invocation_get_message(context);
2666 GUnixFDList *fd_list;
2671 fd_list = g_dbus_message_get_unix_fd_list(msg);
2673 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2675 app = (char*)g_dbus_method_invocation_get_sender(context);
2677 __bt_service_get_parameters(in_param1, ¶m,
2678 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2680 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2681 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2682 fd = fd_list_array[0];
2685 result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
2689 case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE: {
2691 bluetooth_gatt_server_acquire_response_params_t param;
2694 msg = g_dbus_method_invocation_get_message(context);
2695 GUnixFDList *fd_list;
2700 fd_list = g_dbus_message_get_unix_fd_list(msg);
2702 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2704 app = (char*)g_dbus_method_invocation_get_sender(context);
2706 __bt_service_get_parameters(in_param1, ¶m,
2707 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2709 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2710 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2711 fd = fd_list_array[0];
2714 result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
2718 case BT_GATT_SERVER_SEND_INDICATION: {
2719 bluetooth_gatt_server_indication_params_t param;
2720 bluetooth_gatt_att_data_t data;
2721 bluetooth_device_address_t address;
2724 app = (char*)g_dbus_method_invocation_get_sender(context);
2726 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_indication_params_t));
2727 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2728 memset(&address, 0x00, sizeof(bluetooth_device_address_t));
2730 __bt_service_get_parameters(in_param1, &data,
2731 sizeof(bluetooth_gatt_att_data_t));
2732 __bt_service_get_parameters(in_param2, ¶m,
2733 sizeof(bluetooth_gatt_server_indication_params_t));
2734 __bt_service_get_parameters(in_param3, &address,
2735 sizeof(bluetooth_device_address_t));
2737 result = _bt_gatt_server_send_indication(app, &address, &data, ¶m);
2741 case BT_GATT_SERVER_UPDATE_VALUE: {
2742 bluetooth_gatt_server_update_value_t param;
2746 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_update_value_t));
2748 app = (char*)g_dbus_method_invocation_get_sender(context);
2750 __bt_service_get_parameters(in_param1, &instance_id,
2752 __bt_service_get_parameters(in_param2, ¶m,
2753 sizeof(bluetooth_gatt_server_update_value_t));
2755 result = _bt_gatt_server_update_attribute_value(app, instance_id, ¶m);
2758 case BT_GATT_SERVER_READ_PHY: {
2759 bluetooth_device_address_t address = { {0} };
2761 sender = (char*)g_dbus_method_invocation_get_sender(context);
2763 __bt_service_get_parameters(in_param1,
2764 &address, sizeof(bluetooth_device_address_t));
2766 result = _bt_gatt_server_read_phy(&address);
2769 case BT_GATT_SERVER_SET_PHY: {
2770 bluetooth_device_address_t address = { {0} };
2775 sender = (char*)g_dbus_method_invocation_get_sender(context);
2777 __bt_service_get_parameters(in_param1,
2778 &address, sizeof(bluetooth_device_address_t));
2779 __bt_service_get_parameters(in_param2,
2780 &tx_phy, sizeof(int));
2781 __bt_service_get_parameters(in_param3,
2782 &rx_phy, sizeof(int));
2783 __bt_service_get_parameters(in_param4,
2784 &phy_options, sizeof(int));
2786 result = _bt_gatt_server_set_phy(&address, tx_phy, rx_phy, phy_options);
2789 case BT_GATT_CLIENT_READ_PHY: {
2790 bluetooth_device_address_t address = { {0} };
2792 sender = (char*)g_dbus_method_invocation_get_sender(context);
2794 __bt_service_get_parameters(in_param1,
2795 &address, sizeof(bluetooth_device_address_t));
2797 result = _bt_gatt_client_read_phy(&address);
2800 case BT_GATT_CLIENT_SET_PHY: {
2801 bluetooth_device_address_t address = { {0} };
2806 sender = (char*)g_dbus_method_invocation_get_sender(context);
2808 __bt_service_get_parameters(in_param1,
2809 &address, sizeof(bluetooth_device_address_t));
2810 __bt_service_get_parameters(in_param2,
2811 &tx_phy, sizeof(int));
2812 __bt_service_get_parameters(in_param3,
2813 &rx_phy, sizeof(int));
2814 __bt_service_get_parameters(in_param4,
2815 &phy_options, sizeof(int));
2817 result = _bt_gatt_client_set_phy(&address, tx_phy, rx_phy, phy_options);
2820 case BT_GET_ATT_MTU: {
2821 bluetooth_device_address_t address = { {0} };
2822 unsigned int mtu = 0;
2824 __bt_service_get_parameters(in_param1,
2825 &address, sizeof(bluetooth_device_address_t));
2826 result = _bt_get_att_mtu(&address, &mtu);
2827 BT_DBG("MTU: %d", mtu);
2829 if (result == BLUETOOTH_ERROR_NONE) {
2830 g_array_append_vals(*out_param1, &mtu,
2831 sizeof(unsigned int));
2835 case BT_REQ_ATT_MTU: {
2836 bluetooth_device_address_t address = { {0} };
2840 sender = (char*)g_dbus_method_invocation_get_sender(context);
2842 __bt_service_get_parameters(in_param1,
2843 &address, sizeof(bluetooth_device_address_t));
2844 __bt_service_get_parameters(in_param2,
2845 &mtu, sizeof(unsigned int));
2846 BT_DBG("BT_REQ_ATT_MTU: %d", mtu);
2847 result = _bt_request_att_mtu(&address, mtu);
2848 if (BLUETOOTH_ERROR_NONE == result) {
2849 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2851 _bt_convert_addr_type_to_string(addr, address.addr);
2853 /* Save the informations to invocation */
2854 _bt_save_invocation_context(context, result, sender,
2855 function_name, (gpointer)addr);
2857 g_array_append_vals(*out_param1, &address,
2858 sizeof(bluetooth_device_address_t));
2862 case BT_GET_DEVICE_IDA: {
2863 bluetooth_device_address_t address = { {0} };
2864 bluetooth_device_address_t id_addr = { {0} };
2866 __bt_service_get_parameters(in_param1,
2867 &address, sizeof(bluetooth_device_address_t));
2869 result = _bt_device_get_ida(&address, &id_addr);
2871 if (result == BLUETOOTH_ERROR_NONE) {
2872 g_array_append_vals(*out_param1, &id_addr,
2873 sizeof(bluetooth_device_address_t));
2877 case BT_SET_LE_STATIC_RANDOM_ADDRESS: {
2880 __bt_service_get_parameters(in_param1, &is_enable,
2883 result = _bt_set_le_static_random_address(is_enable);
2888 case BT_GATT_CLIENT_REGISTER: {
2889 bluetooth_device_address_t address = { {0} };
2892 sender = (char*)g_dbus_method_invocation_get_sender(context);
2894 __bt_service_get_parameters(in_param1,
2895 &address, sizeof(bluetooth_device_address_t));
2897 result = _bt_register_gatt_client_instance(sender, &address);
2898 if (BLUETOOTH_ERROR_NONE == result) {
2899 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2901 _bt_convert_addr_type_to_string(addr, address.addr);
2903 /* Save the informations to invocation */
2904 _bt_save_invocation_context(context, result, sender,
2905 function_name, (gpointer)addr);
2910 case BT_GATT_CLIENT_UNREGISTER: {
2913 sender = (char*)g_dbus_method_invocation_get_sender(context);
2914 __bt_service_get_parameters(in_param1,
2915 &client_id, sizeof(int));
2917 result = _bt_unregister_gatt_client_instance(sender, client_id);
2921 /* Async: Remote Interaction */
2922 case BT_GATT_ACQUIRE_WRITE: {
2926 bluetooth_gatt_client_char_prop_info_t param;
2928 sender = (char*)g_dbus_method_invocation_get_sender(context);
2930 __bt_service_get_parameters(in_param1, ¶m,
2931 sizeof(bluetooth_gatt_client_char_prop_info_t));
2934 result = _bt_gatt_acquire_write(¶m , &fd, &mtu);
2936 g_array_append_vals(*out_param1, &mtu, sizeof(int));
2938 if (BLUETOOTH_ERROR_NONE == result)
2939 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
2941 BT_ERR("GATT Client: gatt acquire write failed");
2945 GUnixFDList *fd_list = NULL;
2946 GError *error = NULL;
2948 /* Add socket fd to unix_fd_list */
2949 fd_list = g_unix_fd_list_new();
2950 g_unix_fd_list_append(fd_list, fd, &error);
2951 g_assert_no_error(error);
2953 _bt_service_method_return_with_unix_fd_list(
2954 context, *out_param1, result, fd_list);
2957 g_object_unref(fd_list);
2961 /* Async: Remote Interaction */
2962 case BT_CONNECT_LE: {
2963 bluetooth_device_address_t address = { {0} };
2964 gboolean auto_connect;
2968 sender = (char*)g_dbus_method_invocation_get_sender(context);
2970 __bt_service_get_parameters(in_param1,
2971 &address, sizeof(bluetooth_device_address_t));
2972 __bt_service_get_parameters(in_param2,
2973 &auto_connect, sizeof(gboolean));
2974 __bt_service_get_parameters(in_param3,
2975 &client_id, sizeof(int));
2977 BT_DBG("GATT Client: client_id[%d]", client_id);
2978 result = _bt_connect_le_device(&address, auto_connect, client_id);
2979 if (BLUETOOTH_ERROR_NONE == result) {
2980 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2981 _bt_convert_addr_type_to_string(addr, address.addr);
2983 /* Save the informations to invocation */
2984 _bt_save_invocation_context(context, result, sender,
2985 function_name, (gpointer)addr);
2988 _bt_handle_invocation_context(function_name, (void *)addr);
2990 BT_ERR("GATT Client: gatt connect failed. client_id[%d]", client_id);
2991 g_array_append_vals(*out_param1, &address,
2992 sizeof(bluetooth_device_address_t));
2996 /* Async: Remote Interaction */
2997 case BT_DISCONNECT_LE: {
2998 bluetooth_device_address_t address = { {0} };
3002 sender = (char*)g_dbus_method_invocation_get_sender(context);
3004 __bt_service_get_parameters(in_param1,
3005 &address, sizeof(bluetooth_device_address_t));
3006 __bt_service_get_parameters(in_param2,
3007 &client_id, sizeof(int));
3009 BT_INFO("GATT Disconnect using client Interface [%d]", client_id);
3010 result = _bt_disconnect_le_device(&address, client_id);
3011 if (BLUETOOTH_ERROR_NONE == result) {
3012 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
3014 _bt_convert_addr_type_to_string(addr, address.addr);
3016 /* Save the informations to invocation */
3017 _bt_save_invocation_context(context, result, sender,
3018 function_name, (gpointer)addr);
3020 g_array_append_vals(*out_param1, &address,
3021 sizeof(bluetooth_device_address_t));
3026 case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS: {
3027 guint available_packets = 0;
3029 result = _bt_gatt_get_data_batching_available_packets(&available_packets);
3030 BT_DBG("LE batching available packets %u", available_packets);
3031 if (result == BLUETOOTH_ERROR_NONE) {
3032 g_array_append_vals(*out_param1, &available_packets,
3039 case BT_ENABLE_GATT_DATA_BATCHING: {
3040 bluetooth_device_address_t address = { {0} };
3041 int packet_threshold;
3044 __bt_service_get_parameters(in_param1,
3045 &address, sizeof(bluetooth_device_address_t));
3046 __bt_service_get_parameters(in_param2,
3047 &packet_threshold, sizeof(int));
3048 __bt_service_get_parameters(in_param3,
3049 &timeout, sizeof(int));
3050 result = _bt_gatt_enable_data_batching(&address, packet_threshold, timeout);
3055 case BT_DISABLE_GATT_DATA_BATCHING: {
3056 bluetooth_device_address_t address = { {0} };
3058 __bt_service_get_parameters(in_param1,
3059 &address, sizeof(bluetooth_device_address_t));
3060 result = _bt_gatt_disable_data_batching(&address);
3065 case BT_GATT_GET_PRIMARY_SERVICES: {
3068 sender = (char*)g_dbus_method_invocation_get_sender(context);
3069 bluetooth_device_address_t address = { {0} };
3071 __bt_service_get_parameters(in_param1, &address,
3072 sizeof(bluetooth_device_address_t));
3074 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
3075 _bt_convert_addr_type_to_string(addr, address.addr);
3077 result = _bt_gatt_get_primary_services(addr);
3078 if (BLUETOOTH_ERROR_NONE == result) {
3079 _bt_save_invocation_context(context, result, sender,
3080 function_name, (gpointer)addr);
3086 case BT_GATT_GET_SERVICE_PROPERTIES: {
3087 bluetooth_gatt_client_svc_prop_info_t param;
3089 sender = (char*)g_dbus_method_invocation_get_sender(context);
3090 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_svc_prop_info_t));
3092 __bt_service_get_parameters(in_param1, ¶m,
3093 sizeof(bluetooth_gatt_client_svc_prop_info_t));
3095 result = _bt_gatt_get_all_characteristic(¶m);
3096 if (BLUETOOTH_ERROR_NONE == result) {
3097 /* Save the informations to invocation */
3098 _bt_save_invocation_context(context, result, sender,
3100 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_svc_prop_info_t)));
3104 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: {
3105 bluetooth_gatt_client_char_prop_info_t param;
3107 sender = (char*)g_dbus_method_invocation_get_sender(context);
3108 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3110 __bt_service_get_parameters(in_param1, ¶m,
3111 sizeof(bluetooth_gatt_client_char_prop_info_t));
3113 result = _bt_gatt_get_all_characteristic_properties(¶m);
3114 if (BLUETOOTH_ERROR_NONE == result) {
3115 /* Save the informations to invocation */
3116 _bt_save_invocation_context(context, result, sender,
3118 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3122 /* Async: Remote Interaction */
3123 case BT_GATT_READ_CHARACTERISTIC: {
3124 bluetooth_gatt_client_char_prop_info_t param;
3126 sender = (char*)g_dbus_method_invocation_get_sender(context);
3127 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3129 __bt_service_get_parameters(in_param1, ¶m,
3130 sizeof(bluetooth_gatt_client_char_prop_info_t));
3132 result = _bt_gatt_read_characteristic_value(¶m);
3133 if (BLUETOOTH_ERROR_NONE == result) {
3134 /* Save the informations to invocation */
3135 _bt_save_invocation_context(context, result, sender,
3137 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3141 /* Async: Remote Interaction */
3142 case BT_GATT_READ_DESCRIPTOR_VALUE: {
3143 bluetooth_gatt_client_desc_prop_info_t param;
3145 sender = (char*)g_dbus_method_invocation_get_sender(context);
3146 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3148 __bt_service_get_parameters(in_param1, ¶m,
3149 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3151 result = _bt_gatt_read_descriptor_value(¶m);
3152 if (BLUETOOTH_ERROR_NONE == result) {
3153 /* Save the informations to invocation */
3154 _bt_save_invocation_context(context, result, sender,
3156 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3160 /* Async: Remote Interaction */
3161 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: {
3162 bluetooth_gatt_client_char_prop_info_t param;
3163 bluetooth_gatt_att_data_t data;
3164 bluetooth_gatt_write_type_e write_type;
3166 sender = (char*)g_dbus_method_invocation_get_sender(context);
3168 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3169 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3171 __bt_service_get_parameters(in_param1, ¶m,
3172 sizeof(bluetooth_gatt_client_char_prop_info_t));
3173 __bt_service_get_parameters(in_param2, &data,
3174 sizeof(bluetooth_gatt_att_data_t));
3175 __bt_service_get_parameters(in_param3, &write_type,
3176 sizeof(bluetooth_gatt_write_type_e));
3178 result = _bt_gatt_write_characteristic_value_by_type(¶m , &data, write_type);
3179 if (BLUETOOTH_ERROR_NONE == result) {
3180 /* Save the informations to invocation */
3181 _bt_save_invocation_context(context, result, sender,
3183 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3187 /* Async: Remote Interaction */
3188 case BT_GATT_WRITE_DESCRIPTOR_VALUE: {
3189 bluetooth_gatt_client_desc_prop_info_t param;
3190 bluetooth_gatt_att_data_t data;
3191 bluetooth_gatt_write_type_e write_type;
3193 sender = (char*)g_dbus_method_invocation_get_sender(context);
3194 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3195 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3197 __bt_service_get_parameters(in_param1, ¶m,
3198 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3199 __bt_service_get_parameters(in_param2, &data,
3200 sizeof(bluetooth_gatt_att_data_t));
3201 __bt_service_get_parameters(in_param3, &write_type,
3202 sizeof(bluetooth_gatt_write_type_e));
3204 result = _bt_gatt_write_descriptor_value_by_type(¶m, &data, write_type);
3205 if (BLUETOOTH_ERROR_NONE == result) {
3206 /* Save the informations to invocation */
3207 _bt_save_invocation_context(context, result, sender,
3209 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3214 case BT_GATT_WATCH_CHARACTERISTIC: {
3215 bluetooth_gatt_client_char_prop_info_t param;
3220 gboolean is_indicate;
3223 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3225 sender = (char*)g_dbus_method_invocation_get_sender(context);
3227 __bt_service_get_parameters(in_param1, ¶m,
3228 sizeof(bluetooth_gatt_client_char_prop_info_t));
3229 __bt_service_get_parameters(in_param2, &client_id,
3231 __bt_service_get_parameters(in_param3, &is_notify,
3233 __bt_service_get_parameters(in_param4, &is_indicate,
3236 #ifdef TIZEN_FEATURE_BT_GATT_CLIENT_FD_DISABLE
3240 if (is_indicate == false) {
3241 result = _bt_gatt_acquire_notify(¶m , &fd, &mtu);
3242 if (BLUETOOTH_ERROR_NONE == result && fd > -1) {
3243 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
3245 GUnixFDList *fd_list = NULL;
3246 GError *error = NULL;
3248 g_array_append_vals(*out_param1, &mtu, sizeof(int));
3249 /* Add socket fd to unix_fd_list */
3250 fd_list = g_unix_fd_list_new();
3251 g_unix_fd_list_append(fd_list, fd, &error);
3252 g_assert_no_error(error);
3254 _bt_service_method_return_with_unix_fd_list(
3255 context, *out_param1, result, fd_list);
3257 g_object_unref(fd_list);
3263 result = _bt_gatt_watch_characteristic(¶m , client_id, is_notify);
3264 if (BLUETOOTH_ERROR_NONE == result) {
3265 /* Save the informations to invocation */
3266 _bt_save_invocation_context(context, result, sender, function_name,
3267 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3272 case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: {
3273 gboolean is_enabled;
3274 bluetooth_device_address_t address;
3276 sender = (char*)g_dbus_method_invocation_get_sender(context);
3278 __bt_service_get_parameters(in_param1,
3279 &address, sizeof(bluetooth_device_address_t));
3280 __bt_service_get_parameters(in_param2, &is_enabled,
3282 result = _bt_gatt_watch_service_changed_indication(sender, &address, is_enabled);
3283 BT_INFO("Service changed indication from app [%s]", sender);
3287 case BT_LE_CONN_UPDATE: {
3288 char *sender = NULL;
3289 bluetooth_device_address_t local_address = { {0} };
3290 bluetooth_le_connection_param_t parameters = {0};
3292 sender = (char *)g_dbus_method_invocation_get_sender(context);
3294 __bt_service_get_parameters(in_param1, &local_address,
3295 sizeof(bluetooth_device_address_t));
3296 __bt_service_get_parameters(in_param2, ¶meters,
3297 sizeof(bluetooth_le_connection_param_t));
3299 result = _bt_le_connection_update(sender,
3301 parameters.interval_min,
3302 parameters.interval_max,
3304 parameters.timeout);
3307 case BT_START_LE_DISCOVERY: {
3311 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3313 sender = (char *)g_dbus_method_invocation_get_sender(context);
3315 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3316 BT_ERR("Fail to get the sender pid");
3318 result = _bt_start_le_scan(sender, uid, pid);
3319 if (result == BLUETOOTH_ERROR_NONE) {
3320 _bt_save_invocation_context(context, result, sender,
3321 function_name, NULL);
3323 BT_DBG("Remeber pid / uid for the scan operation");
3324 _bt_bm_add_scan_app(SCAN_LE, uid, pid);
3328 case BT_STOP_LE_DISCOVERY: {
3332 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3334 sender = (char *)g_dbus_method_invocation_get_sender(context);
3336 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3337 BT_ERR("Fail to get the sender pid");
3339 result = _bt_stop_le_scan(sender);
3340 if (result == BLUETOOTH_ERROR_NONE) {
3341 _bt_save_invocation_context(context, result, sender,
3342 function_name, NULL);
3345 BT_DBG("Remove pid / uid for the scan operation");
3346 _bt_bm_remove_scan_app(SCAN_LE, uid, pid);
3350 case BT_IS_LE_DISCOVERYING: {
3351 gboolean le_discovering = FALSE;
3353 le_discovering = _bt_is_le_scanning();
3354 g_array_append_vals(*out_param1,
3355 &le_discovering, sizeof(gboolean));
3358 case BT_SET_SCAN_PARAMETERS: {
3359 bluetooth_le_scan_params_t scan_params;
3361 __bt_service_get_parameters(in_param1, &scan_params,
3362 sizeof(bluetooth_le_scan_params_t));
3364 BT_DBG("bluetooth_le_scan_params_t [%f %f %d]",
3365 scan_params.interval, scan_params.window,
3368 result = _bt_prepare_scan_parameters(&scan_params, 0);
3371 case BT_SET_SCAN_TYPE: {
3373 __bt_service_get_parameters(in_param1, &scan_type, sizeof(int));
3375 BT_DBG("bluetooth_le_scan_type [%d]", scan_type);
3376 result = _bt_prepare_scan_parameters(NULL, scan_type);
3379 #ifdef TIZEN_FEATURE_BT_PAN_NAP
3380 case BT_NETWORK_ACTIVATE:
3381 BT_DBG("BT_NETWORK_ACTIVATE Request recieved Request Handler ");
3382 result = _bt_network_activate();
3384 case BT_NETWORK_DEACTIVATE:
3385 result = _bt_network_deactivate();
3387 case BT_NETWORK_CONNECT: {
3388 bluetooth_device_address_t address = { {0} };
3391 __bt_service_get_parameters(in_param1,
3392 &address, sizeof(bluetooth_device_address_t));
3393 __bt_service_get_parameters(in_param2,
3394 &role, sizeof(int));
3396 result = _bt_network_connect(request_id, role, &address);
3397 if (result != BLUETOOTH_ERROR_NONE) {
3398 g_array_append_vals(*out_param1, &address,
3399 sizeof(bluetooth_device_address_t));
3403 case BT_NETWORK_DISCONNECT: {
3404 bluetooth_device_address_t address = { {0} };
3406 __bt_service_get_parameters(in_param1,
3407 &address, sizeof(bluetooth_device_address_t));
3409 result = _bt_network_disconnect(request_id, &address);
3410 if (result != BLUETOOTH_ERROR_NONE) {
3411 g_array_append_vals(*out_param1, &address,
3412 sizeof(bluetooth_device_address_t));
3416 case BT_NETWORK_SERVER_DISCONNECT: {
3417 bluetooth_device_address_t address = { {0} };
3419 __bt_service_get_parameters(in_param1,
3420 &address, sizeof(bluetooth_device_address_t));
3422 result = _bt_network_server_disconnect(request_id, &address);
3423 if (result != BLUETOOTH_ERROR_NONE) {
3424 g_array_append_vals(*out_param1, &address,
3425 sizeof(bluetooth_device_address_t));
3431 #ifdef TIZEN_FEATURE_BT_IPSP
3432 case BT_LE_IPSP_INIT:
3433 result = _bt_initialize_ipsp();
3435 case BT_LE_IPSP_DEINIT:
3436 result = _bt_deinitialize_ipsp();
3438 case BT_LE_IPSP_CONNECT: {
3439 bluetooth_device_address_t address = { {0} };
3440 __bt_service_get_parameters(in_param1, &address,
3441 sizeof(bluetooth_device_address_t));
3442 result = _bt_connect_le_ipsp_device(&address);
3445 case BT_LE_IPSP_DISCONNECT: {
3446 bluetooth_device_address_t address = { {0} };
3447 __bt_service_get_parameters(in_param1, &address,
3448 sizeof(bluetooth_device_address_t));
3449 result = _bt_disconnect_le_ipsp_device(&address);
3453 case BT_IS_ADVERTISING: {
3454 gboolean advertising = FALSE;
3455 advertising = _bt_is_advertising();
3456 g_array_append_vals(*out_param1, &advertising,
3460 case BT_IS_LE_2M_PHY_SUPPORTED: {
3461 gboolean is_2m_phy_supported = FALSE;
3463 is_2m_phy_supported = _bt_is_le_2m_phy_supported();
3464 g_array_append_vals(*out_param1, &is_2m_phy_supported, sizeof(gboolean));
3467 case BT_IS_LE_CODED_PHY_SUPPORTED: {
3468 gboolean is_coded_phy_supported = FALSE;
3470 is_coded_phy_supported = _bt_is_le_coded_phy_supported();
3471 g_array_append_vals(*out_param1, &is_coded_phy_supported, sizeof(gboolean));
3474 case BT_IS_LE_EXTENDED_ADVERTISING_SUPPORTED: {
3475 gboolean is_extended_advertising_supported = FALSE;
3477 is_extended_advertising_supported = _bt_is_le_extended_advertising_supported();
3478 g_array_append_vals(*out_param1, &is_extended_advertising_supported,
3482 case BT_IS_LE_EXTENDED_SCAN_SUPPORTED: {
3483 gboolean is_extended_scan_supported = FALSE;
3485 is_extended_scan_supported = _bt_is_le_extended_scan_supported();
3486 g_array_append_vals(*out_param1, &is_extended_scan_supported, sizeof(gboolean));
3489 case BT_LE_MAX_ADVERTISING_DATA_LEN: {
3490 gint max_advertising_len = 0;
3492 max_advertising_len = _bt_le_get_maximum_advertising_len();
3493 g_array_append_vals(*out_param1, &max_advertising_len, sizeof(gint));
3496 case BT_DISCONNECT_DEVICE: {
3497 bluetooth_device_address_t address = { {0} };
3499 __bt_service_get_parameters(in_param1,
3500 &address, sizeof(bluetooth_device_address_t));
3502 result = _bt_disconnect_device(&address);
3505 case BT_SET_SCANNING_PHY: {
3507 sender = (char*)g_dbus_method_invocation_get_sender(context);
3508 __bt_service_get_parameters(in_param1, &phy, sizeof(int));
3510 result = _bt_set_scan_phy(sender, phy);
3514 case BT_SET_SCANNING_ROLE: {
3516 sender = (char*)g_dbus_method_invocation_get_sender(context);
3517 __bt_service_get_parameters(in_param1, &role, sizeof(int));
3519 result = _bt_set_scan_role(sender, role);
3523 case BT_REGISTER_SCAN_FILTER: {
3524 bluetooth_le_scan_filter_t scan_filter;
3526 sender = (char*)g_dbus_method_invocation_get_sender(context);
3527 __bt_service_get_parameters(in_param1, &scan_filter,
3528 sizeof(bluetooth_le_scan_filter_t));
3530 BT_DBG("bluetooth_le_scan_filter_t [features : 0x%.2x]",
3531 scan_filter.added_features);
3533 result = _bt_register_scan_filter(sender, &scan_filter);
3538 case BT_TDS_PROVIDER_REGISTER: {
3539 char *sender = NULL;
3541 sender = (char *)g_dbus_method_invocation_get_sender(context);
3542 result = _bt_tds_provider_register(sender);
3547 case BT_TDS_PROVIDER_UNREGISTER: {
3548 char *sender = NULL;
3550 sender = (char *)g_dbus_method_invocation_get_sender(context);
3551 result = _bt_tds_provider_unregister(sender);
3556 case BT_TDS_PROVIDER_SET_MANUF_DATA: {
3557 char *sender = NULL;
3558 unsigned int length = 0;
3559 bluetooth_advertising_data_t manuf_data;
3561 __bt_service_get_parameters(in_param1,
3562 &length, sizeof(unsigned int));
3563 __bt_service_get_parameters(in_param2,
3564 &manuf_data, sizeof(bluetooth_advertising_data_t));
3565 sender = (char *)g_dbus_method_invocation_get_sender(context);
3567 result = _bt_tds_provider_set_manuf_data(sender, manuf_data.data, length);
3571 case BT_TDS_PROVIDER_CREATE: {
3572 char *sender = NULL;
3573 unsigned int tds_handle = 0;
3576 __bt_service_get_parameters(in_param1,
3577 &tds_handle, sizeof(unsigned int));
3578 __bt_service_get_parameters(in_param2,
3579 &transport, sizeof(int));
3580 sender = (char *)g_dbus_method_invocation_get_sender(context);
3581 result = _bt_tds_provider_transport_create(sender, transport, tds_handle);
3586 case BT_TDS_PROVIDER_DESTROY: {
3587 char *sender = NULL;
3588 unsigned int tds_handle = 0;
3590 __bt_service_get_parameters(in_param1,
3591 &tds_handle, sizeof(unsigned int));
3592 sender = (char *)g_dbus_method_invocation_get_sender(context);
3593 result = _bt_tds_provider_transport_remove(sender, tds_handle);
3598 case BT_TDS_PROVIDER_SET_TRANSPORT_DATA: {
3599 char *sender = NULL;
3600 unsigned int tds_handle = 0;
3601 int transport_state = 0;
3602 bluetooth_tds_data_t tds_data;
3604 __bt_service_get_parameters(in_param1,
3605 &tds_handle, sizeof(unsigned int));
3606 __bt_service_get_parameters(in_param2,
3607 &transport_state, sizeof(int));
3608 __bt_service_get_parameters(in_param3,
3609 &tds_data, sizeof(bluetooth_tds_data_t));
3610 sender = (char *)g_dbus_method_invocation_get_sender(context);
3612 result = _bt_tds_provider_set_transport_data(sender, tds_handle,
3613 transport_state, tds_data.data, tds_data.length);
3617 case BT_TDS_SEND_ACTIVATION_RESPONSE: {
3618 bluetooth_device_address_t address = { {0} };
3619 bluetooth_tds_data_t tds_data;
3620 char *sender = NULL;
3621 unsigned int tds_handle = 0;
3624 __bt_service_get_parameters(in_param1,
3625 &tds_handle, sizeof(unsigned int));
3626 __bt_service_get_parameters(in_param2,
3627 &response, sizeof(int));
3628 __bt_service_get_parameters(in_param3, &address,
3629 sizeof(bluetooth_device_address_t));
3630 __bt_service_get_parameters(in_param4,
3631 &tds_data, sizeof(bluetooth_tds_data_t));
3632 sender = (char *)g_dbus_method_invocation_get_sender(context);
3634 result = _bt_tds_provider_send_activation_response(sender, tds_handle,
3635 &address, response, tds_data.data, tds_data.length);
3640 sender = (char*)g_dbus_method_invocation_get_sender(context);
3641 BT_INFO("Mesh: Init by [%s]", sender);
3642 result = _bt_mesh_init(sender);
3643 /* Save invocation */
3644 if (result == BLUETOOTH_ERROR_NONE) {
3645 BT_INFO("Mesh: Save Invoation");
3646 sender = (char*)g_dbus_method_invocation_get_sender(context);
3647 _bt_save_invocation_context(context,
3649 function_name, NULL);
3653 case BT_MESH_DEINIT:
3654 sender = (char*)g_dbus_method_invocation_get_sender(context);
3655 BT_INFO("Mesh: De-Init by [%s]", sender);
3656 result = _bt_mesh_deinit(sender);
3659 case BT_MESH_NETWORK_CREATE: {
3660 bluetooth_mesh_node_t node;
3661 GSList *model_list = NULL;
3662 int total_models = 0;
3665 const char *network_name = NULL;
3666 bluetooth_mesh_network_t *network;
3668 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
3669 sender = (char*)g_dbus_method_invocation_get_sender(context);
3671 __bt_service_get_parameters(in_param1,
3672 &node, sizeof(bluetooth_mesh_node_t));
3673 network_name = (const char *)g_variant_get_data(in_param2);
3675 BT_INFO("MESH: Network name [%s]", network_name);
3677 param3 = g_array_new(TRUE, TRUE, sizeof(gchar));
3678 __bt_fill_garray_from_variant(in_param3, param3);
3680 total_models = (param3->len) / sizeof(bluetooth_mesh_model_t);
3681 for (i = 0; i < total_models; i++) {
3682 bluetooth_mesh_model_t *info = NULL;
3683 bluetooth_mesh_model_t *mod = NULL;
3685 info = &g_array_index(param3,
3686 bluetooth_mesh_model_t, i);
3688 mod = g_memdup2(info, sizeof(bluetooth_mesh_model_t));
3691 model_list = g_slist_append(model_list,
3694 result = _bt_mesh_network_create(requester_unique_creds,
3695 sender, network_name, &node, model_list);
3697 /* Save invocation */
3698 if (result == BLUETOOTH_ERROR_NONE) {
3699 BT_INFO("Mesh: Save Invoation");
3700 network = g_malloc0(sizeof(bluetooth_mesh_network_t));
3702 /* Save Network name & UUID, Token will be received in event */
3703 _bt_mesh_util_convert_hex_to_string(
3704 (uint8_t *) node.uuid, 16,
3706 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
3707 BT_INFO("Mesh: Mesh Netwok UUID [%s]", network->uuid);
3708 g_strlcpy(network->name.name, network_name,
3709 sizeof(network->name.name));
3710 g_strlcpy(network->app_cred,
3711 requester_unique_creds,
3712 sizeof(network->app_cred));
3713 sender = (char*)g_dbus_method_invocation_get_sender(context);
3714 BT_INFO("Mesh: Network Create by [%s]", sender);
3715 _bt_save_invocation_context(context,
3717 function_name, (gpointer)network);
3719 g_array_append_vals(*out_param1, &node, sizeof(bluetooth_mesh_node_t));
3720 BT_ERR("Mesh: Mesh Network creation schedule failed");
3721 g_slist_free_full(model_list, g_free);
3725 BT_INFO("Mesh: Cleanup");
3726 g_free((gpointer)requester_unique_creds);
3727 g_array_free(param3, TRUE);
3728 BT_INFO("Mesh: Cleanup Done");
3731 case BT_MESH_NETWORK_DESTROY: {
3732 bluetooth_mesh_network_t network;
3733 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3735 __bt_service_get_parameters(in_param1,
3736 &network, sizeof(bluetooth_mesh_network_t));
3738 BT_INFO("Mesh: Destroy Network");
3739 result = _bt_mesh_network_destroy(requester_unique_creds,
3742 if (result != BLUETOOTH_ERROR_NONE) {
3743 g_array_append_vals(*out_param1,
3744 &network, sizeof(bluetooth_mesh_network_t));
3746 BT_INFO("Mesh: Destroy Network scheduled: add invocation");
3747 bluetooth_mesh_network_t *net = \
3748 g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
3750 sender = (char*)g_dbus_method_invocation_get_sender(context);
3751 _bt_save_invocation_context(context, result, sender,
3752 function_name, (gpointer)net);
3756 case BT_MESH_NETWORK_LOAD: {
3758 bluetooth_mesh_network_t *network;
3759 token = (char *)g_variant_get_data(in_param1);
3760 BT_INFO("MESH: Network Load: Token string [%s]", token);
3761 result = _bt_mesh_network_load(requester_unique_creds, sender, token);
3762 /* Save invocation */
3763 if (result == BLUETOOTH_ERROR_NONE) {
3764 network = g_malloc0(sizeof(bluetooth_mesh_network_t));
3765 g_strlcpy(network->token.token, token,
3766 BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
3767 g_strlcpy(network->app_cred, requester_unique_creds,
3768 sizeof(network->app_cred));
3770 sender = (char*)g_dbus_method_invocation_get_sender(context);
3771 _bt_save_invocation_context(context, result, sender,
3772 function_name, (gpointer)network);
3774 g_free((gpointer)requester_unique_creds);
3777 case BT_MESH_NETWORK_UNLOAD: {
3778 bluetooth_mesh_network_t network;
3779 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3781 __bt_service_get_parameters(in_param1,
3782 &network, sizeof(bluetooth_mesh_network_t));
3784 BT_INFO("MESH: Network Unload: Network UUID [%s]", network.uuid);
3785 result = _bt_mesh_network_unload(requester_unique_creds,
3789 case BT_MESH_NETWORK_JOIN: {
3790 bluetooth_mesh_node_t node;
3791 GSList *model_list = NULL;
3792 int total_models = 0;
3796 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
3797 sender = (char*)g_dbus_method_invocation_get_sender(context);
3799 __bt_service_get_parameters(in_param1,
3800 &node, sizeof(bluetooth_mesh_node_t));
3802 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
3803 __bt_fill_garray_from_variant(in_param2, param2);
3805 total_models = (param2->len) / sizeof(bluetooth_mesh_model_t);
3806 for (i = 0; i < total_models; i++) {
3807 bluetooth_mesh_model_t *info = NULL;
3808 bluetooth_mesh_model_t *mod = NULL;
3809 info = &g_array_index(param2,
3810 bluetooth_mesh_model_t, i);
3811 mod = g_memdup2(info, sizeof(bluetooth_mesh_model_t));
3814 model_list = g_slist_append(model_list,
3818 BT_INFO("MESH: Network Join bt-service");
3819 //result = BLUETOOTH_ERROR_NONE;
3820 result = _bt_mesh_network_join(requester_unique_creds,
3821 sender, &node, model_list);
3822 if (result != BLUETOOTH_ERROR_NONE) {
3823 g_array_append_vals(*out_param1, &node, sizeof(bluetooth_mesh_node_t));
3824 BT_ERR("Mesh: Mesh Join Network schedule failed");
3825 g_slist_free_full(model_list, g_free);
3828 BT_INFO("return of _bt_mesh_network_join : [%d]", result);
3831 case BT_MESH_CANCEL_JOIN: {
3832 bluetooth_mesh_node_info_t node;
3833 memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t));
3835 __bt_service_get_parameters(in_param1,
3836 &node, sizeof(bluetooth_mesh_node_info_t));
3838 BT_INFO("Mesh: Cancel Join request");
3839 result = _bt_mesh_cancel_join(requester_unique_creds,
3841 if (result != BLUETOOTH_ERROR_NONE) {
3842 g_array_append_vals(*out_param1,
3843 &node, sizeof(bluetooth_mesh_node_t));
3847 case BT_MESH_NETWORK_SCAN: {
3848 bluetooth_mesh_network_t network;
3849 bluetooth_mesh_scan_param_t param;
3850 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3851 memset(¶m, 0x00, sizeof(bluetooth_mesh_scan_param_t));
3853 __bt_service_get_parameters(in_param1,
3854 &network, sizeof(bluetooth_mesh_network_t));
3856 __bt_service_get_parameters(in_param2,
3857 ¶m, sizeof(bluetooth_mesh_scan_param_t));
3859 result = _bt_mesh_network_scan(requester_unique_creds,
3860 sender, &network, ¶m);
3862 if (result != BLUETOOTH_ERROR_NONE) {
3863 g_array_append_vals(*out_param1,
3864 &network, sizeof(bluetooth_mesh_network_t));
3866 bluetooth_mesh_network_t *net = \
3867 g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
3869 sender = (char*)g_dbus_method_invocation_get_sender(context);
3870 _bt_save_invocation_context(context, result, sender,
3871 function_name, (gpointer)net);
3875 case BT_MESH_NETWORK_CANCEL_SCAN: {
3876 bluetooth_mesh_network_t network;
3877 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3879 __bt_service_get_parameters(in_param1,
3880 &network, sizeof(bluetooth_mesh_network_t));
3882 result = _bt_mesh_network_scan_cancel(requester_unique_creds,
3885 if (result != BLUETOOTH_ERROR_NONE)
3886 g_array_append_vals(*out_param1,
3887 &network, sizeof(bluetooth_mesh_network_t));
3890 case BT_MESH_NETWORK_SET_CAPABILITIES: {
3891 bluetooth_mesh_network_t network;
3892 bluetooth_mesh_provisioner_caps_t caps;
3893 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3894 memset(&caps, 0x00, sizeof(bluetooth_mesh_provisioner_caps_t));
3896 __bt_service_get_parameters(in_param1,
3897 &network, sizeof(bluetooth_mesh_network_t));
3899 __bt_service_get_parameters(in_param2,
3900 &caps, sizeof(bluetooth_mesh_provisioner_caps_t));
3902 result = _bt_mesh_network_set_provisioner_caps(
3903 requester_unique_creds, sender, &network, &caps);
3907 case BT_MESH_NETWORK_PROVISION_DEVICE: {
3908 bluetooth_mesh_provisioning_request_t req;
3909 memset(&req, 0x00, sizeof(bluetooth_mesh_provisioning_request_t));
3911 __bt_service_get_parameters(in_param1,
3912 &req, sizeof(bluetooth_mesh_provisioning_request_t));
3914 BT_INFO("Mesh: Provision Device UUID [%s]", req.dev_uuid);
3915 BT_INFO("Mesh: Provision Device in network[%s]", req.net_uuid);
3917 result = _bt_mesh_network_provision_device(
3918 requester_unique_creds, sender, &req);
3920 /* Save invocation */
3921 if (result != BLUETOOTH_ERROR_NONE) {
3922 g_array_append_vals(*out_param1, &req,
3923 sizeof(bluetooth_mesh_provisioning_request_t));
3925 bluetooth_mesh_provisioning_request_t *param = \
3926 g_memdup2(&req, sizeof(bluetooth_mesh_provisioning_request_t));
3928 sender = (char*)g_dbus_method_invocation_get_sender(context);
3929 _bt_save_invocation_context(context, result, sender,
3930 function_name, (gpointer)param);
3934 case BT_MESH_AUTHENTICATION_REPLY: {
3935 BT_INFO("Mesh: BT_MESH_AUTHENTICATION_REPLY");
3936 const char *auth_value = NULL;
3937 gboolean authentication_reply = FALSE;
3939 auth_value = g_variant_get_data(in_param2);
3940 __bt_service_get_parameters(in_param3,
3941 &authentication_reply, sizeof(gboolean));
3942 __bt_service_get_parameters(in_param1,
3943 &auth_type, sizeof(int));
3944 BT_INFO("Mesh: Auth Reply Type [%d]", auth_type);
3945 BT_INFO("Mesh: Auth Value [%s]", auth_value);
3946 BT_INFO("Mesh: Auth Accept [%d]", authentication_reply);
3947 result = _bt_mesh_authentication_reply(auth_type,
3948 auth_value, authentication_reply);
3951 case BT_MESH_NETWORK_SET_NAME: {
3952 bluetooth_mesh_network_t network;
3953 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3955 __bt_service_get_parameters(in_param1,
3956 &network, sizeof(bluetooth_mesh_network_t));
3958 result = _bt_mesh_network_set_name(requester_unique_creds, sender, &network);
3962 case BT_MESH_NETWORK_ADD_NETKEY: {
3963 bluetooth_mesh_network_t network;
3964 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3966 __bt_service_get_parameters(in_param1,
3967 &network, sizeof(bluetooth_mesh_network_t));
3969 result = _bt_mesh_network_add_netkey(requester_unique_creds,
3972 if (result != BLUETOOTH_ERROR_NONE) {
3973 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3975 bluetooth_mesh_network_t *net = g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
3977 sender = (char*)g_dbus_method_invocation_get_sender(context);
3978 _bt_save_invocation_context(context, result, sender,
3979 function_name, (gpointer)net);
3983 case BT_MESH_NETWORK_DELETE_NETKEY: {
3984 bluetooth_mesh_network_t network;
3987 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3989 __bt_service_get_parameters(in_param1,
3990 &network, sizeof(bluetooth_mesh_network_t));
3991 __bt_service_get_parameters(in_param2,
3992 &index, sizeof(guint16));
3994 result = _bt_mesh_network_delete_netkey(requester_unique_creds,
3995 sender, &network, index);
3997 if (result != BLUETOOTH_ERROR_NONE) {
3998 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
4000 bluetooth_mesh_network_t *net = g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
4002 sender = (char*)g_dbus_method_invocation_get_sender(context);
4003 _bt_save_invocation_context(context, result, sender,
4004 function_name, (gpointer)net);
4008 case BT_MESH_NETWORK_UPDATE_NETKEY: {
4009 bluetooth_mesh_network_t network;
4012 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4014 __bt_service_get_parameters(in_param1,
4015 &network, sizeof(bluetooth_mesh_network_t));
4016 __bt_service_get_parameters(in_param2,
4017 &index, sizeof(guint16));
4019 result = _bt_mesh_network_update_netkey(requester_unique_creds,
4020 sender, &network, index);
4022 if (result != BLUETOOTH_ERROR_NONE) {
4023 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
4025 bluetooth_mesh_network_t *net = g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
4027 sender = (char*)g_dbus_method_invocation_get_sender(context);
4028 _bt_save_invocation_context(context, result, sender,
4029 function_name, (gpointer)net);
4033 case BT_MESH_NETWORK_ADD_APPKEY: {
4034 bluetooth_mesh_network_t network;
4037 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4039 __bt_service_get_parameters(in_param1,
4040 &network, sizeof(bluetooth_mesh_network_t));
4041 __bt_service_get_parameters(in_param2,
4042 &net_idx, sizeof(guint16));
4044 result = _bt_mesh_network_add_appkey(requester_unique_creds,
4045 sender, &network, net_idx);
4047 if (result != BLUETOOTH_ERROR_NONE) {
4048 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
4050 bluetooth_mesh_network_t *net = g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
4052 sender = (char*)g_dbus_method_invocation_get_sender(context);
4053 _bt_save_invocation_context(context, result, sender,
4054 function_name, (gpointer)net);
4058 case BT_MESH_NETWORK_UPDATE_APPKEY: {
4059 bluetooth_mesh_network_t network;
4063 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4065 __bt_service_get_parameters(in_param1,
4066 &network, sizeof(bluetooth_mesh_network_t));
4067 __bt_service_get_parameters(in_param2,
4068 &net_idx, sizeof(guint16));
4069 __bt_service_get_parameters(in_param3,
4070 &app_idx, sizeof(guint16));
4072 result = _bt_mesh_network_update_appkey(requester_unique_creds,
4073 sender, &network, net_idx, app_idx);
4075 if (result != BLUETOOTH_ERROR_NONE) {
4076 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
4078 bluetooth_mesh_network_t *net = g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
4080 sender = (char*)g_dbus_method_invocation_get_sender(context);
4081 _bt_save_invocation_context(context, result, sender,
4082 function_name, (gpointer)net);
4086 case BT_MESH_NETWORK_DELETE_APPKEY: {
4087 bluetooth_mesh_network_t network;
4091 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4093 __bt_service_get_parameters(in_param1,
4094 &network, sizeof(bluetooth_mesh_network_t));
4095 __bt_service_get_parameters(in_param2,
4096 &net_idx, sizeof(guint16));
4097 __bt_service_get_parameters(in_param3,
4098 &app_idx, sizeof(guint16));
4100 result = _bt_mesh_network_delete_appkey(requester_unique_creds,
4101 sender, &network, net_idx, app_idx);
4103 if (result != BLUETOOTH_ERROR_NONE) {
4104 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
4106 bluetooth_mesh_network_t *net = g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
4108 sender = (char*)g_dbus_method_invocation_get_sender(context);
4109 _bt_save_invocation_context(context, result, sender,
4110 function_name, (gpointer)net);
4114 case BT_MESH_NETWORK_GET_NETKEYS: {
4115 bluetooth_mesh_network_t network;
4116 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4117 __bt_service_get_parameters(in_param1,
4118 &network, sizeof(bluetooth_mesh_network_t));
4119 result = _bt_mesh_network_get_netkeys(requester_unique_creds,
4120 sender, &network, out_param1);
4123 case BT_MESH_NETWORK_GET_APPKEYS: {
4124 bluetooth_mesh_network_t network;
4127 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4128 __bt_service_get_parameters(in_param1,
4129 &network, sizeof(bluetooth_mesh_network_t));
4130 __bt_service_get_parameters(in_param2,
4131 &net_idx, sizeof(guint16));
4132 result = _bt_mesh_network_get_appkeys(
4133 requester_unique_creds, sender,
4134 &network, net_idx, out_param1);
4137 case BT_MESH_NETWORK_GET_NODES: {
4138 bluetooth_mesh_network_t network;
4139 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4140 __bt_service_get_parameters(in_param1,
4141 &network, sizeof(bluetooth_mesh_network_t));
4142 result = _bt_mesh_network_get_nodes(
4143 requester_unique_creds, sender,
4144 &network, out_param1);
4147 case BT_MESH_ELEMENT_GET_MODELS: {
4148 bluetooth_mesh_network_t network;
4152 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4153 __bt_service_get_parameters(in_param1,
4154 &network, sizeof(bluetooth_mesh_network_t));
4155 __bt_service_get_parameters(in_param2,
4156 &node_addr, sizeof(guint16));
4157 __bt_service_get_parameters(in_param3,
4158 &elem_idx, sizeof(int));
4159 result = _bt_mesh_element_get_models(requester_unique_creds, sender,
4160 &network, node_addr, elem_idx, out_param1);
4163 case BT_MESH_NODE_BROWSE: {
4164 bluetooth_mesh_node_discover_t req;
4165 memset(&req, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4167 __bt_service_get_parameters(in_param1,
4168 &req, sizeof(bluetooth_mesh_node_discover_t));
4170 result = _bt_mesh_browse_remote_node(
4171 requester_unique_creds, sender, &req);
4173 /* Save invocation */
4174 if (result != BLUETOOTH_ERROR_NONE) {
4175 g_array_append_vals(*out_param1, &req,
4176 sizeof(bluetooth_mesh_node_discover_t));
4178 bluetooth_mesh_node_discover_t *param = \
4179 g_memdup2(&req, sizeof(bluetooth_mesh_node_discover_t));
4181 sender = (char*)g_dbus_method_invocation_get_sender(context);
4182 _bt_save_invocation_context(context, result, sender,
4183 function_name, (gpointer)param);
4187 case BT_MESH_NODE_GET_VENDOR_FEATURES: {
4188 bluetooth_mesh_node_features_t req;
4189 memset(&req, 0x00, sizeof(bluetooth_mesh_node_features_t));
4191 __bt_service_get_parameters(in_param1,
4192 &req, sizeof(bluetooth_mesh_node_features_t));
4194 result = _bt_mesh_node_discover_vendor_features(
4195 requester_unique_creds, sender, &req);
4197 /* Save invocation */
4198 if (result != BLUETOOTH_ERROR_NONE) {
4199 g_array_append_vals(*out_param1,
4200 &req, sizeof(bluetooth_mesh_node_features_t));
4202 bluetooth_mesh_node_features_t *param = \
4203 g_memdup2(&req, sizeof(bluetooth_mesh_node_features_t));
4205 sender = (char*)g_dbus_method_invocation_get_sender(context);
4206 _bt_save_invocation_context(context, result, sender,
4207 function_name, (gpointer)param);
4211 case BT_MESH_NODE_CONFIGURE_KEY: {
4212 bluetooth_mesh_key_configure_t req;
4214 memset(&req, 0x00, sizeof(bluetooth_mesh_key_configure_t));
4216 __bt_service_get_parameters(in_param1,
4217 &req, sizeof(bluetooth_mesh_key_configure_t));
4219 result = _bt_mesh_node_configure_key(
4220 requester_unique_creds, sender, &req);
4222 /* Save invocation */
4223 if (result != BLUETOOTH_ERROR_NONE) {
4224 g_array_append_vals(*out_param1,
4225 &req, sizeof(bluetooth_mesh_key_configure_t));
4227 bluetooth_mesh_key_configure_t *param = \
4228 g_memdup2(&req, sizeof(bluetooth_mesh_key_configure_t));
4230 sender = (char*)g_dbus_method_invocation_get_sender(context);
4231 _bt_save_invocation_context(context, result, sender,
4232 function_name, (gpointer)param);
4236 case BT_MESH_NODE_TTL_EXECUTE: {
4237 bluetooth_mesh_node_ttl_info_t req;
4239 memset(&req, 0x00, sizeof(bluetooth_mesh_node_ttl_info_t));
4241 __bt_service_get_parameters(in_param1,
4242 &req, sizeof(bluetooth_mesh_node_ttl_info_t));
4244 result = _bt_mesh_ttl_execute_remote_node(
4245 requester_unique_creds, sender, &req);
4247 /* Save invocation */
4248 if (result != BLUETOOTH_ERROR_NONE) {
4249 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_node_ttl_info_t));
4251 bluetooth_mesh_node_ttl_info_t *param = \
4252 g_memdup2(&req, sizeof(bluetooth_mesh_node_ttl_info_t));
4254 sender = (char*)g_dbus_method_invocation_get_sender(context);
4255 _bt_save_invocation_context(context, result, sender,
4256 function_name, (gpointer)param);
4260 case BT_MESH_MODEL_CONFIGURE_APPKEY: {
4261 bluetooth_mesh_model_configure_t req;
4263 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4265 __bt_service_get_parameters(in_param1,
4266 &req, sizeof(bluetooth_mesh_model_configure_t));
4268 result = _bt_mesh_node_model_appkey_execute(
4269 requester_unique_creds, sender, &req);
4271 /* Save invocation */
4272 if (result != BLUETOOTH_ERROR_NONE) {
4273 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4275 bluetooth_mesh_model_configure_t *param = \
4276 g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4278 sender = (char*)g_dbus_method_invocation_get_sender(context);
4279 _bt_save_invocation_context(context, result, sender,
4280 function_name, (gpointer)param);
4284 case BT_MESH_MODEL_EXECUTE_MSG: {
4285 bluetooth_mesh_model_msg_t req;
4287 memset(&req, 0x00, sizeof(bluetooth_mesh_model_msg_t));
4289 __bt_service_get_parameters(in_param1,
4290 &req, sizeof(bluetooth_mesh_model_msg_t));
4292 result = _bt_mesh_model_execute_msg(
4293 requester_unique_creds, sender, &req);
4295 /* Save invocation */
4296 if (result != BLUETOOTH_ERROR_NONE) {
4297 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_msg_t));
4299 bluetooth_mesh_model_msg_t *param = \
4300 g_memdup2(&req, sizeof(bluetooth_mesh_model_msg_t));
4302 sender = (char*)g_dbus_method_invocation_get_sender(context);
4303 _bt_save_invocation_context(context, result, sender,
4304 function_name, (gpointer)param);
4308 case BT_MESH_MODEL_RESPONSE_MSG: {
4309 bluetooth_mesh_model_msg_t req;
4310 memset(&req, 0x00, sizeof(bluetooth_mesh_model_msg_t));
4311 __bt_service_get_parameters(in_param1,
4312 &req, sizeof(bluetooth_mesh_model_msg_t));
4314 result = _bt_mesh_model_send_response(
4315 requester_unique_creds, sender, &req);
4316 if (result != BLUETOOTH_ERROR_NONE)
4317 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_msg_t));
4320 case BT_MESH_NODE_GET_NETKEYS: {
4321 bluetooth_mesh_node_discover_t node;
4322 memset(&node, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4323 __bt_service_get_parameters(in_param1,
4324 &node, sizeof(bluetooth_mesh_node_discover_t));
4325 result = _bt_mesh_network_node_get_netkeys(
4326 requester_unique_creds, &node, out_param1);
4329 case BT_MESH_NODE_GET_APPKEYS: {
4330 bluetooth_mesh_node_discover_t node;
4331 memset(&node, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4332 __bt_service_get_parameters(in_param1,
4333 &node, sizeof(bluetooth_mesh_node_discover_t));
4334 result = _bt_mesh_network_node_get_appkeys(
4335 requester_unique_creds, sender, &node, out_param1);
4338 case BT_MESH_NODE_RESET: {
4339 bluetooth_mesh_node_info_t node;
4340 memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t));
4342 __bt_service_get_parameters(in_param1,
4343 &node, sizeof(bluetooth_mesh_node_info_t));
4345 BT_INFO("Mesh: Reset the Node");
4346 result = _bt_mesh_network_reset_node(requester_unique_creds,
4351 case BT_MESH_MODEL_GET_APPKEY_LIST: {
4352 bluetooth_mesh_model_configure_t req;
4354 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4356 __bt_service_get_parameters(in_param1,
4357 &req, sizeof(bluetooth_mesh_model_configure_t));
4359 result = _bt_mesh_node_model_get_appkey_list(
4360 requester_unique_creds, sender, &req);
4362 /* Save invocation */
4363 if (result != BLUETOOTH_ERROR_NONE) {
4364 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4366 bluetooth_mesh_model_configure_t *param = \
4367 g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4369 sender = (char*)g_dbus_method_invocation_get_sender(context);
4370 _bt_save_invocation_context(context, result, sender,
4371 function_name, (gpointer)param);
4375 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST: {
4376 bluetooth_mesh_model_configure_t req;
4378 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4380 __bt_service_get_parameters(in_param1,
4381 &req, sizeof(bluetooth_mesh_model_configure_t));
4383 result = _bt_mesh_node_model_get_subscription_list(
4384 requester_unique_creds, sender, &req);
4386 /* Save invocation */
4387 if (result != BLUETOOTH_ERROR_NONE) {
4388 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4390 bluetooth_mesh_model_configure_t *param = \
4391 g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4393 sender = (char*)g_dbus_method_invocation_get_sender(context);
4394 _bt_save_invocation_context(context, result, sender,
4395 function_name, (gpointer)param);
4400 case BT_MESH_NETWORK_CREATE_GROUP: {
4401 bluetooth_mesh_network_t net;
4402 bluetooth_mesh_network_group_info_t res;
4403 gboolean is_virtual;
4406 memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
4407 memset(&res, 0x00, sizeof(bluetooth_mesh_network_group_info_t));
4409 __bt_service_get_parameters(in_param1,
4410 &net, sizeof(bluetooth_mesh_network_t));
4411 __bt_service_get_parameters(in_param2,
4412 &is_virtual, sizeof(gboolean));
4413 __bt_service_get_parameters(in_param3,
4414 &grp_addr, sizeof(guint16));
4416 result = _bt_mesh_network_create_group(
4417 requester_unique_creds, sender, &net,
4418 is_virtual, grp_addr, &res);
4420 if (result == BLUETOOTH_ERROR_NONE)
4421 g_array_append_vals(*out_param1, &res,
4422 sizeof(bluetooth_mesh_network_group_info_t));
4425 case BT_MESH_NETWORK_REMOVE_GROUP: {
4426 bluetooth_mesh_network_t net;
4427 bluetooth_mesh_network_group_info_t req;
4429 memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
4430 memset(&req, 0x00, sizeof(bluetooth_mesh_network_group_info_t));
4432 __bt_service_get_parameters(in_param1,
4433 &net, sizeof(bluetooth_mesh_network_t));
4434 __bt_service_get_parameters(in_param2,
4435 &req, sizeof(bluetooth_mesh_network_group_info_t));
4437 result = _bt_mesh_network_remove_group(
4438 requester_unique_creds, sender, &net, &req);
4442 case BT_MESH_MODEL_CONFIG_GROUP_SUB: {
4443 bluetooth_mesh_model_configure_t req;
4445 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4447 __bt_service_get_parameters(in_param1,
4448 &req, sizeof(bluetooth_mesh_model_configure_t));
4450 result = _bt_mesh_model_configure_group_subscription(
4451 requester_unique_creds, sender, &req);
4453 /* Save invocation */
4454 if (result != BLUETOOTH_ERROR_NONE) {
4455 g_array_append_vals(*out_param1,
4456 &req, sizeof(bluetooth_mesh_model_configure_t));
4458 bluetooth_mesh_model_configure_t *param = \
4459 g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4461 sender = (char*)g_dbus_method_invocation_get_sender(context);
4462 _bt_save_invocation_context(context, result, sender,
4463 function_name, (gpointer)param);
4467 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB: {
4468 bluetooth_mesh_model_configure_t req;
4470 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4472 __bt_service_get_parameters(in_param1,
4473 &req, sizeof(bluetooth_mesh_model_configure_t));
4475 result = _bt_mesh_model_configure_virtual_group_subscription(
4476 requester_unique_creds, sender, &req);
4478 /* Save invocation */
4479 if (result != BLUETOOTH_ERROR_NONE) {
4480 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4482 bluetooth_mesh_model_configure_t *param = \
4483 g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4485 sender = (char*)g_dbus_method_invocation_get_sender(context);
4486 _bt_save_invocation_context(context, result, sender,
4487 function_name, (gpointer)param);
4491 case BT_MESH_MODEL_SET_PUBLICATION: {
4492 bluetooth_mesh_model_configure_t req;
4494 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4496 __bt_service_get_parameters(in_param1,
4497 &req, sizeof(bluetooth_mesh_model_configure_t));
4499 result = _bt_mesh_model_set_publication(
4500 requester_unique_creds, sender, &req);
4502 /* Save invocation */
4503 if (result != BLUETOOTH_ERROR_NONE) {
4504 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4506 bluetooth_mesh_model_configure_t *param = g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4508 sender = (char*)g_dbus_method_invocation_get_sender(context);
4509 _bt_save_invocation_context(context, result, sender,
4510 function_name, (gpointer)param);
4514 case BT_MESH_MODEL_GET_PUBLICATION: {
4515 bluetooth_mesh_model_configure_t req;
4517 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4519 __bt_service_get_parameters(in_param1,
4520 &req, sizeof(bluetooth_mesh_model_configure_t));
4522 result = _bt_mesh_model_get_publication(
4523 requester_unique_creds, sender, &req);
4525 /* Save invocation */
4526 if (result != BLUETOOTH_ERROR_NONE) {
4527 g_array_append_vals(*out_param1,
4528 &req, sizeof(bluetooth_mesh_model_configure_t));
4530 bluetooth_mesh_model_configure_t *param = \
4531 g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4533 sender = (char*)g_dbus_method_invocation_get_sender(context);
4534 _bt_save_invocation_context(context, result, sender,
4535 function_name, (gpointer)param);
4539 case BT_MESH_NETWORK_GET_GROUPS: {
4540 bluetooth_mesh_network_t network;
4541 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4542 __bt_service_get_parameters(in_param1,
4543 &network, sizeof(bluetooth_mesh_network_t));
4544 BT_INFO("Mesh: Request:: Get Groups");
4545 result = _bt_mesh_network_get_groups(
4546 requester_unique_creds, sender, &network, out_param1);
4549 case BT_L2CAP_LE_CLIENT_CONNECT: {
4550 bluetooth_device_address_t address = { {0} };
4553 __bt_service_get_parameters(in_param1,
4554 &address, sizeof(bluetooth_device_address_t));
4556 __bt_service_get_parameters(in_param2, &psm, sizeof(int));
4558 result = _bt_l2cap_le_connect_using_psm(&address, psm);
4560 if (result != BLUETOOTH_ERROR_NONE) {
4561 bluetooth_l2cap_le_connection_t conn_info;
4563 BT_ERR("BT_L2CAP_LE_CLIENT_CONNECT failed, send error errcode %d", result);
4564 memset(&conn_info, 0x00, sizeof(bluetooth_l2cap_le_connection_t));
4565 conn_info.device_role = L2CAP_LE_ROLE_CLIENT;
4566 conn_info.socket_fd = -1;
4567 conn_info.psm = psm;
4568 memcpy(&conn_info.device_addr, &address, sizeof(bluetooth_device_address_t));
4569 g_array_append_vals(*out_param1, &conn_info,
4570 sizeof(bluetooth_l2cap_le_connection_t));
4572 bluetooth_l2cap_le_connection_t *conn_info;
4574 BT_INFO("BT_L2CAP_LE_CLIENT_CONNECT success, save context");
4575 sender = (char*)g_dbus_method_invocation_get_sender(context);
4576 conn_info = g_malloc0(sizeof(bluetooth_l2cap_le_connection_t));
4577 conn_info->socket_fd = -1;
4578 conn_info->device_role = L2CAP_LE_ROLE_CLIENT;
4579 conn_info->psm = psm;
4581 memcpy(&conn_info->device_addr, &address, sizeof(bluetooth_device_address_t));
4583 _bt_save_invocation_context(context, result, sender, function_name, (gpointer)conn_info);
4587 case BT_L2CAP_LE_SOCKET_DISCONNECT: {
4589 * Bluetooth L2CAP_LE socket disconnection will be done from bt-api, call to bt-service
4590 * is only used for privilege check, so return BLUETOOTH_ERROR_NONE from here.
4592 result = BLUETOOTH_ERROR_NONE;
4595 case BT_L2CAP_LE_SOCKET_WRITE: {
4597 * This call to bt-service is only used for privilege check, so return
4598 * BLUETOOTH_ERROR_NONE from here.
4600 result = BLUETOOTH_ERROR_NONE;
4603 case BT_L2CAP_LE_CREATE_SOCKET: {
4605 * This call to bt-service is only used for privilege check, so return
4606 * BLUETOOTH_ERROR_NONE from here.
4608 result = BLUETOOTH_ERROR_NONE;
4611 case BT_L2CAP_LE_LISTEN_AND_ACCEPT: {
4615 __bt_service_get_parameters(in_param1, &psm, sizeof(int));
4617 socket_fd = _bt_l2cap_le_socket_listen(psm, true);
4618 if (socket_fd > 0) {
4619 result = BLUETOOTH_ERROR_NONE;
4620 sender = (char *)g_dbus_method_invocation_get_sender(context);
4621 _bt_save_invocation_context(context,
4622 result, sender, function_name, NULL);
4624 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
4628 case BT_L2CAP_LE_LISTEN: {
4632 __bt_service_get_parameters(in_param1, &psm, sizeof(int));
4634 socket_fd = _bt_l2cap_le_socket_listen(psm, false);
4635 if (socket_fd > 0) {
4636 result = BLUETOOTH_ERROR_NONE;
4637 sender = (char *)g_dbus_method_invocation_get_sender(context);
4638 _bt_save_invocation_context(context, result,
4639 sender, function_name, NULL);
4641 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
4645 case BT_L2CAP_LE_ACCEPT_CONNECTION: {
4648 address = (char *)g_variant_get_data(in_param1);
4649 result = _bt_socket_reply_conn_authorization(address, TRUE);
4652 case BT_L2CAP_LE_REJECT_CONNECTION: {
4655 address = (char *)g_variant_get_data(in_param1);
4656 result = _bt_socket_reply_conn_authorization(address, FALSE);
4659 case BT_L2CAP_LE_REMOVE_SOCKET: {
4661 * This call to bt-service is only used for privilege check, so return
4662 * BLUETOOTH_ERROR_NONE from here.
4664 result = BLUETOOTH_ERROR_NONE;
4668 BT_INFO("UnSupported function [%d]", function_name);
4669 result = BLUETOOTH_ERROR_NOT_SUPPORT;
4675 #ifdef TIZEN_FEATURE_BT_OBEX
4676 /* Function definitions*/
4677 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
4682 size = g_variant_get_size(var);
4684 data = (char *)g_variant_get_data(var);
4686 param = g_array_append_vals(param, data, size);
4692 int __bt_obexd_request(int function_name,
4695 GDBusMethodInvocation *context,
4696 GVariant *in_param1,
4697 GVariant *in_param2,
4698 GVariant *in_param3,
4699 GVariant *in_param4,
4700 GArray **out_param1)
4704 int result = BLUETOOTH_ERROR_NONE;
4706 BT_DBG("function_name : %x", function_name);
4708 switch (function_name) {
4709 case BT_OPP_PUSH_FILES: {
4710 BT_DBG("BT_OPP_PUSH_FILES");
4712 bluetooth_device_address_t address = { {0} };
4713 bt_file_path_t *path;
4718 __bt_service_get_parameters(in_param1, &address,
4719 sizeof(bluetooth_device_address_t));
4720 __bt_service_get_parameters(in_param3, &file_count,
4723 file_path = g_new0(char *, file_count + 1);
4725 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
4726 __bt_fill_garray_from_variant(in_param2, param2);
4728 for (i = 0; i < file_count; i++) {
4729 path = &g_array_index(param2, bt_file_path_t, i);
4730 file_path[i] = g_strdup(path->path);
4732 BT_DBG("_bt_opp_client_push_files");
4733 result = _bt_opp_client_push_files(request_id, context,
4734 &address, file_path,
4737 for (i = 0; i < file_count; i++)
4738 g_free(file_path[i]);
4741 g_array_free(param2, TRUE);
4745 case BT_OPP_CANCEL_PUSH: {
4746 result = _bt_opp_client_cancel_push();
4750 case BT_OPP_IS_PUSHING_FILES: {
4751 gboolean is_sending = FALSE;
4753 result = _bt_opp_client_is_sending(&is_sending);
4755 g_array_append_vals(*out_param1, &is_sending,
4759 case BT_OPP_GET_TRANSFER_PROGRESS: {
4762 guint8 progress = 0;
4764 __bt_service_get_parameters(in_param1, &direction,
4766 __bt_service_get_parameters(in_param2, &transfer_id,
4769 result = _bt_opp_get_client_progress(&progress);
4771 result = _bt_opp_get_server_progress(transfer_id, &progress);
4773 g_array_append_vals(*out_param1, &progress,
4779 case BT_MAP_CREATE_SESSION: {
4780 BT_DBG("BT_MAP_CREATE_SESSION");
4781 char *address = (char *)g_variant_get_data(in_param1);
4782 char *session_id = NULL;
4783 result = _bt_create_session_sync(address, &session_id);
4784 if (result == BLUETOOTH_ERROR_NONE)
4785 g_array_append_vals(*out_param1, session_id, strlen(session_id)+1);
4789 case BT_MAP_DESTROY_SESSION: {
4790 BT_DBG("BT_MAP_DESTROY_SESSION");
4791 char* session_id = (char *)g_variant_get_data(in_param1);
4792 result = _bt_destroy_session_sync(session_id);
4793 if (result == BLUETOOTH_ERROR_NONE)
4794 BT_DBG("successfully destroyed session");
4798 case BT_MAP_SET_FOLDER: {
4799 BT_DBG("BT_MAP_SET_FOLDER");
4800 char *session_id = (char *)g_variant_get_data(in_param1);
4801 char *name = (char *)g_variant_get_data(in_param2);
4802 result = _bt_map_client_set_folder(session_id, name);
4806 case BT_MAP_LIST_FOLDERS: {
4807 BT_DBG("BT_MAP_LIST_FOLDERS");
4809 char* session_id = (char *)g_variant_get_data(in_param1);
4810 char* filter_serialized = (char*)g_variant_get_data(in_param2);
4812 result = _bt_map_client_list_folders(request_id, context, session_id, filter_serialized);
4813 if (result == BLUETOOTH_ERROR_NONE)
4814 BT_DBG("_bt_map_client_list_folders succeed");
4819 case BT_MAP_LIST_FILTER_FIELDS: {
4820 BT_DBG("BT_MAP_LIST_FILTER_FIELDS");
4822 char* session_id = (char *)g_variant_get_data(in_param1);
4824 result = _bt_map_client_list_filter_fields(request_id, context, session_id);
4825 if (result == BLUETOOTH_ERROR_NONE)
4826 BT_DBG("_bt_map_client_list_filter_fields succeed");
4831 case BT_MAP_LIST_MESSAGES: {
4832 BT_DBG("BT_MAP_LIST_MESSAGES");
4834 char* session_id = (char*)g_variant_get_data(in_param1);
4835 char* folder = (char*)g_variant_get_data(in_param2);
4836 char* filter_serialized = (char*)g_variant_get_data(in_param3);
4838 result = _bt_map_client_list_messages(request_id, context, session_id, folder, filter_serialized);
4839 if (result == BLUETOOTH_ERROR_NONE)
4840 BT_DBG("_bt_map_client_list_messages succeed");
4842 BT_DBG("_bt_map_client_list_messages failed");
4847 case BT_MAP_UPDATE_INBOX: {
4848 BT_DBG("BT_MAP_UPDATE_INBOX");
4849 char* session_id = (char *)g_variant_get_data(in_param1);
4850 result = _bt_map_client_update_inbox(session_id);
4854 case BT_MAP_PUSH_MESSAGE: {
4855 BT_DBG("BT_MAP_PUSH_MESSAGE");
4857 char* session_id = (char *)g_variant_get_data(in_param1);
4858 char* source_file = (char *)g_variant_get_data(in_param2);
4859 char* folder = (char *)g_variant_get_data(in_param3);
4860 char* args_serialized = (char *)g_variant_get_data(in_param4);
4862 result = _bt_map_client_push_message(
4863 request_id, context, session_id, source_file, folder, args_serialized);
4864 if (result == BLUETOOTH_ERROR_NONE)
4865 BT_DBG("_bt_map_client_push_message succeed");
4867 BT_ERR("_bt_map_client_push_message failed");
4872 case BT_MAP_GET_MESSAGE: {
4873 BT_DBG("BT_MAP_GET_MESSAGE");
4874 // TODO session currently is not used, but should be valid
4875 //char* session_id = (char *)g_variant_get_data(in_param1);
4876 char* message_object = (char *)g_variant_get_data(in_param2);
4877 char* target_file = (char *)g_variant_get_data(in_param3);
4878 bool attachment = false;
4879 __bt_service_get_parameters(in_param4, &attachment, sizeof(bool));
4881 result = _bt_map_client_get_message(request_id, context, message_object,
4882 target_file, attachment);
4883 if (result == BLUETOOTH_ERROR_NONE)
4884 BT_DBG("_bt_map_client_get_message succeed");
4889 case BT_OBEX_SERVER_ALLOCATE: {
4895 sender = (char *)g_dbus_method_invocation_get_sender(context);
4897 path = (char *)g_variant_get_data(in_param1);
4898 __bt_service_get_parameters(in_param2, &is_native,
4900 __bt_service_get_parameters(in_param3, &app_pid,
4903 result = _bt_obex_server_allocate(sender,
4904 path, app_pid, is_native);
4908 case BT_OBEX_SERVER_DEALLOCATE: {
4912 __bt_service_get_parameters(in_param1, &is_native,
4914 __bt_service_get_parameters(in_param2, &app_pid,
4917 result = _bt_obex_server_deallocate(app_pid, is_native);
4920 case BT_OBEX_SERVER_IS_ACTIVATED: {
4921 gboolean is_activated = FALSE;
4923 result = _bt_obex_server_is_activated(&is_activated);
4925 g_array_append_vals(*out_param1, &is_activated,
4930 case BT_OBEX_SERVER_ACCEPT_CONNECTION: {
4931 result = _bt_obex_server_accept_connection(request_id);
4935 case BT_OBEX_SERVER_REJECT_CONNECTION: {
4936 result = _bt_obex_server_reject_connection();
4940 case BT_OBEX_SERVER_ACCEPT_FILE: {
4943 file_name = (char *)g_variant_get_data(in_param1);
4945 result = _bt_obex_server_accept_authorize(file_name, TRUE);
4949 case BT_OBEX_SERVER_REJECT_FILE: {
4950 result = _bt_obex_server_reject_authorize();
4954 case BT_OBEX_SERVER_SET_PATH: {
4956 char *destination_path;
4958 destination_path = (char *)g_variant_get_data(in_param1);
4959 __bt_service_get_parameters(in_param2, &is_native,
4962 result = _bt_obex_server_set_destination_path(destination_path,
4967 case BT_OBEX_SERVER_SET_ROOT: {
4970 root = (char *)g_variant_get_data(in_param1);
4972 result = _bt_obex_server_set_root(root);
4976 case BT_OBEX_SERVER_CANCEL_TRANSFER: {
4979 __bt_service_get_parameters(in_param1, &transfer_id,
4982 result = _bt_obex_server_cancel_transfer(transfer_id);
4986 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS: {
4987 result = _bt_obex_server_cancel_all_transfers();
4991 case BT_OBEX_SERVER_IS_RECEIVING: {
4992 gboolean is_receiving = FALSE;
4994 result = _bt_obex_server_is_receiving(&is_receiving);
4996 g_array_append_vals(*out_param1, &is_receiving,
5000 case BT_PBAP_CONNECT: {
5001 bluetooth_device_address_t address = { {0} };
5003 __bt_service_get_parameters(in_param1, &address,
5004 sizeof(bluetooth_device_address_t));
5006 result = _bt_pbap_connect(&address);
5009 case BT_PBAP_DISCONNECT: {
5010 bluetooth_device_address_t address = { {0} };
5012 __bt_service_get_parameters(in_param1, &address,
5013 sizeof(bluetooth_device_address_t));
5015 result = _bt_pbap_disconnect(&address);
5018 case BT_PBAP_GET_PHONEBOOK_SIZE: {
5019 bluetooth_device_address_t address = { {0} };
5020 bt_pbap_folder_t folder = { 0, };
5022 __bt_service_get_parameters(in_param1, &address,
5023 sizeof(bluetooth_device_address_t));
5024 __bt_service_get_parameters(in_param2, &folder,
5025 sizeof(bt_pbap_folder_t));
5027 result = _bt_pbap_get_phonebook_size(&address,
5028 folder.addressbook, folder.folder_type);
5031 case BT_PBAP_GET_PHONEBOOK: {
5032 bluetooth_device_address_t address = { {0} };
5033 bt_pbap_folder_t folder = { 0, };
5034 bt_pbap_pull_parameters_t app_param = { 0, };
5036 __bt_service_get_parameters(in_param1, &address,
5037 sizeof(bluetooth_device_address_t));
5038 __bt_service_get_parameters(in_param2, &folder,
5039 sizeof(bt_pbap_folder_t));
5040 __bt_service_get_parameters(in_param3, &app_param,
5041 sizeof(bt_pbap_pull_parameters_t));
5043 result = _bt_pbap_get_phonebook(&address, folder.addressbook,
5044 folder.folder_type, &app_param);
5047 case BT_PBAP_GET_LIST: {
5048 bluetooth_device_address_t address = { {0} };
5049 bt_pbap_folder_t folder = { 0, };
5050 bt_pbap_list_parameters_t app_param = { 0, };
5052 __bt_service_get_parameters(in_param1, &address,
5053 sizeof(bluetooth_device_address_t));
5054 __bt_service_get_parameters(in_param2, &folder,
5055 sizeof(bt_pbap_folder_t));
5056 __bt_service_get_parameters(in_param3, &app_param,
5057 sizeof(bt_pbap_list_parameters_t));
5059 result = _bt_pbap_get_list(&address, folder.addressbook,
5060 folder.folder_type, &app_param);
5063 case BT_PBAP_PULL_VCARD: {
5064 bluetooth_device_address_t address = { {0} };
5065 bt_pbap_folder_t folder = { 0, };
5066 bt_pbap_pull_vcard_parameters_t app_param = { 0, };
5068 __bt_service_get_parameters(in_param1, &address,
5069 sizeof(bluetooth_device_address_t));
5070 __bt_service_get_parameters(in_param2, &folder,
5071 sizeof(bt_pbap_folder_t));
5072 __bt_service_get_parameters(in_param3, &app_param,
5073 sizeof(bt_pbap_pull_vcard_parameters_t));
5075 result = _bt_pbap_pull_vcard(&address, folder.addressbook,
5076 folder.folder_type, &app_param);
5079 case BT_PBAP_PHONEBOOK_SEARCH: {
5080 bluetooth_device_address_t address = { {0} };
5081 bt_pbap_folder_t folder = { 0, };
5082 bt_pbap_search_parameters_t app_param = { 0, };
5084 __bt_service_get_parameters(in_param1, &address,
5085 sizeof(bluetooth_device_address_t));
5086 __bt_service_get_parameters(in_param2, &folder,
5087 sizeof(bt_pbap_folder_t));
5088 __bt_service_get_parameters(in_param3, &app_param,
5089 sizeof(bt_pbap_search_parameters_t));
5091 result = _bt_pbap_phonebook_search(&address, folder.addressbook,
5092 folder.folder_type, &app_param);
5097 BT_ERR("Unknown function!");
5098 result = BLUETOOTH_ERROR_INTERNAL;
5107 int __bt_agent_request(int function_name,
5110 GDBusMethodInvocation *context,
5111 GVariant *in_param1,
5112 GVariant *in_param2,
5113 GVariant *in_param3,
5114 GVariant *in_param4,
5115 GArray **out_param1)
5118 switch (function_name) {
5119 case BT_SET_AUTHORIZATION: {
5126 sender = (char *)g_dbus_method_invocation_get_sender(context);
5127 __bt_service_get_parameters(in_param1, &type, sizeof(int));
5128 uuid = (char *)g_variant_get_data(in_param2);
5129 path = (char *)g_variant_get_data(in_param3);
5130 __bt_service_get_parameters(in_param4, &fd, sizeof(int));
5132 result = _bt_register_osp_server_in_agent(sender, type, uuid, path, fd);
5135 case BT_UNSET_AUTHORIZATION: {
5139 __bt_service_get_parameters(in_param1, &type, sizeof(int));
5140 uuid = (char *)g_variant_get_data(in_param2);
5142 result = _bt_unregister_osp_server_in_agent(type, uuid);
5146 BT_ERR("Unknown function!");
5147 result = BLUETOOTH_ERROR_INTERNAL;
5154 int __bt_core_request(int function_name,
5157 GDBusMethodInvocation *context,
5158 GVariant *in_param1)
5162 switch (function_name) {
5163 case BT_ENABLE_ADAPTER:
5166 _bt_set_adapter_request_state(TRUE);
5167 status = _bt_adapter_get_status();
5169 if (status == BT_ACTIVATING) {
5170 BT_DBG("Enabling in progress");
5171 result = BLUETOOTH_ERROR_IN_PROGRESS;
5172 } else if (status == BT_ACTIVATED) {
5173 BT_DBG("Already enabled");
5174 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
5176 _bt_adapter_set_status(BT_ACTIVATING);
5177 result = BLUETOOTH_ERROR_NONE;
5182 case BT_DISABLE_ADAPTER:
5186 status = _bt_adapter_get_status();
5187 if (status == BT_DEACTIVATING) {
5188 BT_DBG("Disabling in progress");
5189 result = BLUETOOTH_ERROR_IN_PROGRESS;
5190 } else if (status == BT_DEACTIVATED) {
5191 BT_DBG("Already disabled");
5192 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
5194 _bt_adapter_set_status(BT_DEACTIVATING);
5195 result = BLUETOOTH_ERROR_NONE;
5200 case BT_ENABLE_ADAPTER_LE:
5202 bt_le_status_t le_status;
5203 _bt_set_le_request_state(TRUE);
5204 le_status = _bt_adapter_get_le_status();
5205 if (le_status == BT_LE_ACTIVATING) {
5206 BT_DBG("Enabling in progress");
5207 result = BLUETOOTH_ERROR_IN_PROGRESS;
5208 } else if (le_status == BT_LE_ACTIVATED) {
5209 BT_DBG("Already enabled");
5210 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
5212 _bt_adapter_set_le_status(BT_LE_ACTIVATING);
5213 result = BLUETOOTH_ERROR_NONE;
5218 case BT_DISABLE_ADAPTER_LE:
5220 bt_le_status_t le_status;
5222 le_status = _bt_adapter_get_le_status();
5223 if (le_status == BT_LE_DEACTIVATING) {
5224 BT_DBG("Disabling in progress");
5225 result = BLUETOOTH_ERROR_IN_PROGRESS;
5226 } else if (le_status == BT_LE_DEACTIVATED) {
5227 BT_DBG("Already disabled");
5228 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
5230 _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
5231 result = BLUETOOTH_ERROR_NONE;
5237 BT_ERR("Unknown function!");
5238 result = BLUETOOTH_ERROR_INTERNAL;
5245 static int __bt_service_get_requester_app_id(const char *unique_name, char *app_id, int len)
5250 retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
5251 retv_if(unique_name == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
5253 ret = __bt_service_get_sender_pid(unique_name, &pid);
5254 if (ret != BLUETOOTH_ERROR_NONE) {
5255 BT_ERR("Fail to get the sender pid");
5259 ret = aul_app_get_appid_bypid(pid, app_id, len);
5260 if (ret != AUL_R_OK) {
5261 BT_ERR("app_id not found");
5262 return BLUETOOTH_ERROR_NOT_SUPPORT;
5264 BT_DBG("Sender app_id: %s", app_id);
5266 return BLUETOOTH_ERROR_NONE;
5269 #ifdef TIZEN_FEATURE_BT_CONTAINER
5270 static void __bt_service_free_nspid(struct nspid_t *nspid)
5272 g_free(nspid->unique_name);
5276 static void __bt_service_cleanup_nspid_list(const char *unique_name)
5279 struct nspid_t *nspid;
5281 ret_if(unique_name == NULL);
5283 for (l = nspid_list; l; l = g_slist_next(l)) {
5287 if (!g_strcmp0(nspid->unique_name, unique_name)) {
5288 nspid_list = g_slist_remove(nspid_list, nspid);
5289 __bt_service_free_nspid(nspid);
5295 static gboolean __bt_service_is_container_request(const char *unique_name)
5299 char path[1024], buf[1024];
5301 gboolean is_container = FALSE;
5303 struct nspid_t *nspid;
5305 for (l = nspid_list; l; l = g_slist_next(l)) {
5309 if (!g_strcmp0(nspid->unique_name, unique_name))
5310 return nspid->is_container;
5313 ret = __bt_service_get_sender_pid(unique_name, &pid);
5314 if (ret != BLUETOOTH_ERROR_NONE)
5317 sprintf(path, "/proc/%d/status", pid);
5318 fp = fopen(path, "r");
5320 BT_ERR("fopen() failed. %d(%s)", errno, strerror(errno));
5324 while (fgets(buf, sizeof(buf), fp)) {
5325 if (strstr(buf, "NSpid:")) {
5326 char *p = strchr(buf + 7, '\t'); /* find 2nd '\t' */
5328 BT_DBG("caller is container process");
5329 is_container = TRUE;
5337 nspid = g_malloc0(sizeof(struct nspid_t));
5338 nspid->unique_name = g_strdup(unique_name);
5339 nspid->is_container = is_container;
5340 nspid_list = g_slist_append(nspid_list, nspid);
5342 return is_container;
5346 #ifdef TIZEN_FEATURE_BT_CONTAINER
5347 static gboolean __bt_service_check_privilege_in_container(int function_name,
5348 const char *unique_name)
5350 int result = BLUETOOTH_ERROR_NONE;
5351 GError *error = NULL;
5353 GArray *in_param1, *in_param2, *in_param3, *in_param4, *in_param5;
5354 GVariant *param1, *param2, *param3, *param4, *param5, *out_param;
5356 proxy = _bt_get_container_proxy();
5357 if (proxy == NULL) {
5358 BT_ERR("container proxy is NULL");
5362 in_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
5363 in_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
5364 in_param3 = g_array_new(TRUE, TRUE, sizeof(gchar));
5365 in_param4 = g_array_new(TRUE, TRUE, sizeof(gchar));
5366 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
5368 /* The sender's privilege should be checked not bt-service in container */
5369 g_array_append_vals(in_param1, unique_name, strlen(unique_name));
5371 param1 = g_variant_new_from_data((const GVariantType *)"ay",
5372 in_param1->data, in_param1->len, TRUE, NULL, NULL);
5373 param2 = g_variant_new_from_data((const GVariantType *)"ay",
5374 in_param2->data, in_param2->len, TRUE, NULL, NULL);
5375 param3 = g_variant_new_from_data((const GVariantType *)"ay",
5376 in_param3->data, in_param3->len, TRUE, NULL, NULL);
5377 param4 = g_variant_new_from_data((const GVariantType *)"ay",
5378 in_param4->data, in_param4->len, TRUE, NULL, NULL);
5379 param5 = g_variant_new_from_data((const GVariantType *)"ay",
5380 in_param5->data, in_param5->len, TRUE, NULL, NULL);
5382 BT_DBG("This request is from container. Privilege will be checked in container. unique_name: %s", unique_name);
5384 GVariant *ret = g_dbus_proxy_call_sync(proxy, "service_request",
5385 g_variant_new("(iii@ay@ay@ay@ay@ay)",
5386 BT_CHECK_PRIVILEGE, function_name,
5387 BT_SYNC_REQ, param1, param2,
5388 param3, param4, param5),
5389 G_DBUS_CALL_FLAGS_NONE, -1,
5392 BT_ERR("dBUS-RPC is failed");
5394 if (error != NULL) {
5395 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
5396 error->code, error->message);
5397 g_clear_error(&error);
5399 BT_ERR("error returned was NULL");
5402 result = BLUETOOTH_ERROR_INTERNAL;
5404 g_variant_get(ret, "(iv)", &result, &out_param);
5405 g_variant_unref(out_param);
5406 g_variant_unref(ret);
5409 g_array_free(in_param1, TRUE);
5410 g_array_free(in_param2, TRUE);
5411 g_array_free(in_param3, TRUE);
5412 g_array_free(in_param4, TRUE);
5413 g_array_free(in_param5, TRUE);
5415 return (result == BLUETOOTH_ERROR_NONE) ? TRUE : FALSE;
5419 gboolean __bt_service_check_privilege(int function_name,
5421 const char *unique_name)
5424 gboolean result = TRUE;
5425 char *client_creds = NULL;
5426 char *user_creds = NULL;
5427 char *client_session = "";
5428 enum cynara_client_creds client_creds_method = CLIENT_METHOD_SMACK;
5429 enum cynara_user_creds user_creds_method = USER_METHOD_UID;
5430 char err_msg[256] = {0, };
5432 retv_if(unique_name == NULL, FALSE);
5433 retv_if(bt_service_conn == NULL, FALSE);
5435 #ifdef TIZEN_FEATURE_BT_CONTAINER
5436 if (_bt_service_is_container() == FALSE)
5437 if (__bt_service_is_container_request(unique_name) == TRUE)
5438 return __bt_service_check_privilege_in_container(function_name, unique_name);
5441 ret_val = cynara_creds_get_default_client_method(&client_creds_method);
5442 if (ret_val != CYNARA_API_SUCCESS) {
5443 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5444 BT_ERR("Fail to get default client method: %s", err_msg);
5448 ret_val = cynara_creds_get_default_user_method(&user_creds_method);
5449 if (ret_val != CYNARA_API_SUCCESS) {
5450 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5451 BT_ERR("Fail to get default user method: %s", err_msg);
5455 ret_val = cynara_creds_gdbus_get_client(bt_service_conn, unique_name, client_creds_method, &client_creds);
5456 if (ret_val != CYNARA_API_SUCCESS) {
5457 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5458 BT_ERR("Fail to get client credential: %s", err_msg);
5462 ret_val = cynara_creds_gdbus_get_user(bt_service_conn, unique_name, user_creds_method, &user_creds);
5463 if (ret_val != CYNARA_API_SUCCESS) {
5464 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5465 BT_ERR("Fail to get user credential: %s", err_msg);
5471 BT_DBG("%s, %s, %s", unique_name, client_creds, user_creds);
5473 switch (function_name) {
5474 case BT_SET_LOCAL_NAME:
5475 case BT_START_DISCOVERY:
5476 case BT_START_CUSTOM_DISCOVERY:
5477 case BT_CANCEL_DISCOVERY:
5478 case BT_OOB_ADD_REMOTE_DATA:
5479 case BT_OOB_REMOVE_REMOTE_DATA:
5480 case BT_OOB_READ_LOCAL_DATA:
5481 case BT_SET_ADVERTISING:
5482 case BT_SET_CUSTOM_ADVERTISING:
5483 case BT_SET_ADVERTISING_PARAMETERS:
5484 case BT_START_LE_DISCOVERY:
5485 case BT_STOP_LE_DISCOVERY:
5486 case BT_SET_SCAN_PARAMETERS:
5487 case BT_SET_SCAN_TYPE:
5488 case BT_UPDATE_LE_CONNECTION_MODE:
5490 case BT_BOND_DEVICE:
5491 case BT_CANCEL_BONDING:
5492 case BT_UNBOND_DEVICE:
5494 case BT_SET_AUTHORIZATION:
5495 case BT_UNSET_AUTHORIZATION:
5496 case BT_SEARCH_SERVICE:
5498 case BT_RFCOMM_CLIENT_CONNECT:
5499 if (function_name == BT_RFCOMM_CLIENT_CONNECT)
5500 BT_PERMANENT_LOG("Connect socket");
5501 case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
5502 case BT_RFCOMM_SOCKET_DISCONNECT:
5503 if (function_name == BT_RFCOMM_SOCKET_DISCONNECT)
5504 BT_PERMANENT_LOG("Disconnect socket");
5505 case BT_RFCOMM_SOCKET_WRITE:
5506 case BT_RFCOMM_CREATE_SOCKET:
5507 case BT_RFCOMM_REMOVE_SOCKET:
5508 case BT_RFCOMM_SEND_RX_DETAILS:
5509 case BT_RFCOMM_SEND_TX_DETAILS:
5510 case BT_RFCOMM_UPDATE_CONNECTION_INFO:
5512 case BT_OPP_PUSH_FILES:
5513 case BT_OPP_CANCEL_PUSH:
5514 /* TODO: MAP? MAP functions, see above */
5516 case BT_OBEX_SERVER_ACCEPT_CONNECTION:
5517 case BT_OBEX_SERVER_REJECT_CONNECTION:
5518 case BT_OBEX_SERVER_ACCEPT_FILE:
5519 case BT_OBEX_SERVER_REJECT_FILE:
5520 case BT_OBEX_SERVER_SET_PATH:
5521 case BT_OBEX_SERVER_SET_ROOT:
5522 case BT_OBEX_SERVER_CANCEL_TRANSFER:
5523 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS:
5525 case BT_AUDIO_SELECT_ROLE:
5526 case BT_AUDIO_CONNECT:
5527 case BT_AUDIO_DISCONNECT:
5529 case BT_AG_DISCONNECT:
5531 case BT_AV_DISCONNECT:
5532 case BT_AV_SOURCE_CONNECT:
5533 case BT_AV_SOURCE_DISCONNECT:
5534 case BT_AVRCP_TARGET_CONNECT:
5535 case BT_AVRCP_TARGET_DISCONNECT:
5536 case BT_AVRCP_CONTROL_CONNECT:
5537 case BT_AVRCP_CONTROL_DISCONNECT:
5538 case BT_AVRCP_HANDLE_CONTROL:
5539 case BT_AVRCP_SET_TRACK_INFO:
5540 case BT_AVRCP_SET_PROPERTY:
5541 case BT_AVRCP_SET_PROPERTIES:
5542 case BT_AVRCP_CONTROL_SET_PROPERTY:
5544 case BT_AUDIO_SET_ABSOLUTE_VOLUME:
5545 case BT_AUDIO_GET_ABSOLUTE_VOLUME:
5546 case BT_AUDIO_IS_AVC_ACTIVATED:
5549 case BT_HF_DISCONNECT:
5551 case BT_HID_CONNECT:
5552 case BT_HID_DISCONNECT:
5554 case BT_HID_DEVICE_ACTIVATE:
5555 case BT_HID_DEVICE_DEACTIVATE:
5556 case BT_HID_DEVICE_CONNECT:
5557 case BT_HID_DEVICE_DISCONNECT:
5558 case BT_HID_DEVICE_SEND_MOUSE_EVENT:
5559 case BT_HID_DEVICE_SEND_KEY_EVENT:
5560 case BT_HID_DEVICE_SEND_REPLY_TO_REPORT:
5561 case BT_HID_DEVICE_SEND_CUSTOM_EVENT:
5564 case BT_DISCONNECT_LE:
5566 case BT_SET_ADVERTISING_DATA:
5567 case BT_SET_SCAN_RESPONSE_DATA:
5569 case BT_HDP_CONNECT:
5570 case BT_HDP_DISCONNECT:
5571 case BT_HDP_SEND_DATA:
5572 case BT_HDP_REGISTER_SINK_APP:
5573 case BT_HDP_UNREGISTER_SINK_APP:
5576 case BT_DPM_SET_ALLOW_BT_MODE:
5577 case BT_DPM_GET_ALLOW_BT_MODE:
5578 case BT_DPM_SET_DEVICE_RESTRITION:
5579 case BT_DPM_GET_DEVICE_RESTRITION:
5580 case BT_DPM_SET_UUID_RESTRITION:
5581 case BT_DPM_GET_UUID_RESTRITION:
5582 case BT_DPM_ADD_DEVICES_BLOCKLIST:
5583 case BT_DPM_ADD_DEVICES_ALLOWLIST:
5584 case BT_DPM_ADD_UUIDS_BLOCKLIST:
5585 case BT_DPM_ADD_UUIDS_ALLOWLIST:
5586 case BT_DPM_CLEAR_DEVICES_BLOCKLIST:
5587 case BT_DPM_CLEAR_DEVICES_ALLOWLIST:
5588 case BT_DPM_CLEAR_UUIDS_BLOCKLIST:
5589 case BT_DPM_CLEAR_UUIDS_ALLOWLIST:
5590 case BT_DPM_REMOVE_DEVICE_BLOCKLIST:
5591 case BT_DPM_REMOVE_DEVICE_ALLOWLIST:
5592 case BT_DPM_REMOVE_UUID_BLOCKLIST:
5593 case BT_DPM_REMOVE_UUID_ALLOWLIST:
5594 case BT_DPM_GET_DEVICES_BLOCKLIST:
5595 case BT_DPM_GET_DEVICES_ALLOWLIST:
5596 case BT_DPM_GET_UUIDS_BLOCKLIST:
5597 case BT_DPM_GET_UUIDS_ALLOWLIST:
5598 case BT_DPM_SET_ALLOW_OUTGOING_CALL:
5599 case BT_DPM_GET_ALLOW_OUTGOING_CALL:
5600 case BT_DPM_SET_PAIRING_STATE:
5601 case BT_DPM_GET_PAIRING_STATE:
5602 case BT_DPM_SET_PROFILE_STATE:
5603 case BT_DPM_GET_PROFILE_STATE:
5604 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE:
5605 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE:
5606 case BT_DPM_SET_DISCOVERABLE_STATE:
5607 case BT_DPM_GET_DISCOVERABLE_STATE:
5608 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE:
5609 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE:
5610 case BT_DPM_SET_DATA_TRANSFER_STATE:
5611 case BT_DPM_GET_DATA_TRANSFER_STATE:
5613 case BT_NETWORK_ACTIVATE:
5614 case BT_NETWORK_DEACTIVATE:
5615 case BT_NETWORK_CONNECT:
5616 case BT_NETWORK_DISCONNECT:
5617 case BT_NETWORK_SERVER_DISCONNECT:
5619 case BT_GATT_GET_PRIMARY_SERVICES:
5620 case BT_GATT_GET_SERVICE_PROPERTIES: /* GATT Client */
5621 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: /* GATT Client */
5622 case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: /* GATT Client */
5623 case BT_GATT_DISCOVER_CHARACTERISTICS:
5624 case BT_GATT_SET_PROPERTY_REQUEST:
5625 case BT_GATT_READ_CHARACTERISTIC:
5626 case BT_GATT_READ_DESCRIPTOR_VALUE: /* GATT Client */
5627 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: /* GATT Client */
5628 case BT_GATT_ACQUIRE_WRITE:
5629 case BT_GATT_WRITE_DESCRIPTOR_VALUE: /* GATT Client */
5630 case BT_GATT_WATCH_CHARACTERISTIC: /* GATT Client */
5631 case BT_GATT_CLIENT_REGISTER: /* GATT Client */
5632 case BT_GATT_CLIENT_UNREGISTER: /* GATT Client */
5633 case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
5634 case BT_GATT_REGISTER_APPLICATION:
5635 case BT_GATT_REGISTER_SERVICE:
5636 case BT_GATT_SEND_RESPONSE:
5638 case BT_GATT_SERVER_REGISTER:
5639 case BT_GATT_SERVER_ADD_SERVICE:
5640 case BT_GATT_SERVER_ADD_CHARACTERISTIC:
5641 case BT_GATT_SERVER_ADD_DESCRIPTOR:
5642 case BT_GATT_SERVER_START_SERVICE:
5643 case BT_GATT_SERVER_STOP_SERVICE:
5644 case BT_GATT_SERVER_DELETE_SERVICE:
5645 case BT_GATT_SERVER_SET_SERVICE_PERSISTENCE:
5646 case BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE:
5647 case BT_GATT_SERVER_SEND_RESPONSE:
5648 case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE:
5649 case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE:
5650 case BT_GATT_SERVER_SEND_INDICATION:
5651 case BT_GATT_SERVER_UPDATE_VALUE:
5652 case BT_GATT_SERVER_DEREGISTER:
5654 case BT_GATT_SERVER_READ_PHY:
5655 case BT_GATT_SERVER_SET_PHY:
5656 case BT_GATT_CLIENT_READ_PHY:
5657 case BT_GATT_CLIENT_SET_PHY:
5658 case BT_REQ_ATT_MTU:
5659 case BT_PBAP_CONNECT:
5660 case BT_PBAP_DISCONNECT:
5661 case BT_PBAP_GET_PHONEBOOK_SIZE:
5662 case BT_PBAP_GET_PHONEBOOK:
5663 case BT_PBAP_GET_LIST:
5664 case BT_PBAP_PULL_VCARD:
5665 case BT_PBAP_PHONEBOOK_SEARCH:
5667 case BT_RFCOMM_LISTEN_AND_ACCEPT:
5669 case BT_L2CAP_LE_CLIENT_CONNECT:
5670 case BT_L2CAP_LE_CLIENT_CANCEL_CONNECT:
5671 case BT_L2CAP_LE_SOCKET_DISCONNECT:
5672 case BT_L2CAP_LE_SOCKET_WRITE:
5673 case BT_L2CAP_LE_CREATE_SOCKET:
5674 case BT_L2CAP_LE_REMOVE_SOCKET:
5675 case BT_L2CAP_LE_LISTEN_AND_ACCEPT:
5676 case BT_L2CAP_LE_ACCEPT_CONNECTION:
5677 case BT_L2CAP_LE_REJECT_CONNECTION:
5678 case BT_L2CAP_LE_LISTEN:
5680 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5681 BT_PRIVILEGE_PUBLIC);
5683 BT_INFO("Client Credentials [%s]", client_creds);
5684 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5685 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PUBLIC);
5689 /* Need to check mediastorage privilege */
5690 if (function_name == BT_PBAP_GET_PHONEBOOK ||
5691 function_name == BT_PBAP_PULL_VCARD) {
5692 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5693 MEDIASTORAGE_PRIVILEGE);
5695 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5696 BT_ERR("Fail to access: %s", MEDIASTORAGE_PRIVILEGE);
5702 case BT_ENABLE_ADAPTER:
5703 case BT_DISABLE_ADAPTER:
5704 case BT_RESET_ADAPTER:
5705 case BT_RECOVER_ADAPTER:
5706 case BT_BATTERY_READ_DATA:
5707 case BT_ENABLE_ADAPTER_LE:
5708 case BT_DISABLE_ADAPTER_LE:
5709 case BT_SET_CONNECTABLE:
5710 case BT_SET_DISCOVERABLE_MODE:
5711 case BT_ADD_ALLOW_LIST:
5712 case BT_REMOVE_ALLOW_LIST:
5713 case BT_CLEAR_ALLOW_LIST:
5714 case BT_SET_MANUFACTURER_DATA:
5716 case BT_CANCEL_SEARCH_SERVICE:
5717 case BT_ENABLE_RSSI:
5718 case BT_DISCONNECT_DEVICE:
5720 case BT_RFCOMM_ACCEPT_CONNECTION:
5721 case BT_RFCOMM_REJECT_CONNECTION:
5722 case BT_RFCOMM_LISTEN:
5724 case BT_HID_ENABLE_BARCODE_FEATURE:
5726 case BT_AVRCP_TRANSPORT_SET_PROPERTY:
5727 case BT_AVRCP_HANDLE_CONTROL_TO_DEST:
5729 case BT_SET_CONTENT_PROTECT:
5730 case BT_BOND_DEVICE_BY_TYPE:
5731 case BT_SET_LE_PRIVACY:
5732 case BT_SET_LE_STATIC_RANDOM_ADDRESS:
5733 case BT_LE_CONN_UPDATE:
5734 case BT_GET_DEVICE_IDA:
5735 case BT_LE_READ_MAXIMUM_DATA_LENGTH:
5736 case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH:
5737 case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH:
5738 case BT_LE_SET_DATA_LENGTH:
5739 case BT_LE_OOB_READ_LOCAL_DATA:
5740 case BT_LE_OOB_ADD_REMOTE_DATA:
5742 case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS:
5743 case BT_ENABLE_GATT_DATA_BATCHING:
5744 case BT_DISABLE_GATT_DATA_BATCHING:
5746 case BT_LE_IPSP_INIT:
5747 case BT_LE_IPSP_DEINIT:
5748 case BT_LE_IPSP_CONNECT:
5749 case BT_LE_IPSP_DISCONNECT:
5750 case BT_PXP_MONITOR_SET_PROPERTY:
5751 case BT_PXP_MONITOR_GET_PROPERTY:
5752 case BT_PXP_MONITOR_GET_SUPPORTED_SERIVCES:
5753 case BT_PXP_REPORTER_REGISTER:
5754 case BT_PXP_REPORTER_UNREGISTER:
5755 case BT_PXP_REPORTER_GET_PROPERTY:
5758 case BT_TDS_PROVIDER_REGISTER:
5759 case BT_TDS_PROVIDER_UNREGISTER:
5760 case BT_TDS_PROVIDER_SET_MANUF_DATA:
5761 case BT_TDS_PROVIDER_CREATE:
5762 case BT_TDS_PROVIDER_DESTROY:
5763 case BT_TDS_PROVIDER_SET_TRANSPORT_DATA:
5764 case BT_TDS_SEND_ACTIVATION_RESPONSE:
5765 case BT_TDS_READ_TRANSPORT_DATA:
5766 case BT_TDS_ENABLE_CONTROL_POINT:
5767 case BT_TDS_ACTIVATE_CONTROL_POINT:
5770 case BT_OTP_SERVER_INIT:
5771 case BT_OTP_SERVER_DEINIT:
5772 case BT_OTP_READ_VALUE:
5773 case BT_OTP_ENABLE_NOTIFICATION:
5774 case BT_OTP_WRITE_VALUE:
5775 case BT_LE_OTC_CONNECT:
5776 case BT_LE_OTC_DISCONNECT:
5778 case BT_MAP_CREATE_SESSION:
5779 case BT_MAP_DESTROY_SESSION:
5780 case BT_MAP_SET_FOLDER:
5781 case BT_MAP_LIST_FOLDERS:
5782 case BT_MAP_LIST_FILTER_FIELDS:
5783 case BT_MAP_LIST_MESSAGES:
5784 case BT_MAP_UPDATE_INBOX:
5785 case BT_MAP_PUSH_MESSAGE:
5786 case BT_MAP_GET_MESSAGE:
5789 case BT_MESH_DEINIT:
5790 case BT_MESH_NETWORK_CREATE:
5791 case BT_MESH_NETWORK_DESTROY:
5792 case BT_MESH_NETWORK_LOAD:
5793 case BT_MESH_NETWORK_UNLOAD:
5794 case BT_MESH_NETWORK_JOIN:
5795 case BT_MESH_CANCEL_JOIN:
5796 case BT_MESH_NETWORK_SCAN:
5797 case BT_MESH_NETWORK_CANCEL_SCAN:
5798 case BT_MESH_NETWORK_SET_CAPABILITIES:
5799 case BT_MESH_NETWORK_PROVISION_DEVICE:
5800 case BT_MESH_AUTHENTICATION_REPLY:
5801 case BT_MESH_NETWORK_SET_NAME:
5802 case BT_MESH_NETWORK_ADD_NETKEY:
5803 case BT_MESH_NETWORK_DELETE_NETKEY:
5804 case BT_MESH_NETWORK_UPDATE_NETKEY:
5805 case BT_MESH_NETWORK_ADD_APPKEY:
5806 case BT_MESH_NETWORK_DELETE_APPKEY:
5807 case BT_MESH_NETWORK_UPDATE_APPKEY:
5808 case BT_MESH_NETWORK_GET_NETKEYS:
5809 case BT_MESH_NETWORK_GET_APPKEYS:
5810 case BT_MESH_NETWORK_GET_NODES:
5811 case BT_MESH_ELEMENT_GET_MODELS:
5812 case BT_MESH_NODE_BROWSE:
5813 case BT_MESH_NODE_GET_VENDOR_FEATURES:
5814 case BT_MESH_NODE_CONFIGURE_KEY:
5815 case BT_MESH_NODE_TTL_EXECUTE:
5816 case BT_MESH_NODE_GET_NETKEYS:
5817 case BT_MESH_NODE_GET_APPKEYS:
5818 case BT_MESH_NODE_RESET:
5819 case BT_MESH_MODEL_CONFIGURE_APPKEY:
5820 case BT_MESH_MODEL_GET_APPKEY_LIST:
5821 case BT_MESH_MODEL_EXECUTE_MSG:
5822 case BT_MESH_MODEL_RESPONSE_MSG:
5823 case BT_MESH_NETWORK_CREATE_GROUP:
5824 case BT_MESH_NETWORK_REMOVE_GROUP:
5825 case BT_MESH_MODEL_CONFIG_GROUP_SUB:
5826 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB:
5827 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST:
5828 case BT_MESH_MODEL_SET_PUBLICATION:
5829 case BT_MESH_MODEL_GET_PUBLICATION:
5830 case BT_MESH_NETWORK_GET_GROUPS:
5832 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5833 BT_PRIVILEGE_PLATFORM);
5835 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5836 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PLATFORM);
5841 case BT_CHECK_ADAPTER:
5844 case BT_GET_LOCAL_NAME:
5845 case BT_GET_LOCAL_ADDRESS:
5846 case BT_GET_LOCAL_VERSION:
5847 case BT_IS_SERVICE_USED:
5848 case BT_GET_DISCOVERABLE_MODE:
5849 case BT_GET_DISCOVERABLE_TIME:
5850 case BT_IS_DISCOVERYING:
5851 case BT_IS_LE_DISCOVERYING:
5852 case BT_IS_CONNECTABLE:
5853 case BT_GET_CONNECTABLE:
5854 case BT_GET_BONDED_DEVICES:
5855 case BT_GET_PROFILE_CONNECTED_DEVICES:
5856 case BT_GET_BONDED_DEVICE:
5857 case BT_PASSKEY_REPLY:
5858 case BT_PASSKEY_CONFIRMATION_REPLY:
5859 case BT_GET_IS_ALIAS_SET:
5860 case BT_IS_DEVICE_CONNECTED:
5861 case BT_GET_CONNECTED_LINK_TYPE:
5862 case BT_SET_PROFILE_TRUSTED:
5863 case BT_GET_PROFILE_TRUSTED:
5864 case BT_GET_SPEAKER_GAIN:
5865 case BT_SET_SPEAKER_GAIN:
5866 case BT_RFCOMM_CLIENT_IS_CONNECTED:
5867 case BT_RFCOMM_IS_UUID_AVAILABLE:
5868 case BT_GET_ADVERTISING_DATA:
5869 case BT_GET_SCAN_RESPONSE_DATA:
5870 case BT_IS_ADVERTISING:
5871 case BT_IS_LE_2M_PHY_SUPPORTED:
5872 case BT_IS_LE_CODED_PHY_SUPPORTED:
5873 case BT_SET_SCANNING_ROLE:
5874 case BT_SET_SCANNING_PHY:
5875 case BT_IS_LE_EXTENDED_ADVERTISING_SUPPORTED:
5876 case BT_IS_LE_EXTENDED_SCAN_SUPPORTED:
5877 case BT_LE_MAX_ADVERTISING_DATA_LEN:
5878 case BT_REGISTER_SCAN_FILTER:
5879 case BT_IS_SCAN_FILTER_SUPPORTED:
5880 case BT_GET_ATT_MTU:
5882 case BT_OBEX_SERVER_ALLOCATE:
5883 case BT_OBEX_SERVER_DEALLOCATE:
5884 case BT_OBEX_SERVER_IS_ACTIVATED:
5885 case BT_OPP_GET_TRANSFER_PROGRESS:
5886 case BT_AVRCP_CONTROL_GET_PROPERTY:
5887 case BT_AVRCP_GET_TRACK_INFO:
5889 case BT_L2CAP_LE_IS_PSM_AVAILABLE:
5890 /* Non-privilege control */
5893 BT_ERR("Unknown function!");
5898 if (function_name >= BT_FUNC_MESH_BASE) {
5899 BT_INFO("MESH Function called");
5900 char app_id[256] = { 0, };
5902 if (BLUETOOTH_ERROR_NONE == __bt_service_get_requester_app_id(unique_name,
5903 app_id, sizeof(app_id))) {
5904 requester_unique_creds = g_strdup(app_id);
5906 BT_DBG("Requester app_id not found, use client creds");
5907 requester_unique_creds = g_strdup(client_creds);
5909 BT_DBG("Requester unique_creds: %s", requester_unique_creds);
5911 BT_INFO("Non MESH Function called client creds [%s]", client_creds);
5923 GDBusNodeInfo *__bt_service_create_method_node_info
5924 (const gchar *introspection_data)
5927 GDBusNodeInfo *node_info = NULL;
5929 if (introspection_data == NULL) {
5930 BT_ERR("Introspection XML not present");
5934 node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
5937 BT_ERR("Unable to create node: %s", err->message);
5938 g_clear_error(&err);
5943 int __bt_service_register_object(GDBusConnection *conn,
5944 GDBusNodeInfo *node_info, gboolean reg)
5946 static guint service_id = 0;
5947 GError *error = NULL;
5950 if (node_info == NULL)
5953 service_id = g_dbus_connection_register_object(conn,
5955 node_info->interfaces[0],
5957 NULL, NULL, &error);
5958 if (service_id == 0)
5961 if (service_id > 0) {
5962 g_dbus_connection_unregister_object(conn,
5971 static void __name_owner_changed(GDBusConnection *connection,
5972 const gchar *sender_name,
5973 const gchar *object_path,
5974 const gchar *interface_name,
5975 const gchar *signal_name,
5976 GVariant *parameters,
5979 const char *name = NULL;
5980 const char *old_owner = NULL;
5981 const char *new_owner = NULL;
5983 g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
5984 if (new_owner && *new_owner != '\0')
5987 _bt_check_hdp_app_termination(name);
5989 /* Advertising App Termination */
5990 _bt_check_adv_app_termination(name);
5992 /* Check if le_scanning app is terminated */
5993 _bt_check_le_scanner_app_termination(name);
5995 /* Check if RFCOMM app is terminated */
5996 _bt_rfcomm_check_termination(name);
5998 /* Mesh App Termination */
5999 _bt_check_mesh_app_termination(name);
6001 /* Stop the Transport Discovery service */
6002 _bt_tds_stop_by_terminated_process(name);
6004 #ifdef TIZEN_FEATURE_BT_CONTAINER
6005 /* Cleanup the NSpid list */
6006 __bt_service_cleanup_nspid_list(name);
6010 static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
6011 const gchar *name, gpointer user_data)
6013 GDBusNodeInfo *node_info = NULL;
6015 BT_INFO("bus acquired");
6017 ret_if(connection == NULL);
6019 node_info = __bt_service_create_method_node_info(
6020 bt_service_introspection_xml);
6021 ret_if(node_info == NULL);
6023 __bt_service_register_object(connection, node_info, TRUE);
6024 g_dbus_node_info_unref(node_info);
6026 bt_service_conn = connection;
6029 static void __bt_service_name_acquired_handler(GDBusConnection *connection,
6030 const gchar *name, gpointer user_data)
6032 BT_INFO("name acquired");
6033 name_acquired = TRUE;
6035 #ifdef TIZEN_FEATURE_BT_CONTAINER
6036 if (_bt_service_is_container() == TRUE)
6037 __bt_service_bus_acquired_handler(connection, name, user_data);
6041 static void __bt_service_name_lost_handler(GDBusConnection *connection,
6042 const gchar *name, gpointer user_data)
6044 BT_INFO("name lost");
6045 name_acquired = FALSE;
6048 gboolean _is_name_acquired(void)
6050 return name_acquired;
6053 void _bt_service_unref_connection(void)
6057 if (bt_service_conn) {
6058 g_dbus_connection_flush_sync(bt_service_conn, NULL, NULL);
6059 g_object_unref(bt_service_conn);
6060 bt_service_conn = NULL;
6066 int _bt_service_register(void)
6068 GDBusConnection *conn;
6071 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
6072 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
6073 bt_service_conn = conn;
6075 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
6077 G_BUS_NAME_OWNER_FLAGS_NONE,
6078 __bt_service_bus_acquired_handler,
6079 __bt_service_name_acquired_handler,
6080 __bt_service_name_lost_handler,
6082 BT_DBG("owner_id is [%d]", owner_id);
6086 /* Subscribe for name owner changed signal */
6087 owner_sig_id = g_dbus_connection_signal_subscribe(conn,
6088 BT_FREEDESKTOP_SERVICE, BT_FREEDESKTOP_INTERFACE,
6089 BT_NAME_OWNER_CHANGED, NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
6090 __name_owner_changed, NULL, NULL);
6091 BT_INFO("owner_sig_id: %d", owner_sig_id);
6093 return BLUETOOTH_ERROR_NONE;
6096 if (bt_service_conn) {
6097 g_object_unref(bt_service_conn);
6098 bt_service_conn = NULL;
6101 return BLUETOOTH_ERROR_INTERNAL;
6104 #ifdef TIZEN_FEATURE_BT_CONTAINER
6105 int _bt_service_register_in_container(void)
6107 GDBusConnection *conn;
6110 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
6111 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
6113 /* Register dbus name because systemd will down bt-service
6114 * if we don't reigster the dbus name in container */
6115 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
6117 G_BUS_NAME_OWNER_FLAGS_NONE,
6118 NULL, NULL, NULL, NULL, NULL);
6119 BT_DBG("owner_id is [%d]", owner_id);
6123 conn = g_dbus_connection_new_for_address_sync(
6124 DBUS_HOST_SYSTEM_BUS_ADDRESS,
6125 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
6127 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
6128 bt_service_conn = conn;
6130 /* Register to host dbus connection to call
6131 * the method toward container in host bt-service */
6132 owner_id = g_bus_own_name_on_connection(conn,
6133 BT_SERVICE_CONTAINER_NAME,
6134 G_BUS_NAME_OWNER_FLAGS_NONE,
6135 __bt_service_name_acquired_handler,
6136 __bt_service_name_lost_handler,
6138 BT_DBG("owner_id is [%d]", owner_id);
6142 return BLUETOOTH_ERROR_NONE;
6145 if (bt_service_conn) {
6146 g_object_unref(bt_service_conn);
6147 bt_service_conn = NULL;
6150 return BLUETOOTH_ERROR_INTERNAL;
6154 void _bt_service_unregister(void)
6156 if (bt_service_conn) {
6157 sd_notify(0, "STOPPING=1");
6159 if (owner_sig_id > 0) {
6160 g_dbus_connection_signal_unsubscribe(
6161 bt_service_conn, owner_sig_id);
6166 g_bus_unown_name(owner_id);
6170 __bt_service_register_object(bt_service_conn, NULL, FALSE);
6173 #ifdef TIZEN_FEATURE_BT_CONTAINER
6175 g_slist_free_full(nspid_list, (GDestroyNotify)__bt_service_free_nspid);
6181 int _bt_service_cynara_init(void)
6184 char err_msg[256] = {0, };
6186 retv_if(p_cynara != NULL, BLUETOOTH_ERROR_ALREADY_INITIALIZED);
6188 result = cynara_initialize(&p_cynara, conf);
6190 if (result != CYNARA_API_SUCCESS) {
6191 cynara_strerror(result, err_msg, sizeof(err_msg));
6192 BT_ERR("Fail to initialize cynara: [%s]", err_msg);
6193 return BLUETOOTH_ERROR_INTERNAL;
6196 return BLUETOOTH_ERROR_NONE;
6199 void _bt_service_cynara_deinit(void)
6202 char err_msg[256] = {0, };
6204 ret_if(p_cynara == NULL);
6206 result = cynara_finish(p_cynara);
6208 if (result != CYNARA_API_SUCCESS) {
6209 cynara_strerror(result, err_msg, sizeof(err_msg));
6210 BT_ERR("Fail to finish cynara: [%s]", err_msg);
6218 void _bt_service_method_return(GDBusMethodInvocation *invocation,
6219 GArray *out_param, int result)
6223 out_var = g_variant_new_from_data((const GVariantType *)"ay",
6224 out_param->data, out_param->len, TRUE, NULL, NULL);
6226 g_dbus_method_invocation_return_value(invocation,
6227 g_variant_new("(iv)", result, out_var));
6230 void _bt_service_method_return_with_unix_fd_list(GDBusMethodInvocation *invocation,
6231 GArray *out_param, int result, GUnixFDList *fd_list)
6235 out_var = g_variant_new_from_data((const GVariantType *)"ay",
6236 out_param->data, out_param->len, TRUE, NULL, NULL);
6238 g_dbus_method_invocation_return_value_with_unix_fd_list(invocation,
6239 g_variant_new("(iv)", result, out_var), fd_list);