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>
28 #include "bluetooth-api.h"
29 #include "bluetooth-audio-api.h"
30 #include "bluetooth-gatt-server-api.h"
31 #include "bluetooth-mesh-api.h"
32 #include "bt-request-handler.h"
33 #include "bt-service-common.h"
34 #include "bt-service-util.h"
36 #include "bt-service-core-adapter.h"
37 #include "bt-service-core-adapter-le.h"
38 #include "bt-service-core-device.h"
40 #include "bt-service-audio-common.h"
41 #include "bt-service-avrcp-tg.h"
42 #include "bt-service-avrcp-ctrl.h"
43 #include "bt-service-gatt.h"
44 #include "bt-service-mesh-util.h"
45 #include "bt-service-mesh-network.h"
47 #ifdef TIZEN_FEATURE_BT_DPM
48 #include "bt-service-dpm.h"
50 #include "bt-service-hidhost.h"
51 #include "bt-service-rfcomm.h"
52 #include "bt-service-hdp.h"
55 #include "bt-service-obex-server.h"
56 #include "bt-service-opp-client.h"
57 #include "bt-service-map-client.h"
58 #include "bt-service-pbap.h"
59 #include "bt-service-oob.h"
61 #include "bt-service-battery-monitor.h"
63 #ifdef TIZEN_FEATURE_BT_PAN_NAP
64 #include "bt-service-network.h"
67 #ifdef TIZEN_FEATURE_BT_IPSP
68 #include "bt-service-ipsp.h"
70 /* For maintaining Application Sync API call requests */
71 GSList *invocation_list = NULL;
73 static GDBusConnection *bt_service_conn;
74 static guint owner_id = 0;
75 static guint owner_sig_id = 0;
76 static gboolean is_le_intended = FALSE;
78 static cynara *p_cynara;
79 static cynara_configuration *conf;
80 const char *requester_unique_creds = NULL;
82 static const gchar bt_service_introspection_xml[] =
83 "<node name='/org/projectx/bt_service'>"
84 " <interface name='org.projectx.bt'>"
85 " <method name='service_request'>"
86 /* Input Parameters */
87 " <arg type='i' name='service_type' direction='in' />"
88 " <arg type='i' name='service_function' direction='in' />"
89 " <arg type='i' name='request_type' direction='in' />"
90 " <arg type='ay' name='input_param1' direction='in' />"
91 " <arg type='ay' name='input_param2' direction='in' />"
92 " <arg type='ay' name='input_param3' direction='in' />"
93 " <arg type='ay' name='input_param4' direction='in' />"
94 " <arg type='ay' name='input_param5' direction='in' />"
95 /* Return Parameters */
96 " <arg type='i' name='output_param1' direction='out' />"
97 " <arg type='v' name='output_param2' direction='out' />"
99 #ifdef TIZEN_FEATURE_BT_AVC_TARGET
100 " <method name='get_avc_mode'>"
102 " <arg type='u' name='avc_mode' direction='out' />"
108 static gboolean name_acquired = FALSE;
110 static char *current_sender_playing = NULL;
112 GDBusNodeInfo *node_info_g = NULL;
114 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param);
116 static void __bt_service_method(GDBusConnection *connection,
118 const gchar *object_path,
119 const gchar *interface_name,
120 const gchar *method_name,
121 GVariant *parameters,
122 GDBusMethodInvocation *invocation,
125 int __bt_bluez_request(int function_name,
128 GDBusMethodInvocation *context,
133 GArray **out_param1);
134 int __bt_obexd_request(int function_name,
137 GDBusMethodInvocation *context,
142 GArray **out_param1);
143 int __bt_agent_request(int function_name,
146 GDBusMethodInvocation *context,
151 GArray **out_param1);
152 int __bt_core_request(int function_name,
155 GDBusMethodInvocation *context,
156 GVariant *in_param1);
158 gboolean __bt_service_check_privilege(int function_name,
160 const char *unique_name);
162 /* Function definitions*/
163 GSList *_bt_get_invocation_list(void)
165 return invocation_list;
168 void _bt_free_info_from_invocation_list(invocation_info_t *req_info)
170 ret_if(NULL == req_info);
171 invocation_list = g_slist_remove(invocation_list, req_info);
172 g_free(req_info->sender);
173 g_free(req_info->user_data);
177 void _bt_set_le_intended_status(gboolean value)
179 is_le_intended = value;
182 static void __bt_service_get_parameters(GVariant *in_param,
183 void *value, int size)
186 buf = (void *)g_variant_get_data(in_param);
187 memcpy(value, buf, size);
190 static gboolean __bt_is_sync_function(int service_function)
192 /*TODO: Keep adding sync methods with expect replies from bluetooth service */
193 if (service_function == BT_GET_LOCAL_ADDRESS
194 || service_function == BT_GET_LOCAL_NAME
195 || service_function == BT_GET_LOCAL_VERSION
196 || service_function == BT_GET_BONDED_DEVICES
197 || service_function == BT_GET_BONDED_DEVICE
198 || service_function == BT_GET_PROFILE_CONNECTED_DEVICES
199 || service_function == BT_GET_IS_ALIAS_SET
200 || service_function == BT_GET_CONNECTED_LINK_TYPE
201 || service_function == BT_IS_SERVICE_USED
202 || service_function == BT_RFCOMM_LISTEN_AND_ACCEPT
203 || service_function == BT_RFCOMM_LISTEN
204 || service_function == BT_HDP_REGISTER_SINK_APP
205 || service_function == BT_HDP_UNREGISTER_SINK_APP
206 || service_function == BT_HDP_GET_FD
207 || service_function == BT_AVRCP_GET_TRACK_INFO
208 || service_function == BT_AVRCP_CONTROL_GET_PROPERTY
209 || service_function == BT_SET_ADVERTISING_DATA
210 || service_function == BT_SET_SCAN_RESPONSE_DATA
211 || service_function == BT_SET_ADVERTISING
212 || service_function == BT_SET_CUSTOM_ADVERTISING
213 || service_function == BT_GATT_SERVER_REGISTER
214 || service_function == BT_GATT_SERVER_ADD_SERVICE
215 || service_function == BT_GATT_SERVER_ADD_CHARACTERISTIC
216 || service_function == BT_GATT_SERVER_ADD_DESCRIPTOR
217 || service_function == BT_GATT_SERVER_START_SERVICE
218 || service_function == BT_GATT_SERVER_STOP_SERVICE
219 || service_function == BT_GATT_SERVER_DELETE_SERVICE
220 || service_function == BT_START_LE_DISCOVERY
221 || service_function == BT_STOP_LE_DISCOVERY
222 || service_function == BT_GET_CONNECTABLE
223 #ifdef TIZEN_GATT_CLIENT
224 || service_function == BT_GATT_CLIENT_REGISTER
225 || service_function == BT_GATT_GET_PRIMARY_SERVICES
226 || service_function == BT_GATT_GET_SERVICE_PROPERTIES
227 || service_function == BT_GATT_GET_INCLUDED_SERVICES
228 || service_function == BT_GATT_GET_CHARACTERISTIC_PROPERTIES
229 || service_function == BT_GATT_WATCH_CHARACTERISTIC
230 || service_function == BT_GATT_ACQUIRE_WRITE
232 || service_function == BT_AUDIO_SELECT_ROLE
234 || service_function == BT_MESH_NETWORK_CREATE
235 || service_function == BT_MESH_NETWORK_SCAN
236 || service_function == BT_MESH_NETWORK_ADD_NETKEY
237 || service_function == BT_MESH_NETWORK_DELETE_NETKEY
238 || service_function == BT_MESH_NETWORK_UPDATE_NETKEY
239 || service_function == BT_MESH_NETWORK_ADD_APPKEY
240 || service_function == BT_MESH_NETWORK_DELETE_APPKEY
241 || service_function == BT_MESH_NETWORK_UPDATE_APPKEY)
247 void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
248 char *sender, int service_function,
249 gpointer invocation_data)
251 invocation_info_t *info;
252 info = g_malloc0(sizeof(invocation_info_t));
253 info->context = invocation;
254 info->result = result;
255 info->sender = g_strdup(sender);
256 info->service_function = service_function;
257 info->user_data = invocation_data;
258 invocation_list = g_slist_append(invocation_list, info);
262 static int __bt_service_get_sender_pid(const char *unique_name, pid_t *pid)
265 char err_msg[256] = {0, };
267 retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
269 ret = cynara_creds_gdbus_get_pid(bt_service_conn, unique_name, pid);
270 if (ret != CYNARA_API_SUCCESS) {
271 cynara_strerror(ret, err_msg, sizeof(err_msg));
272 BT_ERR("Fail to get user credential: %s", err_msg);
274 return BLUETOOTH_ERROR_INTERNAL;
277 return BLUETOOTH_ERROR_NONE;
280 static int __bt_bm_request_data(_bt_battery_data_t *latest)
282 int ret = _bt_bm_read_data(latest);
283 if (ret == BLUETOOTH_ERROR_NONE) {
284 BT_DBG("Received data from bluetooth battery monitor: %ld %ld %d %d",
285 latest->session_start_time, latest->session_end_time,
286 latest->session_scan_time, latest->session_connected_time);
288 if (latest->atm_list == NULL) {
289 BT_DBG("No app data transaction for this session");
293 for (GSList *l = latest->atm_list; l != NULL; l = g_slist_next(l)) {
294 _bt_battery_app_data_t *t = (_bt_battery_app_data_t *)(l->data);
295 BT_DBG("%ld %ld %d %d", (long int)(t->uid), (long int)(t->pid), t->rx_bytes, t->tx_bytes);
299 BT_ERR("Error encountered");
303 static void __bt_service_method(GDBusConnection *connection,
305 const gchar *object_path,
306 const gchar *interface_name,
307 const gchar *method_name,
308 GVariant *parameters,
309 GDBusMethodInvocation *invocation,
314 BT_DBG("Method[%s] Object Path[%s] Interface Name[%s]",
315 method_name, object_path, interface_name);
317 if (g_strcmp0(method_name, "service_request") == 0) {
319 int service_function;
321 GVariant *param1 = NULL;
322 GVariant *param2 = NULL;
323 GVariant *param3 = NULL;
324 GVariant *param4 = NULL;
325 GVariant *param5 = NULL;
326 GArray *out_param1 = NULL;
327 GVariant *out_var = NULL;
328 GVariant *temp = NULL;
332 g_variant_get(parameters, "(iii@ay@ay@ay@ay@ay)", &service_type,
333 &service_function, &request_type,
334 ¶m1, ¶m2, ¶m3, ¶m4, ¶m5);
336 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
338 if (service_type == BT_CORE_SERVICE) {
339 BT_DBG("No need to check privilege from bt-core");
340 } else if (__bt_service_check_privilege(service_function,
341 service_type, (const char *)sender) == FALSE) {
342 BT_ERR("Client don't have the privilege to excute this function");
343 result = BLUETOOTH_ERROR_PERMISSION_DEINED;
347 BT_DBG("SERVICE TYPE [%d] SERVICE FUNC [%d]",
348 service_type, service_function);
349 switch (service_type) {
350 case BT_BLUEZ_SERVICE:
351 result = __bt_bluez_request(service_function,
352 request_type, request_id,
353 invocation, param1, param2,
354 param3, param4, &out_param1);
356 case BT_OBEX_SERVICE:
357 result = __bt_obexd_request(service_function,
358 request_type, request_id,
361 param4, &out_param1);
363 case BT_AGENT_SERVICE:
364 result = __bt_agent_request(service_function,
365 request_type, request_id,
368 param4, &out_param1);
370 case BT_CORE_SERVICE:
371 result = __bt_core_request(service_function,
372 request_type, request_id,
375 case BT_CHECK_PRIVILEGE:
376 result = BLUETOOTH_ERROR_NONE;
379 BT_ERR("Unknown service type");
380 result = BLUETOOTH_ERROR_INTERNAL;
384 if (result != BLUETOOTH_ERROR_NONE)
387 if (service_type == BT_CHECK_PRIVILEGE)
390 if (service_function == BT_OPP_PUSH_FILES)
393 if (request_type == BT_ASYNC_REQ ||
394 __bt_is_sync_function(service_function)) {
395 /* Do not send reply to bt-api over dbus,
396 Invocation context is already saved in service_function */
401 out_var = g_variant_new_from_data((const GVariantType *)"ay",
402 out_param1->data, out_param1->len,
405 temp = g_variant_new("(iv)", result, out_var);
406 g_dbus_method_invocation_return_value(invocation, temp);
407 g_array_free(out_param1, TRUE);
411 g_variant_unref(param1);
412 g_variant_unref(param2);
413 g_variant_unref(param3);
414 g_variant_unref(param4);
415 g_variant_unref(param5);
419 BT_ERR_C("Request is failed [%s] [0x%x]",
420 _bt_convert_error_to_string(result), result);
422 out_var = g_variant_new_from_data((const GVariantType *)"ay",
423 out_param1->data, out_param1->len,
426 temp = g_variant_new("(iv)", result, out_var);
427 g_dbus_method_invocation_return_value(invocation, temp);
429 g_array_free(out_param1, TRUE);
432 g_variant_unref(param1);
433 g_variant_unref(param2);
434 g_variant_unref(param3);
435 g_variant_unref(param4);
436 g_variant_unref(param5);
438 #ifdef TIZEN_FEATURE_BT_AVC_TARGET
439 else if (g_strcmp0(method_name, "get_avc_mode") == 0) {
440 unsigned int mode = 0;
442 if (_bt_audio_get_avc_mode(&mode) != BLUETOOTH_ERROR_NONE)
443 BT_ERR("Fail to get the avc mode");
445 BT_DBG("Absolute Volume Control mode: %d", mode);
447 g_dbus_method_invocation_return_value(invocation,
448 g_variant_new("(u)", mode));
457 static const GDBusInterfaceVTable method_table = {
464 int __bt_bluez_request(int function_name,
467 GDBusMethodInvocation *context,
474 int result = BLUETOOTH_ERROR_NONE;
477 switch (function_name) {
478 case BT_ENABLE_ADAPTER: {
479 result = _bt_enable_adapter();
480 _bt_adapter_start_enable_timer();
483 case BT_DISABLE_ADAPTER: {
484 result = _bt_disable_adapter();
487 case BT_RECOVER_ADAPTER:
488 result = _bt_recover_adapter();
490 case BT_RESET_ADAPTER:
491 result = _bt_reset_adapter();
493 case BT_BATTERY_READ_DATA: {
494 _bt_battery_data_t *data = NULL;
495 data = g_malloc0(sizeof(_bt_battery_data_t));
496 result = __bt_bm_request_data(data);
498 bt_battery_dbus_data_t dbus_data;
499 memset(&dbus_data, 0, sizeof(bt_battery_dbus_data_t));
500 dbus_data.session_start_time = data->session_start_time;
501 dbus_data.session_end_time = data->session_end_time;
502 dbus_data.session_scan_time = data->session_scan_time;
503 dbus_data.session_connected_time = data->session_connected_time;
504 dbus_data.tx_time = data->tx_time;
505 dbus_data.rx_time = data->rx_time;
506 dbus_data.idle_time = data->idle_time;
508 /*Populating app data*/
510 for (GSList *l = data->atm_list; l != NULL; l = g_slist_next(l)) {
511 bt_battery_app_data *t = (bt_battery_app_data *)(l->data);
512 memcpy(&dbus_data.app_data[n], t, sizeof(bt_battery_app_data));
515 dbus_data.num_app = n;
516 g_array_append_vals(*out_param1, &dbus_data, sizeof(bt_battery_dbus_data_t));
517 g_slist_free_full(data->atm_list, g_free);
522 case BT_CHECK_ADAPTER: {
523 int enabled = BT_ADAPTER_DISABLED;
524 result = _bt_check_adapter(&enabled);
526 g_array_append_vals(*out_param1, &enabled,
530 case BT_ENABLE_ADAPTER_LE:
531 _bt_set_le_intended_status(TRUE);
532 result = _bt_enable_adapter_le();
534 case BT_DISABLE_ADAPTER_LE:
535 _bt_set_le_intended_status(FALSE);
536 result = _bt_disable_adapter_le();
538 case BT_START_DISCOVERY: {
539 unsigned short max_response;
540 unsigned short discovery_duration;
541 unsigned int classOfDeviceMask;
544 __bt_service_get_parameters(in_param1,
545 &max_response, sizeof(unsigned short));
546 __bt_service_get_parameters(in_param2,
547 &discovery_duration, sizeof(unsigned short));
548 __bt_service_get_parameters(in_param3,
549 &classOfDeviceMask, sizeof(unsigned int));
550 __bt_service_get_parameters(in_param4, &uid, sizeof(uid_t));
552 result = _bt_start_discovery(max_response, discovery_duration, classOfDeviceMask);
554 if (result == BLUETOOTH_ERROR_NONE) {
557 sender = (char*)g_dbus_method_invocation_get_sender(context);
559 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
560 BT_ERR("Fail to get the sender pid");
562 BT_DBG("Remeber pid / uid for the scan operation");
563 _bt_bm_add_scan_app(SCAN_REGACY, uid, pid);
568 case BT_START_CUSTOM_DISCOVERY: {
569 bt_discovery_role_type_t role;
571 __bt_service_get_parameters(in_param1,
572 &role, sizeof(bt_discovery_role_type_t));
573 result = _bt_start_custom_discovery(role);
577 case BT_CANCEL_DISCOVERY:
578 result = _bt_cancel_discovery();
580 case BT_IS_DISCOVERYING: {
581 gboolean discovering = FALSE;
582 discovering = _bt_is_discovering();
583 g_array_append_vals(*out_param1,
584 &discovering, sizeof(gboolean));
587 case BT_GET_LOCAL_ADDRESS: {
588 result = _bt_get_local_address();
590 /* Save invocation */
591 if (result == BLUETOOTH_ERROR_NONE) {
592 sender = (char*)g_dbus_method_invocation_get_sender(context);
593 _bt_save_invocation_context(context, result, sender,
594 function_name, NULL);
598 case BT_GET_LOCAL_VERSION: {
599 result = _bt_get_local_version();
601 /* Save invocation */
602 if (result == BLUETOOTH_ERROR_NONE) {
603 sender = (char*)g_dbus_method_invocation_get_sender(context);
604 _bt_save_invocation_context(context, result, sender,
605 function_name, NULL);
609 case BT_GET_LOCAL_NAME: {
610 result = _bt_get_local_name();
612 /* Save invocation */
613 if (result == BLUETOOTH_ERROR_NONE) {
614 sender = (char*)g_dbus_method_invocation_get_sender(context);
615 _bt_save_invocation_context(context, result, sender,
616 function_name, NULL);
620 case BT_SET_LOCAL_NAME: {
621 bluetooth_device_name_t local_name = { {0} };
622 __bt_service_get_parameters(in_param1,
623 &local_name, sizeof(bluetooth_device_name_t));
624 result = _bt_set_local_name(local_name.name);
627 case BT_GET_DISCOVERABLE_MODE: {
628 int discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
629 result = _bt_get_discoverable_mode(&discoverable_mode);
630 g_array_append_vals(*out_param1, &discoverable_mode, sizeof(int));
633 case BT_GET_DISCOVERABLE_TIME: {
636 result = _bt_get_timeout_value(&timeout);
637 g_array_append_vals(*out_param1, &timeout, sizeof(int));
640 case BT_SET_DISCOVERABLE_MODE: {
641 int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
644 __bt_service_get_parameters(in_param1, &mode, sizeof(int));
645 __bt_service_get_parameters(in_param2, &time, sizeof(int));
647 result = _bt_set_discoverable_mode(mode, time);
650 case BT_IS_CONNECTABLE: {
651 gboolean is_connectable = FALSE;
653 is_connectable = _bt_is_connectable();
654 g_array_append_vals(*out_param1, &is_connectable, sizeof(gboolean));
657 case BT_GET_CONNECTABLE: {
658 result = _bt_get_connectable();
660 /* Save invocation */
661 if (result == BLUETOOTH_ERROR_NONE) {
662 sender = (char*)g_dbus_method_invocation_get_sender(context);
663 _bt_save_invocation_context(context, result, sender,
664 function_name, NULL);
668 case BT_SET_CONNECTABLE: {
669 gboolean is_connectable;
671 __bt_service_get_parameters(in_param1,
672 &is_connectable, sizeof(gboolean));
673 result = _bt_set_connectable(is_connectable);
676 case BT_IS_SERVICE_USED: {
679 uuid = (char *)g_variant_get_data(in_param1);
680 BT_INFO("UUID to be searched [%s]", uuid);
681 result = _bt_is_service_used();
683 /* Save invocation */
684 if (result == BLUETOOTH_ERROR_NONE) {
685 sender = (char*)g_dbus_method_invocation_get_sender(context);
686 _bt_save_invocation_context(context, result, sender,
687 function_name, g_strdup(uuid));
691 case BT_GET_BONDED_DEVICES: {
692 result = _bt_get_bonded_devices();
693 /* Save invocation */
694 if (result == BLUETOOTH_ERROR_NONE) {
695 sender = (char*)g_dbus_method_invocation_get_sender(context);
696 _bt_save_invocation_context(context, result, sender,
697 function_name, NULL);
701 case BT_GET_BONDED_DEVICE: {
702 bluetooth_device_address_t address = { {0} };
704 __bt_service_get_parameters(in_param1,
705 &address, sizeof(bluetooth_device_address_t));
707 result = _bt_get_bonded_device_info(&address);
708 /* Save invocation */
709 if (result == BLUETOOTH_ERROR_NONE) {
710 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
712 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
716 _bt_convert_addr_type_to_string(addr, address.addr);
717 sender = (char*)g_dbus_method_invocation_get_sender(context);
718 _bt_save_invocation_context(context, result, sender,
719 function_name, addr);
723 case BT_GET_PROFILE_CONNECTED_DEVICES: {
725 uuid = (char *)g_variant_get_data(in_param1);
726 result = _bt_get_profile_connected_devices(uuid);
728 /* Save invocation */
729 if (result == BLUETOOTH_ERROR_NONE) {
730 sender = (char *)g_dbus_method_invocation_get_sender(context);
731 _bt_save_invocation_context(context, result, sender,
732 function_name, NULL);
737 bluetooth_device_address_t address = { {0} };
738 const char *local_name;
740 __bt_service_get_parameters(in_param1,
741 &address, sizeof(bluetooth_device_address_t));
742 local_name = (const char *)g_variant_get_data(in_param2);
744 result = _bt_set_alias(&address, local_name);
747 case BT_BOND_DEVICE: {
748 bluetooth_device_address_t address = { {0} };
750 __bt_service_get_parameters(in_param1,
751 &address, sizeof(bluetooth_device_address_t));
752 result = _bt_bond_device(&address, BLUETOOTH_DEV_CONN_DEFAULT, out_param1);
754 /* Save invocation */
755 if (result == BLUETOOTH_ERROR_NONE) {
756 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
757 _bt_convert_addr_type_to_string(addr, address.addr);
758 sender = (char*)g_dbus_method_invocation_get_sender(context);
759 _bt_save_invocation_context(context, result, sender,
760 function_name, (gpointer)addr);
762 bluetooth_device_info_t dev_info;
764 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
765 memcpy(&dev_info.device_address, &address,
766 sizeof(bluetooth_device_address_t));
767 g_array_append_vals(*out_param1, &dev_info,
768 sizeof(bluetooth_device_info_t));
772 case BT_BOND_DEVICE_BY_TYPE: {
773 bluetooth_device_address_t address = { {0} };
774 unsigned short conn_type = 0;
776 __bt_service_get_parameters(in_param1,
777 &address, sizeof(bluetooth_device_address_t));
778 __bt_service_get_parameters(in_param2,
779 &conn_type, sizeof(unsigned short));
781 result = _bt_bond_device(&address, conn_type, out_param1);
782 /* Save invocation */
783 if (result == BLUETOOTH_ERROR_NONE) {
784 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
785 _bt_convert_addr_type_to_string(addr, address.addr);
786 sender = (char*)g_dbus_method_invocation_get_sender(context);
787 _bt_save_invocation_context(context, result, sender,
788 function_name, (gpointer)addr);
790 bluetooth_device_info_t dev_info;
792 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
793 memcpy(&dev_info.device_address, &address,
794 sizeof(bluetooth_device_address_t));
795 g_array_append_vals(*out_param1, &dev_info,
796 sizeof(bluetooth_device_info_t));
800 case BT_UNBOND_DEVICE: {
801 bluetooth_device_address_t address = { {0} };
803 __bt_service_get_parameters(in_param1,
804 &address, sizeof(bluetooth_device_address_t));
805 result = _bt_unbond_device(&address, out_param1);
807 /* Save invocation */
808 if (result == BLUETOOTH_ERROR_NONE) {
809 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
810 _bt_convert_addr_type_to_string(addr, address.addr);
811 sender = (char*)g_dbus_method_invocation_get_sender(context);
812 _bt_save_invocation_context(context, result, sender,
813 function_name, (gpointer)addr);
815 g_array_append_vals(*out_param1, &address,
816 sizeof(bluetooth_device_address_t));
820 case BT_CANCEL_BONDING:{
821 result = _bt_cancel_bonding();
824 case BT_SEARCH_SERVICE: {
825 bluetooth_device_address_t address = { {0} };
826 __bt_service_get_parameters(in_param1,
827 &address, sizeof(bluetooth_device_address_t));
828 result = _bt_search_device(&address);
829 /* Save invocation */
830 if (result == BLUETOOTH_ERROR_NONE) {
831 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
832 _bt_convert_addr_type_to_string(addr, address.addr);
833 sender = (char*)g_dbus_method_invocation_get_sender(context);
834 _bt_save_invocation_context(context, result, sender,
835 function_name, (gpointer)addr);
837 bt_sdp_info_t sdp_info;
839 memset(&sdp_info, 0x00, sizeof(bt_sdp_info_t));
840 memcpy(&sdp_info.device_addr, &address,
841 sizeof(bluetooth_device_address_t));
842 g_array_append_vals(*out_param1, &sdp_info, sizeof(bt_sdp_info_t));
846 case BT_CANCEL_SEARCH_SERVICE: {
847 result = _bt_cancel_search_device();
850 case BT_SET_PASSKEY_NOTIFICATION: {
854 sender = (char *)g_dbus_method_invocation_get_sender(context);
855 __bt_service_get_parameters(in_param1,
856 &enable, sizeof(gboolean));
858 result = _bt_set_passkey_notification(sender, enable);
861 case BT_SET_PIN_CODE: {
862 bluetooth_device_address_t address = { {0} };
863 bluetooth_device_pin_code_t pin_code = { {0} };
865 __bt_service_get_parameters(in_param1,
866 &address, sizeof(bluetooth_device_address_t));
867 __bt_service_get_parameters(in_param2,
868 &pin_code, sizeof(bluetooth_device_pin_code_t));
870 result = _bt_set_pin_code(&address, &pin_code);
873 case BT_UNSET_PIN_CODE: {
874 bluetooth_device_address_t address = { {0} };
876 __bt_service_get_parameters(in_param1,
877 &address, sizeof(bluetooth_device_address_t));
879 result = _bt_unset_pin_code(&address);
882 case BT_PASSKEY_REPLY: {
883 const char *passkey = NULL;
884 gboolean authentication_reply = FALSE;
885 passkey = g_variant_get_data(in_param1);
886 __bt_service_get_parameters(in_param2,
887 &authentication_reply, sizeof(gboolean));
888 result = _bt_passkey_reply(passkey, authentication_reply);
891 case BT_PASSKEY_CONFIRMATION_REPLY: {
892 gboolean confirmation_reply = FALSE;
893 __bt_service_get_parameters(in_param1,
894 &confirmation_reply, sizeof(gboolean));
895 result = _bt_passkey_confirmation_reply(confirmation_reply);
898 case BT_GET_IS_ALIAS_SET: {
899 bluetooth_device_address_t address = { {0} };
901 __bt_service_get_parameters(in_param1,
902 &address, sizeof(bluetooth_device_address_t));
904 result = _bt_is_alias_set(&address);
905 if (result == BLUETOOTH_ERROR_NONE) {
906 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
908 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
912 _bt_convert_addr_type_to_string(addr, address.addr);
913 sender = (char*)g_dbus_method_invocation_get_sender(context);
914 _bt_save_invocation_context(context, result, sender,
915 function_name, addr);
919 case BT_SET_AUTHORIZATION: {
920 bluetooth_device_address_t address = { {0} };
922 __bt_service_get_parameters(in_param1,
923 &address, sizeof(bluetooth_device_address_t));
924 __bt_service_get_parameters(in_param2,
925 &authorize, sizeof(gboolean));
926 result = _bt_set_authorization(&address, authorize);
929 case BT_SET_LE_PRIVACY: {
930 gboolean set_privacy;
931 __bt_service_get_parameters(in_param1, &set_privacy,
933 result = _bt_set_le_privacy(set_privacy);
936 case BT_ADD_WHITE_LIST: {
937 bluetooth_device_address_t address = { {0} };
938 int address_type = 0;
940 __bt_service_get_parameters(in_param1,
941 &address, sizeof(bluetooth_device_address_t));
942 __bt_service_get_parameters(in_param2,
943 &address_type, sizeof(int));
944 result = _bt_set_white_list(&address, address_type, is_add);
947 case BT_REMOVE_WHITE_LIST: {
948 bluetooth_device_address_t address = { {0} };
949 int address_type = 0;
951 __bt_service_get_parameters(in_param1,
952 &address, sizeof(bluetooth_device_address_t));
953 __bt_service_get_parameters(in_param2,
954 &address_type, sizeof(int));
955 result = _bt_set_white_list(&address, address_type, is_add);
958 case BT_UPDATE_LE_CONNECTION_MODE: {
960 bluetooth_device_address_t remote_address = { { 0 } };
961 bluetooth_le_connection_param_t parameters = { 0 };
962 bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED;
964 __bt_service_get_parameters(in_param1, &remote_address,
965 sizeof(bluetooth_device_address_t));
966 __bt_service_get_parameters(in_param2, &mode,
967 sizeof(bluetooth_le_connection_mode_t));
969 result = _bt_get_le_connection_parameter(mode, ¶meters);
970 if (result != BLUETOOTH_ERROR_NONE)
973 sender = (char *)g_dbus_method_invocation_get_sender(context);
975 result = _bt_le_connection_update(sender,
977 parameters.interval_min,
978 parameters.interval_max,
983 case BT_SET_MANUFACTURER_DATA: {
984 bluetooth_manufacturer_data_t m_data = { 0 };
985 __bt_service_get_parameters(in_param1,
986 &m_data, sizeof(bluetooth_manufacturer_data_t));
987 result = _bt_set_manufacturer_data(&m_data);
991 case BT_IS_DEVICE_CONNECTED: {
992 bluetooth_device_address_t address = { {0} };
993 gboolean connected = FALSE;
996 __bt_service_get_parameters(in_param1,
997 &address, sizeof(bluetooth_device_address_t));
998 __bt_service_get_parameters(in_param2,
999 &service_type, sizeof(int));
1001 #if defined(TIZEN_FEATURE_BT_PAN_NAP)
1002 if ((service_type == BLUETOOTH_NAP_SERVICE) || (service_type == BLUETOOTH_NAP_SERVER_SERVICE))
1003 connected = _bt_is_nap_panu_device_connected(&address, service_type);
1005 connected = _bt_is_device_connected(&address, service_type);
1007 connected = _bt_is_device_connected(&address, service_type);
1009 BT_INFO("is_connected: %d", connected);
1010 g_array_append_vals(*out_param1, &connected, sizeof(gboolean));
1013 case BT_GET_CONNECTED_LINK_TYPE: {
1014 bluetooth_device_address_t address = { {0} };
1016 __bt_service_get_parameters(in_param1,
1017 &address, sizeof(bluetooth_device_address_t));
1019 result = _bt_get_connected_link(&address);
1020 if (result == BLUETOOTH_ERROR_NONE) {
1021 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
1023 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
1027 _bt_convert_addr_type_to_string(addr, address.addr);
1028 sender = (char*)g_dbus_method_invocation_get_sender(context);
1029 _bt_save_invocation_context(context, result, sender,
1030 function_name, addr);
1034 case BT_IS_SCAN_FILTER_SUPPORTED:{
1035 int is_supported = 0;
1037 if (_bt_is_scan_filter_supported() == TRUE)
1040 g_array_append_vals(*out_param1,
1041 &is_supported, sizeof(int));
1045 case BT_ENABLE_RSSI: {
1046 bluetooth_device_address_t bd_addr;
1048 bt_rssi_threshold_t rssi_threshold;
1050 int in_range_threshold;
1053 BT_DBG("Enable RSSI");
1055 __bt_service_get_parameters(in_param1,
1056 &bd_addr, sizeof(bluetooth_device_address_t));
1057 __bt_service_get_parameters(in_param2,
1058 &link_type, sizeof(int));
1059 __bt_service_get_parameters(in_param3,
1060 &rssi_threshold, sizeof(bt_rssi_threshold_t));
1062 low_threshold = rssi_threshold.low_threshold;
1063 in_range_threshold = rssi_threshold.in_range_threshold;
1064 high_threshold = rssi_threshold.high_threshold;
1066 result = _bt_enable_rssi(&bd_addr, link_type, low_threshold,
1067 in_range_threshold, high_threshold);
1072 bluetooth_device_address_t bd_addr;
1074 BT_DBG("Get RSSI Strength");
1076 __bt_service_get_parameters(in_param1,
1077 &bd_addr, sizeof(bluetooth_device_address_t));
1078 __bt_service_get_parameters(in_param2,
1079 &link_type, sizeof(int));
1081 result = _bt_get_rssi_strength(&bd_addr, link_type);
1084 case BT_SET_PROFILE_TRUSTED: {
1085 bluetooth_device_address_t bd_addr = { {0} };
1089 __bt_service_get_parameters(in_param1, &bd_addr,
1090 sizeof(bluetooth_device_address_t));
1091 __bt_service_get_parameters(in_param2, &profile, sizeof(int));
1092 __bt_service_get_parameters(in_param3, &trust, sizeof(int));
1094 result = _bt_set_trust_profile(&bd_addr, profile, trust);
1097 case BT_GET_PROFILE_TRUSTED: {
1098 bluetooth_device_address_t bd_addr = { {0} };
1100 guint trusted_profile = 0;
1102 __bt_service_get_parameters(in_param1, &bd_addr,
1103 sizeof(bluetooth_device_address_t));
1104 __bt_service_get_parameters(in_param2, &profile, sizeof(int));
1106 result = _bt_get_trust_profile(&bd_addr, profile, &trusted_profile);
1107 BT_DBG("TRUST %d", trusted_profile);
1108 if (result == BLUETOOTH_ERROR_NONE) {
1109 g_array_append_vals(*out_param1, &trusted_profile,
1115 case BT_HID_CONNECT: {
1116 bluetooth_device_address_t address = { {0} };
1118 __bt_service_get_parameters(in_param1,
1119 &address, sizeof(bluetooth_device_address_t));
1121 result = _bt_hid_connect(&address);
1122 if (result != BLUETOOTH_ERROR_NONE) {
1123 g_array_append_vals(*out_param1, &address,
1124 sizeof(bluetooth_device_address_t));
1126 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1127 _bt_convert_addr_type_to_string(addr, address.addr);
1128 sender = (char*)g_dbus_method_invocation_get_sender(context);
1129 _bt_save_invocation_context(context, result, sender,
1130 function_name, (gpointer)addr);
1134 case BT_HID_DISCONNECT: {
1135 bluetooth_device_address_t address = { {0} };
1137 __bt_service_get_parameters(in_param1,
1138 &address, sizeof(bluetooth_device_address_t));
1140 result = _bt_hid_disconnect(&address);
1141 if (result != BLUETOOTH_ERROR_NONE) {
1142 g_array_append_vals(*out_param1, &address,
1143 sizeof(bluetooth_device_address_t));
1145 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1146 _bt_convert_addr_type_to_string(addr, address.addr);
1147 sender = (char*)g_dbus_method_invocation_get_sender(context);
1148 _bt_save_invocation_context(context, result, sender,
1149 function_name, (gpointer)addr);
1153 #ifdef TIZEN_FEATURE_BT_DPM
1154 case BT_DPM_SET_ALLOW_BT_MODE: {
1155 dpm_bt_allow_t value = DPM_BT_ERROR;
1157 __bt_service_get_parameters(in_param1, &value,
1160 result = _bt_dpm_set_allow_bluetooth_mode(value);
1163 case BT_DPM_GET_ALLOW_BT_MODE: {
1164 int value = DPM_BT_ERROR;
1166 result = _bt_dpm_get_allow_bluetooth_mode(&value);
1167 g_array_append_vals(*out_param1, &value, sizeof(int));
1170 case BT_DPM_SET_DEVICE_RESTRITION: {
1171 dpm_status_t value = DPM_STATUS_ERROR;
1173 __bt_service_get_parameters(in_param1, &value,
1176 result = _bt_dpm_activate_bluetooth_device_restriction(value);
1179 case BT_DPM_GET_DEVICE_RESTRITION: {
1180 int value = DPM_STATUS_ERROR;
1182 result = _bt_dpm_is_bluetooth_device_restriction_active(&value);
1183 g_array_append_vals(*out_param1, &value, sizeof(int));
1186 case BT_DPM_SET_UUID_RESTRITION: {
1187 dpm_status_t value = DPM_STATUS_ERROR;
1189 __bt_service_get_parameters(in_param1, &value,
1192 result = _bt_dpm_activate_bluetoooth_uuid_restriction(value);
1195 case BT_DPM_GET_UUID_RESTRITION: {
1196 int value = DPM_STATUS_ERROR;
1198 result = _bt_dpm_is_bluetooth_uuid_restriction_active(&value);
1199 g_array_append_vals(*out_param1, &value, sizeof(int));
1202 case BT_DPM_ADD_DEVICES_BLACKLIST: {
1203 bluetooth_device_address_t address = { {0} };
1205 __bt_service_get_parameters(in_param1, &address,
1206 sizeof(bluetooth_device_address_t));
1208 result = _bt_dpm_add_bluetooth_devices_to_blacklist(&address);
1211 case BT_DPM_ADD_DEVICES_WHITELIST: {
1212 bluetooth_device_address_t address = { {0} };
1214 __bt_service_get_parameters(in_param1, &address,
1215 sizeof(bluetooth_device_address_t));
1217 result = _bt_dpm_add_bluetooth_devices_to_whitelist(&address);
1220 case BT_DPM_ADD_UUIDS_BLACKLIST: {
1221 const char *uuid = NULL;
1223 uuid = g_variant_get_data(in_param1);
1225 result = _bt_dpm_add_bluetooth_uuids_to_blacklist(uuid);
1228 case BT_DPM_ADD_UUIDS_WHITELIST: {
1229 const char *uuid = NULL;
1231 uuid = g_variant_get_data(in_param1);
1233 result = _bt_dpm_add_bluetooth_uuids_to_whitelist(uuid);
1236 case BT_DPM_CLEAR_DEVICES_BLACKLIST: {
1237 result = _bt_dpm_clear_bluetooth_devices_from_blacklist();
1240 case BT_DPM_CLEAR_DEVICES_WHITELIST: {
1241 result = _bt_dpm_clear_bluetooth_devices_from_whitelist();
1244 case BT_DPM_CLEAR_UUIDS_BLACKLIST: {
1245 result = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
1248 case BT_DPM_CLEAR_UUIDS_WHITELIST: {
1249 result = _bt_dpm_clear_bluetooth_uuids_from_whitelist();
1252 case BT_DPM_REMOVE_DEVICE_BLACKLIST: {
1253 bluetooth_device_address_t address = { {0} };
1255 __bt_service_get_parameters(in_param1, &address,
1256 sizeof(bluetooth_device_address_t));
1258 result = _bt_dpm_remove_bluetooth_devices_from_blacklist(&address);
1261 case BT_DPM_REMOVE_DEVICE_WHITELIST: {
1262 bluetooth_device_address_t address = { {0} };
1264 __bt_service_get_parameters(in_param1, &address,
1265 sizeof(bluetooth_device_address_t));
1267 result = _bt_dpm_remove_bluetooth_devices_from_whitelist(&address);
1270 case BT_DPM_REMOVE_UUID_BLACKLIST: {
1271 const char *uuid = NULL;
1273 uuid = g_variant_get_data(in_param1);
1275 result = _bt_dpm_remove_bluetooth_uuids_from_blacklist(uuid);
1278 case BT_DPM_REMOVE_UUID_WHITELIST: {
1279 const char *uuid = NULL;
1281 uuid = g_variant_get_data(in_param1);
1283 result = _bt_dpm_remove_bluetooth_uuids_from_whitelist(uuid);
1287 case BT_DPM_GET_DEVICES_BLACKLIST: {
1288 result = _bt_dpm_get_bluetooth_devices_from_blacklist(out_param1);
1291 case BT_DPM_GET_DEVICES_WHITELIST: {
1292 result = _bt_dpm_get_bluetooth_devices_from_whitelist(out_param1);
1295 case BT_DPM_GET_UUIDS_BLACKLIST: {
1296 result = _bt_dpm_get_bluetooth_uuids_from_blacklist(out_param1);
1299 case BT_DPM_GET_UUIDS_WHITELIST: {
1300 result = _bt_dpm_get_bluetooth_uuids_from_whitelist(out_param1);
1303 case BT_DPM_SET_ALLOW_OUTGOING_CALL: {
1304 dpm_status_t value = DPM_STATUS_ERROR;
1306 __bt_service_get_parameters(in_param1, &value,
1309 result = _bt_dpm_set_allow_bluetooth_outgoing_call(value);
1313 case BT_DPM_GET_ALLOW_OUTGOING_CALL: {
1314 int value = DPM_STATUS_ERROR;
1316 result = _bt_dpm_get_allow_bluetooth_outgoing_call(&value);
1317 g_array_append_vals(*out_param1, &value, sizeof(int));
1320 case BT_DPM_SET_PAIRING_STATE: {
1321 dpm_status_t value = DPM_STATUS_ERROR;
1323 __bt_service_get_parameters(in_param1, &value,
1326 result = _bt_dpm_set_bluetooth_pairing_state(value);
1330 case BT_DPM_GET_PAIRING_STATE: {
1331 int value = DPM_STATUS_ERROR;
1333 result = _bt_dpm_get_bluetooth_pairing_state(&value);
1334 g_array_append_vals(*out_param1, &value, sizeof(int));
1337 case BT_DPM_SET_PROFILE_STATE: {
1338 int value = DPM_STATUS_ERROR;
1339 int profile = DPM_PROFILE_NONE;
1341 __bt_service_get_parameters(in_param1, &profile,
1343 __bt_service_get_parameters(in_param2, &value,
1346 result = _bt_dpm_set_bluetooth_profile_state(profile, value);
1350 case BT_DPM_GET_PROFILE_STATE: {
1351 int value = DPM_STATUS_ERROR;
1352 int profile = DPM_PROFILE_NONE;
1354 __bt_service_get_parameters(in_param1, &profile,
1357 result = _bt_dpm_get_bluetooth_profile_state(profile, &value);
1358 g_array_append_vals(*out_param1, &value, sizeof(int));
1361 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE: {
1362 int value = DPM_BT_ERROR;
1364 __bt_service_get_parameters(in_param1, &value,
1367 result = _bt_dpm_set_bluetooth_desktop_connectivity_state(value);
1371 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE: {
1372 int value = DPM_STATUS_ERROR;
1374 result = _bt_dpm_get_bluetooth_desktop_connectivity_state(&value);
1375 g_array_append_vals(*out_param1, &value, sizeof(int));
1378 case BT_DPM_SET_DISCOVERABLE_STATE: {
1379 int value = DPM_STATUS_ERROR;
1381 __bt_service_get_parameters(in_param1, &value,
1384 result = _bt_dpm_set_bluetooth_discoverable_state(value);
1388 case BT_DPM_GET_DISCOVERABLE_STATE: {
1389 int value = DPM_STATUS_ERROR;
1391 result = _bt_dpm_get_bluetooth_discoverable_state(&value);
1392 g_array_append_vals(*out_param1, &value, sizeof(int));
1395 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE: {
1396 int value = DPM_STATUS_ERROR;
1398 __bt_service_get_parameters(in_param1, &value,
1401 result = _bt_dpm_set_bluetooth_limited_discoverable_state(value);
1405 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE: {
1406 int value = DPM_STATUS_ERROR;
1408 result = _bt_dpm_get_bluetooth_limited_discoverable_state(&value);
1409 g_array_append_vals(*out_param1, &value, sizeof(int));
1412 case BT_DPM_SET_DATA_TRANSFER_STATE: {
1413 int value = DPM_STATUS_ERROR;
1415 __bt_service_get_parameters(in_param1, &value,
1418 result = _bt_dpm_set_bluetooth_data_transfer_state(value);
1422 case BT_DPM_GET_DATA_TRANSFER_STATE: {
1423 int value = DPM_STATUS_ERROR;
1425 result = _bt_dpm_get_allow_bluetooth_data_transfer_state(&value);
1426 g_array_append_vals(*out_param1, &value, sizeof(int));
1430 case BT_RFCOMM_CLIENT_CONNECT: {
1431 bluetooth_device_address_t address = { {0} };
1435 __bt_service_get_parameters(in_param1,
1436 &address, sizeof(bluetooth_device_address_t));
1437 input_string = (char *)g_variant_get_data(in_param2);
1438 __bt_service_get_parameters(in_param3, &connect_type, sizeof(int));
1440 if (connect_type == BT_RFCOMM_UUID)
1441 result = _bt_rfcomm_connect_using_uuid(&address, input_string);
1443 result = _bt_rfcomm_connect_using_channel(&address, input_string);
1445 if (result != BLUETOOTH_ERROR_NONE) {
1446 bluetooth_rfcomm_connection_t conn_info;
1448 BT_ERR("BT_RFCOMM_CLIENT_CONNECT failed, send error");
1449 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
1450 if (connect_type == BT_RFCOMM_UUID)
1451 g_strlcpy(conn_info.uuid, input_string, BLUETOOTH_UUID_STRING_MAX);
1453 g_strlcpy(conn_info.uuid, "not_used", BLUETOOTH_UUID_STRING_MAX);
1455 conn_info.device_role = RFCOMM_ROLE_CLIENT;
1456 conn_info.socket_fd = -1;
1457 g_array_append_vals(*out_param1, &conn_info,
1458 sizeof(bluetooth_rfcomm_connection_t));
1460 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1461 _bt_convert_addr_type_to_string(addr, address.addr);
1462 sender = (char*)g_dbus_method_invocation_get_sender(context);
1463 _bt_save_invocation_context(context, result, sender, function_name, addr);
1467 case BT_RFCOMM_SOCKET_DISCONNECT: {
1469 * Bluetooth RFCOMM socket disconnection will be done from bt-api, call to bt-service
1470 * is only used for privilege check, so return BLUETOOTH_ERROR_NONE from here.
1472 result = BLUETOOTH_ERROR_NONE;
1475 case BT_RFCOMM_SOCKET_WRITE: {
1477 * This call to bt-service is only used for privilege check, so return
1478 * BLUETOOTH_ERROR_NONE from here.
1480 result = BLUETOOTH_ERROR_NONE;
1483 case BT_RFCOMM_CREATE_SOCKET: {
1485 * This call to bt-service is only used for privilege check, so return
1486 * BLUETOOTH_ERROR_NONE from here.
1488 result = BLUETOOTH_ERROR_NONE;
1491 case BT_RFCOMM_LISTEN_AND_ACCEPT: {
1495 sender = (char *)g_dbus_method_invocation_get_sender(context);
1496 uuid = (char *)g_variant_get_data(in_param1);
1498 result = _bt_rfcomm_socket_listen(sender, uuid, true);
1500 result = BLUETOOTH_ERROR_NONE;
1501 _bt_save_invocation_context(context,
1502 result, sender, function_name, NULL);
1504 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1508 case BT_RFCOMM_LISTEN: {
1512 sender = (char *)g_dbus_method_invocation_get_sender(context);
1513 uuid = (char *)g_variant_get_data(in_param1);
1515 result = _bt_rfcomm_socket_listen(sender, uuid, false);
1517 result = BLUETOOTH_ERROR_NONE;
1518 _bt_save_invocation_context(context,
1519 result, sender, function_name, NULL);
1521 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1525 case BT_RFCOMM_ACCEPT_CONNECTION: {
1528 address = (char *)g_variant_get_data(in_param1);
1529 result = _bt_rfcomm_reply_conn_authorization(address, TRUE);
1532 case BT_RFCOMM_REJECT_CONNECTION: {
1535 address = (char *)g_variant_get_data(in_param1);
1536 result = _bt_rfcomm_reply_conn_authorization(address, FALSE);
1539 case BT_RFCOMM_REMOVE_SOCKET: {
1541 * This call to bt-service is only used for privilege check, so return
1542 * BLUETOOTH_ERROR_NONE from here.
1544 result = BLUETOOTH_ERROR_NONE;
1547 case BT_RFCOMM_SEND_RX_DETAILS: {
1551 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
1552 __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t));
1553 __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int));
1554 _bt_bm_add_transaction_details(uid, pid, size, RX_DATA);
1557 case BT_RFCOMM_SEND_TX_DETAILS: {
1561 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
1562 __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t));
1563 __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int));
1564 _bt_bm_add_transaction_details(uid, pid, size, TX_DATA);
1567 case BT_RFCOMM_UPDATE_CONNECTION_INFO: {
1568 gboolean connected = FALSE;
1570 int role = RFCOMM_ROLE_SERVER;
1572 sender = (char *)g_dbus_method_invocation_get_sender(context);
1574 __bt_service_get_parameters(in_param1, &role, sizeof(int));
1575 __bt_service_get_parameters(in_param2, &connected, sizeof(gboolean));
1576 __bt_service_get_parameters(in_param3, &socket_fd, sizeof(int));
1578 if (connected == TRUE)
1579 result = _bt_rfcomm_conn_added(sender, role, socket_fd);
1581 result = _bt_rfcomm_conn_removed(sender, role, socket_fd);
1585 case BT_AUDIO_SELECT_ROLE: {
1586 bluetooth_audio_role_t role;
1588 __bt_service_get_parameters(in_param1,
1589 &role, sizeof(bluetooth_audio_role_t));
1591 result = _bt_audio_select_role(role);
1592 if (result == BLUETOOTH_ERROR_NONE) {
1593 sender = (char*)g_dbus_method_invocation_get_sender(context);
1594 _bt_save_invocation_context(context, result, sender,
1595 function_name, NULL);
1599 #ifdef TIZEN_FEATURE_BT_AVC_TARGET
1600 case BT_AUDIO_SET_ABSOLUTE_VOLUME: {
1601 unsigned int volume = 0;
1603 __bt_service_get_parameters(in_param1,
1604 &volume, sizeof(unsigned int));
1606 result = _bt_audio_set_absolute_volume(volume);
1609 case BT_AUDIO_GET_ABSOLUTE_VOLUME: {
1610 unsigned int volume = 0;
1612 result = _bt_audio_get_absolute_volume(&volume);
1613 g_array_append_vals(*out_param1, &volume, sizeof(unsigned int));
1616 case BT_AUDIO_IS_AVC_ACTIVATED: {
1619 result = _bt_audio_is_avc_activated(&activated);
1620 g_array_append_vals(*out_param1, &activated, sizeof(bool));
1624 case BT_AV_CONNECT: {
1625 bluetooth_device_address_t address = { {0} };
1626 __bt_service_get_parameters(in_param1,
1627 &address, sizeof(bluetooth_device_address_t));
1629 result = _bt_audio_connect(BT_AUDIO_A2DP, &address);
1631 if (result != BLUETOOTH_ERROR_NONE) {
1632 char addr[BT_ADDRESS_STRING_SIZE];
1633 _bt_convert_addr_type_to_string(addr, address.addr);
1634 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1636 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1637 _bt_convert_addr_type_to_string(addr, address.addr);
1638 sender = (char*)g_dbus_method_invocation_get_sender(context);
1639 _bt_save_invocation_context(context, result, sender,
1640 function_name, (gpointer)addr);
1644 case BT_AUDIO_CONNECT: {
1645 bluetooth_device_address_t address = { {0} };
1646 __bt_service_get_parameters(in_param1,
1647 &address, sizeof(bluetooth_device_address_t));
1649 result = _bt_audio_connect(BT_AUDIO_ALL, &address);
1651 if (result != BLUETOOTH_ERROR_NONE) {
1652 char addr[BT_ADDRESS_STRING_SIZE];
1653 _bt_convert_addr_type_to_string(addr, address.addr);
1654 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1656 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1657 _bt_convert_addr_type_to_string(addr, address.addr);
1658 sender = (char*)g_dbus_method_invocation_get_sender(context);
1659 _bt_save_invocation_context(context, result, sender,
1660 function_name, (gpointer)addr);
1664 case BT_AUDIO_DISCONNECT: {
1665 bluetooth_device_address_t address = { {0} };
1666 __bt_service_get_parameters(in_param1,
1667 &address, sizeof(bluetooth_device_address_t));
1669 result = _bt_audio_disconnect(BT_AUDIO_ALL, &address);
1671 if (result != BLUETOOTH_ERROR_NONE) {
1672 char addr[BT_ADDRESS_STRING_SIZE];
1673 _bt_convert_addr_type_to_string(addr, address.addr);
1674 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1676 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1677 _bt_convert_addr_type_to_string(addr, address.addr);
1678 sender = (char*)g_dbus_method_invocation_get_sender(context);
1679 _bt_save_invocation_context(context, result, sender,
1680 function_name, (gpointer)addr);
1684 case BT_AV_DISCONNECT: {
1685 bluetooth_device_address_t address = { {0} };
1686 __bt_service_get_parameters(in_param1,
1687 &address, sizeof(bluetooth_device_address_t));
1689 result = _bt_audio_disconnect(BT_AUDIO_A2DP, &address);
1691 if (result != BLUETOOTH_ERROR_NONE) {
1692 char addr[BT_ADDRESS_STRING_SIZE];
1693 _bt_convert_addr_type_to_string(addr, address.addr);
1694 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1696 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1697 _bt_convert_addr_type_to_string(addr, address.addr);
1698 sender = (char*)g_dbus_method_invocation_get_sender(context);
1699 _bt_save_invocation_context(context, result, sender,
1700 function_name, (gpointer)addr);
1704 case BT_AG_CONNECT: {
1705 bluetooth_device_address_t address = { {0} };
1706 __bt_service_get_parameters(in_param1,
1707 &address, sizeof(bluetooth_device_address_t));
1709 result = _bt_audio_connect(BT_AUDIO_HSP, &address);
1711 if (result != BLUETOOTH_ERROR_NONE) {
1712 char addr[BT_ADDRESS_STRING_SIZE];
1713 _bt_convert_addr_type_to_string(addr, address.addr);
1714 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1716 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1717 _bt_convert_addr_type_to_string(addr, address.addr);
1718 sender = (char*)g_dbus_method_invocation_get_sender(context);
1719 _bt_save_invocation_context(context, result, sender,
1720 function_name, (gpointer)addr);
1724 case BT_AG_DISCONNECT: {
1725 bluetooth_device_address_t address = { {0} };
1727 __bt_service_get_parameters(in_param1,
1728 &address, sizeof(bluetooth_device_address_t));
1730 result = _bt_audio_disconnect(BT_AUDIO_HSP, &address);
1732 if (result != BLUETOOTH_ERROR_NONE) {
1733 char addr[BT_ADDRESS_STRING_SIZE];
1734 _bt_convert_addr_type_to_string(addr, address.addr);
1735 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1737 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1738 _bt_convert_addr_type_to_string(addr, address.addr);
1739 sender = (char*)g_dbus_method_invocation_get_sender(context);
1740 _bt_save_invocation_context(context, result, sender,
1741 function_name, (gpointer)addr);
1745 case BT_AV_SOURCE_CONNECT: {
1746 bluetooth_device_address_t address = { {0} };
1748 __bt_service_get_parameters(in_param1,
1749 &address, sizeof(bluetooth_device_address_t));
1751 result = _bt_audio_connect(BT_AUDIO_A2DP_SOURCE, &address);
1752 if (result != BLUETOOTH_ERROR_NONE) {
1753 char addr[BT_ADDRESS_STRING_SIZE];
1754 _bt_convert_addr_type_to_string(addr, address.addr);
1755 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1757 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1758 _bt_convert_addr_type_to_string(addr, address.addr);
1759 sender = (char*)g_dbus_method_invocation_get_sender(context);
1760 _bt_save_invocation_context(context, result, sender,
1761 function_name, (gpointer)addr);
1765 case BT_AV_SOURCE_DISCONNECT: {
1766 bluetooth_device_address_t address = { {0} };
1768 __bt_service_get_parameters(in_param1,
1769 &address, sizeof(bluetooth_device_address_t));
1771 result = _bt_audio_disconnect(BT_AUDIO_A2DP_SOURCE, &address);
1772 if (result != BLUETOOTH_ERROR_NONE) {
1773 char addr[BT_ADDRESS_STRING_SIZE];
1774 _bt_convert_addr_type_to_string(addr, address.addr);
1775 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1777 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1778 _bt_convert_addr_type_to_string(addr, address.addr);
1779 sender = (char*)g_dbus_method_invocation_get_sender(context);
1780 _bt_save_invocation_context(context, result, sender,
1781 function_name, (gpointer)addr);
1785 case BT_HF_CONNECT: {
1786 bluetooth_device_address_t address = { {0} };
1788 __bt_service_get_parameters(in_param1,
1789 &address, sizeof(bluetooth_device_address_t));
1791 result = _bt_hf_connect(&address);
1792 if (result != BLUETOOTH_ERROR_NONE) {
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_HF_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_hf_disconnect(&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_AVRCP_TARGET_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_connect(BT_AVRCP_TARGET, &address);
1832 if (result != BLUETOOTH_ERROR_NONE) {
1833 char addr[BT_ADDRESS_STRING_SIZE];
1834 _bt_convert_addr_type_to_string(addr, address.addr);
1835 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1837 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1838 _bt_convert_addr_type_to_string(addr, address.addr);
1839 sender = (char*)g_dbus_method_invocation_get_sender(context);
1840 _bt_save_invocation_context(context, result, sender,
1841 function_name, (gpointer)addr);
1845 case BT_AVRCP_TARGET_DISCONNECT: {
1846 bluetooth_device_address_t address = { {0} };
1848 __bt_service_get_parameters(in_param1,
1849 &address, sizeof(bluetooth_device_address_t));
1851 result = _bt_audio_disconnect(BT_AVRCP_TARGET, &address);
1852 if (result != BLUETOOTH_ERROR_NONE) {
1853 char addr[BT_ADDRESS_STRING_SIZE];
1854 _bt_convert_addr_type_to_string(addr, address.addr);
1855 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1857 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1858 _bt_convert_addr_type_to_string(addr, address.addr);
1859 sender = (char*)g_dbus_method_invocation_get_sender(context);
1860 _bt_save_invocation_context(context, result, sender,
1861 function_name, (gpointer)addr);
1865 case BT_AVRCP_CONTROL_CONNECT: {
1866 bluetooth_device_address_t address = { {0} };
1868 __bt_service_get_parameters(in_param1,
1869 &address, sizeof(bluetooth_device_address_t));
1871 result = _bt_audio_connect(BT_AVRCP, &address);
1872 if (result != BLUETOOTH_ERROR_NONE) {
1873 char addr[BT_ADDRESS_STRING_SIZE];
1874 _bt_convert_addr_type_to_string(addr, address.addr);
1875 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1877 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1878 _bt_convert_addr_type_to_string(addr, address.addr);
1879 sender = (char*)g_dbus_method_invocation_get_sender(context);
1880 _bt_save_invocation_context(context, result, sender,
1881 function_name, (gpointer)addr);
1885 case BT_AVRCP_CONTROL_DISCONNECT: {
1886 bluetooth_device_address_t address = { {0} };
1888 __bt_service_get_parameters(in_param1,
1889 &address, sizeof(bluetooth_device_address_t));
1891 result = _bt_audio_disconnect(BT_AVRCP, &address);
1892 if (result != BLUETOOTH_ERROR_NONE) {
1893 char addr[BT_ADDRESS_STRING_SIZE];
1894 _bt_convert_addr_type_to_string(addr, address.addr);
1895 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1897 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1898 _bt_convert_addr_type_to_string(addr, address.addr);
1899 sender = (char*)g_dbus_method_invocation_get_sender(context);
1900 _bt_save_invocation_context(context, result, sender,
1901 function_name, (gpointer)addr);
1905 case BT_AVRCP_HANDLE_CONTROL: {
1907 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1908 result = _bt_avrcp_control_cmd(key_code);
1911 case BT_AVRCP_HANDLE_CONTROL_TO_DEST: {
1913 bluetooth_device_address_t address = { { 0 } };
1915 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1916 __bt_service_get_parameters(in_param2,
1917 &address, sizeof(bluetooth_device_address_t));
1919 result = _bt_avrcp_control_cmd_to_dest(key_code, &address);
1922 case BT_AVRCP_CONTROL_SET_PROPERTY: {
1926 __bt_service_get_parameters(in_param1,
1927 &type, sizeof(int));
1928 __bt_service_get_parameters(in_param2,
1929 &value, sizeof(unsigned int));
1931 result = _bt_avrcp_control_set_property(type, value);
1934 case BT_AVRCP_TRANSPORT_SET_PROPERTY: {
1939 __bt_service_get_parameters(in_param1,
1940 &type, sizeof(int));
1941 __bt_service_get_parameters(in_param2,
1942 &value, sizeof(unsigned int));
1944 result = _bt_avrcp_transport_set_property(type, value);
1948 case BT_AVRCP_CONTROL_GET_PROPERTY: {
1951 __bt_service_get_parameters(in_param1, &type, sizeof(int));
1953 result = _bt_avrcp_control_get_property(type);
1954 /* Save invocation */
1955 if (result == BLUETOOTH_ERROR_NONE) {
1956 sender = (char*)g_dbus_method_invocation_get_sender(context);
1957 _bt_save_invocation_context(context, result, sender,
1958 function_name, g_memdup(&type, sizeof(int)));
1962 case BT_AVRCP_GET_TRACK_INFO: {
1963 result = _bt_avrcp_control_get_track_info();
1964 /* Save invocation */
1965 if (result == BLUETOOTH_ERROR_NONE) {
1966 sender = (char*)g_dbus_method_invocation_get_sender(context);
1967 _bt_save_invocation_context(context, result, sender,
1968 function_name, NULL);
1972 case BT_HDP_REGISTER_SINK_APP: {
1973 unsigned short data_type;
1974 bt_hdp_role_type_t role;
1975 bt_hdp_qos_type_t channel_type;
1976 int *app_id = g_new0(int, 1);
1978 __bt_service_get_parameters(in_param1,
1979 &data_type, sizeof(short));
1980 __bt_service_get_parameters(in_param2,
1981 &role, sizeof(bt_hdp_role_type_t));
1982 __bt_service_get_parameters(in_param3,
1983 &channel_type, sizeof(bt_hdp_qos_type_t));
1984 sender = (char*)g_dbus_method_invocation_get_sender(context);
1986 result = _bt_hdp_app_register(role,
1987 channel_type, data_type, sender, app_id);
1988 if (result != BLUETOOTH_ERROR_NONE) {
1989 g_array_append_vals(*out_param1, &app_id, sizeof(app_id));
1992 _bt_save_invocation_context(context, result, sender,
1993 function_name, (gpointer)app_id);
1997 case BT_HDP_UNREGISTER_SINK_APP: {
1999 int *app_id = g_new0(int, 1);
2001 app_handle = (char *)g_variant_get_data(in_param1);
2002 sscanf(app_handle, "health_app_%d", app_id);
2003 result = _bt_hdp_app_unregister(*app_id);
2004 if (result != BLUETOOTH_ERROR_NONE) {
2007 sender = (char*)g_dbus_method_invocation_get_sender(context);
2008 _bt_save_invocation_context(context, result, sender,
2009 function_name, (gpointer)app_id);
2013 case BT_HDP_CONNECT: {
2017 bt_hdp_connected_t *conn_info = NULL;
2019 conn_info = g_malloc0(sizeof(bt_hdp_connected_t));
2021 app_handle = (char *)g_variant_get_data(in_param1);
2022 conn_info->app_handle = app_handle;
2023 sscanf(app_handle, "health_app_%d", &app_id);
2025 __bt_service_get_parameters(in_param2,
2026 &(conn_info->type), sizeof(bt_hdp_qos_type_t));
2027 __bt_service_get_parameters(in_param3,
2028 &(conn_info->device_address),
2029 sizeof(bluetooth_device_address_t));
2031 result = _bt_hdp_connect(app_id, &(conn_info->device_address),
2032 conn_info->type, (int *)(&(conn_info->channel_id)));
2033 if (result != BLUETOOTH_ERROR_NONE) {
2034 g_array_append_vals(*out_param1, conn_info,
2035 sizeof(bt_hdp_connected_t));
2038 sender = (char*)g_dbus_method_invocation_get_sender(context);
2039 _bt_save_invocation_context(context, result, sender,
2040 function_name, (gpointer)conn_info);
2044 case BT_HDP_DISCONNECT: {
2045 bt_hdp_disconnected_t *hdp_disconn_info = NULL;
2047 hdp_disconn_info = g_malloc0(sizeof(bt_hdp_disconnected_t));
2049 __bt_service_get_parameters(in_param1,
2050 &(hdp_disconn_info->channel_id), sizeof(int));
2051 __bt_service_get_parameters(in_param2,
2052 &(hdp_disconn_info->device_address),
2053 sizeof(bluetooth_device_address_t));
2055 result = _bt_hdp_disconnect(hdp_disconn_info->channel_id);
2056 if (result != BLUETOOTH_ERROR_NONE) {
2057 g_array_append_vals(*out_param1, hdp_disconn_info,
2058 sizeof(bt_hdp_disconnected_t));
2059 g_free(hdp_disconn_info);
2061 sender = (char*)g_dbus_method_invocation_get_sender(context);
2062 _bt_save_invocation_context(context, result, sender,
2063 function_name, (gpointer)hdp_disconn_info);
2067 case BT_HDP_GET_FD: {
2068 int *channel_id = g_new0(int, 1);
2070 __bt_service_get_parameters(in_param1, channel_id, sizeof(int));
2072 result = _bt_hdp_get_fd(*channel_id);
2073 if (result != BLUETOOTH_ERROR_NONE) {
2076 sender = (char*)g_dbus_method_invocation_get_sender(context);
2077 _bt_save_invocation_context(context, result, sender,
2078 function_name, (gpointer)channel_id);
2082 case BT_HDP_SEND_DATA: {
2084 * This call to bt-service is only used for privilege check, so return
2085 * BLUETOOTH_ERROR_NONE from here.
2087 result = BLUETOOTH_ERROR_NONE;
2090 case BT_OOB_READ_LOCAL_DATA: { //208
2091 bt_oob_data_t local_oob_data;
2093 memset(&local_oob_data, 0x00, sizeof(bt_oob_data_t));
2094 result = _bt_oob_read_local_data(&local_oob_data);
2096 g_array_append_vals(*out_param1, &local_oob_data,
2097 sizeof(bt_oob_data_t));
2101 case BT_OOB_ADD_REMOTE_DATA: { //209
2102 bluetooth_device_address_t address = { {0} };
2103 unsigned short address_type;
2104 bt_oob_data_t remote_oob_data;
2106 __bt_service_get_parameters(in_param1,
2107 &address, sizeof(bluetooth_device_address_t));
2108 __bt_service_get_parameters(in_param2,
2109 &address_type, sizeof(unsigned short));
2110 __bt_service_get_parameters(in_param3,
2111 &remote_oob_data, sizeof(bt_oob_data_t));
2113 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2117 case BT_OOB_REMOVE_REMOTE_DATA: { //210
2118 bluetooth_device_address_t address = { {0} };
2120 __bt_service_get_parameters(in_param1,
2121 &address, sizeof(bluetooth_device_address_t));
2123 result = _bt_oob_remove_remote_data(&address);
2127 case BT_LE_OOB_READ_LOCAL_DATA: {
2128 bt_oob_data_t local_oob_data;
2129 bt_oob_data_t *local_oob_cache_data;
2131 local_oob_cache_data = _bt_le_oob_get_local_cache_data();
2132 if (local_oob_cache_data && local_oob_cache_data->eir_len) {
2133 g_array_append_vals(*out_param1, local_oob_cache_data,
2134 sizeof(bt_oob_data_t));
2135 return BLUETOOTH_ERROR_NONE;
2138 /* We should modify this logic in later */
2139 if (_bt_is_le_static_random_address_enabled() == false) {
2140 /* Seperate BT & LE address */
2141 _bt_set_le_static_random_address(TRUE);
2144 result = _bt_le_oob_read_local_data(&local_oob_data);
2145 _bt_le_oob_set_local_cache_data(&local_oob_data);
2147 g_array_append_vals(*out_param1, &local_oob_data,
2148 sizeof(bt_oob_data_t));
2152 case BT_LE_OOB_ADD_REMOTE_DATA: {
2153 bluetooth_device_address_t address = { {0} };
2154 unsigned short address_type;
2155 bt_oob_data_t remote_oob_data;
2157 __bt_service_get_parameters(in_param1,
2158 &address, sizeof(bluetooth_device_address_t));
2159 __bt_service_get_parameters(in_param2,
2160 &address_type, sizeof(unsigned short));
2161 __bt_service_get_parameters(in_param3,
2162 &remote_oob_data, sizeof(bt_oob_data_t));
2164 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2168 case BT_AVRCP_SET_TRACK_INFO: {
2169 media_metadata_t data;
2170 media_metadata_attributes_t meta_data;
2172 memset(&data, 0x00, sizeof(media_metadata_t));
2173 memset(&meta_data, 0x00, sizeof(media_metadata_attributes_t));
2175 __bt_service_get_parameters(in_param1,
2176 &data, sizeof(media_metadata_t));
2178 meta_data.title = g_strdup(data.title);
2179 meta_data.artist = g_strdup(data.artist);
2180 meta_data.album = g_strdup(data.album);
2181 meta_data.genre = g_strdup(data.genre);
2182 meta_data.total_tracks = data.total_tracks;
2183 meta_data.number = data.number;
2184 meta_data.duration = (int64_t) data.duration;
2186 result = _bt_avrcp_set_track_info(&meta_data);
2188 g_free((gpointer)meta_data.title);
2189 g_free((gpointer)meta_data.artist);
2190 g_free((gpointer)meta_data.album);
2191 g_free((gpointer)meta_data.genre);
2195 case BT_AVRCP_SET_PROPERTY: {
2199 sender = (char *)g_dbus_method_invocation_get_sender(context);
2201 __bt_service_get_parameters(in_param1,
2202 &type, sizeof(int));
2203 __bt_service_get_parameters(in_param2,
2204 &value, sizeof(unsigned int));
2206 if (value == STATUS_PLAYING) {
2207 if (current_sender_playing)
2208 g_free(current_sender_playing);
2209 current_sender_playing = g_strdup(sender);
2211 if (g_strcmp0(sender, current_sender_playing) == 0 ||
2212 current_sender_playing == NULL) {
2213 BT_INFO("Current Player Status %d type %d Sender %s", value, type, sender);
2215 BT_INFO("Current Player and this sender (%s) are different", sender);
2216 result = BLUETOOTH_ERROR_NONE;
2219 result = _bt_avrcp_set_property(type, value);
2223 case BT_AVRCP_SET_PROPERTIES: {
2224 media_player_settings_t properties;
2226 memset(&properties, 0x00, sizeof(media_player_settings_t));
2227 __bt_service_get_parameters(in_param1,
2228 &properties, sizeof(media_player_settings_t));
2230 result = _bt_avrcp_set_properties(&properties);
2234 case BT_SET_ADVERTISING_DATA: {
2237 bluetooth_advertising_data_t adv = { {0} };
2239 gboolean use_reserved_slot = FALSE;
2241 app = (char *)g_dbus_method_invocation_get_sender(context);
2242 adv_handle = g_malloc0(sizeof(int));
2244 __bt_service_get_parameters(in_param1,
2245 adv_handle, sizeof(int));
2246 __bt_service_get_parameters(in_param3,
2247 &length, sizeof(int));
2248 __bt_service_get_parameters(in_param2,
2250 __bt_service_get_parameters(in_param4,
2251 &use_reserved_slot, sizeof(gboolean));
2252 result = _bt_set_advertising_data(app, *adv_handle,
2253 &adv, length, use_reserved_slot);
2254 if (result != BLUETOOTH_ERROR_NONE) {
2255 BT_ERR("Set Advertising data failed!!");
2258 _bt_save_invocation_context(context, result, app,
2259 function_name, (gpointer)adv_handle);
2263 case BT_SET_SCAN_RESPONSE_DATA: {
2266 bluetooth_scan_resp_data_t rsp = { {0} };
2268 gboolean use_reserved_slot = FALSE;
2270 app = (char *)g_dbus_method_invocation_get_sender(context);
2271 adv_handle = g_malloc0(sizeof(int));
2273 __bt_service_get_parameters(in_param1,
2274 adv_handle, sizeof(int));
2275 __bt_service_get_parameters(in_param3,
2276 &length, sizeof(int));
2277 __bt_service_get_parameters(in_param2,
2279 __bt_service_get_parameters(in_param4,
2280 &use_reserved_slot, sizeof(gboolean));
2282 result = _bt_set_scan_response_data(app, *adv_handle,
2283 &rsp, length, use_reserved_slot);
2285 if (result != BLUETOOTH_ERROR_NONE) {
2286 BT_ERR("Set Scan Response Data failed!!");
2289 _bt_save_invocation_context(context, result, app,
2290 function_name, (gpointer)adv_handle);
2294 case BT_SET_ADVERTISING: {
2297 gboolean enable = FALSE;
2298 gboolean use_reserved_slot = FALSE;
2300 adv_handle = g_malloc0(sizeof(int));
2301 __bt_service_get_parameters(in_param1,
2302 adv_handle, sizeof(int));
2303 __bt_service_get_parameters(in_param2,
2304 &enable, sizeof(gboolean));
2305 __bt_service_get_parameters(in_param3,
2306 &use_reserved_slot, sizeof(gboolean));
2308 app = (char *)g_dbus_method_invocation_get_sender(context);
2310 result = _bt_set_advertising(app, *adv_handle,
2311 enable, use_reserved_slot);
2312 if (result != BLUETOOTH_ERROR_NONE) {
2313 BT_ERR("Start Advertising failed!!");
2316 _bt_save_invocation_context(context, result, app,
2317 function_name, (gpointer)adv_handle);
2321 case BT_SET_CUSTOM_ADVERTISING: {
2324 gboolean enable = FALSE;
2325 bluetooth_advertising_params_t adv_params;
2326 gboolean use_reserved_slot = FALSE;
2328 app = (char *)g_dbus_method_invocation_get_sender(context);
2329 adv_handle = g_malloc0(sizeof(int));
2331 __bt_service_get_parameters(in_param1, adv_handle,
2333 __bt_service_get_parameters(in_param2, &enable,
2335 __bt_service_get_parameters(in_param3, &adv_params,
2336 sizeof(bluetooth_advertising_params_t));
2337 __bt_service_get_parameters(in_param4, &use_reserved_slot,
2340 BT_DBG("bluetooth_advertising_params_t [%f %f %d %d %d]",
2341 adv_params.interval_min, adv_params.interval_max,
2342 adv_params.filter_policy, adv_params.type, adv_params.tx_power_level);
2343 result = _bt_set_custom_advertising(app, *adv_handle,
2344 enable, &adv_params, use_reserved_slot);
2345 if (result != BLUETOOTH_ERROR_NONE) {
2346 BT_ERR("Start Custom Advertising failed!!");
2349 _bt_save_invocation_context(context, result, app,
2350 function_name, (gpointer)adv_handle);
2354 case BT_GET_SCAN_RESPONSE_DATA: {
2355 bluetooth_scan_resp_data_t rsp = { {0} };
2359 app = (char *)g_dbus_method_invocation_get_sender(context);
2361 __bt_service_get_parameters(in_param1, &adv_handle,
2364 result = _bt_get_scan_response_data(app, adv_handle, &rsp, &length);
2365 if (result == BLUETOOTH_ERROR_NONE)
2366 g_array_append_vals(*out_param1, rsp.data, length);
2370 case BT_GET_ADVERTISING_DATA: {
2371 bluetooth_advertising_data_t adv = { {0} };
2375 app = (char *)g_dbus_method_invocation_get_sender(context);
2377 __bt_service_get_parameters(in_param1, &adv_handle,
2380 result = _bt_get_advertising_data(app, adv_handle, &adv, &length);
2381 if (result == BLUETOOTH_ERROR_NONE)
2382 g_array_append_vals(*out_param1, adv.data, length);
2386 case BT_GATT_REGISTER_APPLICATION: {
2387 BT_DBG("Register GATT application:Unhandled!!");
2390 case BT_GATT_SERVER_REGISTER: {
2391 BT_DBG("GATT Server instance initialization");
2394 app = (char *)g_dbus_method_invocation_get_sender(context);
2395 BT_DBG("GATT Server Unique Name [%s]", app);
2397 /* No ADV handle: Set 0 */
2398 result = _bt_register_server_instance(app, 0);
2400 if (result != BLUETOOTH_ERROR_NONE) {
2401 BT_ERR("GATT Server registration failed. result %d", result);
2403 _bt_save_invocation_context(context, result, app,
2404 function_name, NULL);
2408 case BT_GATT_SERVER_DEREGISTER: {
2410 app = (char*)g_dbus_method_invocation_get_sender(context);
2412 result = _bt_unregister_server_instance(app, 0/* Adv Handle*/);
2415 case BT_GATT_SERVER_ADD_SERVICE: {
2416 BT_DBG("GATT Server Add Service");
2422 int *tmp_inst_id = NULL;
2424 app = (char *)g_dbus_method_invocation_get_sender(context);
2426 __bt_service_get_parameters(in_param1, &service_type,
2428 __bt_service_get_parameters(in_param2, &num_handles,
2430 svc_uuid = (char *)g_variant_get_data(in_param3);
2431 __bt_service_get_parameters(in_param4, &instance_id,
2434 result = _bt_gatt_server_add_service(app, service_type, num_handles, svc_uuid, instance_id);
2435 if (result != BLUETOOTH_ERROR_NONE) {
2436 BT_ERR("GATT Server Add Service failed!!");
2438 tmp_inst_id = g_malloc0(sizeof(int));
2439 *tmp_inst_id = instance_id;
2440 _bt_save_invocation_context(context, result, app,
2441 function_name, (gpointer)tmp_inst_id);
2445 case BT_GATT_SERVER_ADD_CHARACTERISTIC: {
2446 BT_DBG("GATT Server Add Characteristic");
2449 int *tmp_inst_id = NULL;
2450 bluetooth_gatt_server_attribute_params_t param;
2451 memset(¶m, 0, sizeof(bluetooth_gatt_server_attribute_params_t));
2453 app = (char*)g_dbus_method_invocation_get_sender(context);
2455 __bt_service_get_parameters(in_param1, ¶m,
2456 sizeof(bluetooth_gatt_server_attribute_params_t));
2457 char_uuid = (char *)g_variant_get_data(in_param2);
2459 result = _bt_gatt_server_add_characteristic(app, char_uuid, ¶m);
2460 if (result != BLUETOOTH_ERROR_NONE) {
2461 BT_ERR("GATT Server Add Service failed!!");
2463 tmp_inst_id = g_malloc0(sizeof(int));
2464 *tmp_inst_id = param.instance_id;
2466 _bt_save_invocation_context(context, result, app,
2467 function_name, (gpointer)tmp_inst_id);
2471 case BT_GATT_SERVER_ADD_DESCRIPTOR: {
2472 BT_DBG("GATT Server Add Descriptor");
2476 bt_gatt_permission_t perm;
2478 int *tmp_inst_id = NULL;
2479 memset(&perm, 0, sizeof(bt_gatt_permission_t));
2481 app = (char *)g_dbus_method_invocation_get_sender(context);
2483 __bt_service_get_parameters(in_param1, &service_handle,
2485 __bt_service_get_parameters(in_param2, &instance_id,
2487 desc_uuid = (char *)g_variant_get_data(in_param4);
2488 __bt_service_get_parameters(in_param3, &perm,
2489 sizeof(bt_gatt_permission_t));
2491 result = _bt_gatt_server_add_descriptor(app, desc_uuid, &perm, service_handle, instance_id);
2492 if (result != BLUETOOTH_ERROR_NONE) {
2493 BT_ERR("GATT Server Add Service failed!!");
2495 tmp_inst_id = g_malloc0(sizeof(int));
2496 *tmp_inst_id = instance_id;
2497 _bt_save_invocation_context(context, result, app,
2498 function_name, (gpointer)tmp_inst_id);
2502 case BT_GATT_SERVER_START_SERVICE: {
2507 int *tmp_inst_id = NULL;
2508 app = (char*)g_dbus_method_invocation_get_sender(context);
2510 __bt_service_get_parameters(in_param1, &service_handle,
2512 __bt_service_get_parameters(in_param2, &instance_id,
2515 result = _bt_gatt_server_start_service(app, service_handle, instance_id);
2517 if (BLUETOOTH_ERROR_NONE == result) {
2518 tmp_inst_id = g_malloc0(sizeof(int));
2519 *tmp_inst_id = instance_id;
2520 _bt_save_invocation_context(context, result, app,
2521 function_name, (gpointer)tmp_inst_id);
2525 case BT_GATT_SERVER_STOP_SERVICE: {
2529 int *tmp_inst_id = NULL;
2530 app = (char*)g_dbus_method_invocation_get_sender(context);
2532 __bt_service_get_parameters(in_param1, &service_handle,
2534 __bt_service_get_parameters(in_param2, &instance_id,
2537 result = _bt_gatt_server_stop_service(app, service_handle, instance_id);
2539 if (BLUETOOTH_ERROR_NONE == result) {
2540 tmp_inst_id = g_malloc0(sizeof(int));
2541 *tmp_inst_id = instance_id;
2542 _bt_save_invocation_context(context, result, app,
2543 function_name, (gpointer)tmp_inst_id);
2547 case BT_GATT_SERVER_DELETE_SERVICE: {
2550 int *tmp_inst_id = NULL;
2552 app = (char*)g_dbus_method_invocation_get_sender(context);
2554 __bt_service_get_parameters(in_param1, &service_handle,
2556 __bt_service_get_parameters(in_param2, &instance_id,
2559 result = _bt_gatt_server_delete_service(app, service_handle, instance_id);
2561 if (BLUETOOTH_ERROR_NONE == result) {
2562 tmp_inst_id = g_malloc0(sizeof(int));
2563 *tmp_inst_id = instance_id;
2564 _bt_save_invocation_context(context, result, app,
2565 function_name, (gpointer)tmp_inst_id);
2569 case BT_GATT_SERVER_SEND_RESPONSE: {
2570 bluetooth_gatt_server_response_params_t param;
2571 bluetooth_gatt_att_data_t data;
2574 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_response_params_t));
2575 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2577 app = (char*)g_dbus_method_invocation_get_sender(context);
2579 __bt_service_get_parameters(in_param1, &data,
2580 sizeof(bluetooth_gatt_att_data_t));
2581 __bt_service_get_parameters(in_param2, ¶m,
2582 sizeof(bluetooth_gatt_server_response_params_t));
2584 result = _bt_gatt_server_send_response(app, &data, ¶m);
2588 case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE: {
2590 bluetooth_gatt_server_acquire_response_params_t param;
2593 msg = g_dbus_method_invocation_get_message(context);
2594 GUnixFDList *fd_list;
2599 fd_list = g_dbus_message_get_unix_fd_list(msg);
2601 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2603 app = (char*)g_dbus_method_invocation_get_sender(context);
2605 __bt_service_get_parameters(in_param1, ¶m,
2606 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2608 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2609 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2610 fd = fd_list_array[0];
2613 result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
2617 case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE: {
2619 bluetooth_gatt_server_acquire_response_params_t param;
2622 msg = g_dbus_method_invocation_get_message(context);
2623 GUnixFDList *fd_list;
2628 fd_list = g_dbus_message_get_unix_fd_list(msg);
2630 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2632 app = (char*)g_dbus_method_invocation_get_sender(context);
2634 __bt_service_get_parameters(in_param1, ¶m,
2635 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2637 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2638 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2639 fd = fd_list_array[0];
2642 result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
2646 case BT_GATT_SERVER_SEND_INDICATION: {
2647 bluetooth_gatt_server_indication_params_t param;
2648 bluetooth_gatt_att_data_t data;
2649 bluetooth_device_address_t address;
2652 app = (char*)g_dbus_method_invocation_get_sender(context);
2654 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_indication_params_t));
2655 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2656 memset(&address, 0x00, sizeof(bluetooth_device_address_t));
2658 __bt_service_get_parameters(in_param1, &data,
2659 sizeof(bluetooth_gatt_att_data_t));
2660 __bt_service_get_parameters(in_param2, ¶m,
2661 sizeof(bluetooth_gatt_server_indication_params_t));
2662 __bt_service_get_parameters(in_param3, &address,
2663 sizeof(bluetooth_device_address_t));
2665 result = _bt_gatt_server_send_indication(app, &address, &data, ¶m);
2669 case BT_GATT_SERVER_UPDATE_VALUE: {
2670 bluetooth_gatt_server_update_value_t param;
2674 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_update_value_t));
2676 app = (char*)g_dbus_method_invocation_get_sender(context);
2678 __bt_service_get_parameters(in_param1, &instance_id,
2680 __bt_service_get_parameters(in_param2, ¶m,
2681 sizeof(bluetooth_gatt_server_update_value_t));
2683 result = _bt_gatt_server_update_attribute_value(app, instance_id, ¶m);
2686 case BT_GET_ATT_MTU: {
2687 bluetooth_device_address_t address = { {0} };
2688 unsigned int mtu = 0;
2690 __bt_service_get_parameters(in_param1,
2691 &address, sizeof(bluetooth_device_address_t));
2692 result = _bt_get_att_mtu(&address, &mtu);
2693 BT_DBG("MTU: %d", mtu);
2695 if (result == BLUETOOTH_ERROR_NONE) {
2696 g_array_append_vals(*out_param1, &mtu,
2697 sizeof(unsigned int));
2701 case BT_REQ_ATT_MTU: {
2702 bluetooth_device_address_t address = { {0} };
2706 sender = (char*)g_dbus_method_invocation_get_sender(context);
2708 __bt_service_get_parameters(in_param1,
2709 &address, sizeof(bluetooth_device_address_t));
2710 __bt_service_get_parameters(in_param2,
2711 &mtu, sizeof(unsigned int));
2712 BT_DBG("BT_REQ_ATT_MTU: %d", mtu);
2713 result = _bt_request_att_mtu(&address, mtu);
2714 if (BLUETOOTH_ERROR_NONE == result) {
2715 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2717 _bt_convert_addr_type_to_string(addr, address.addr);
2719 /* Save the informations to invocation */
2720 _bt_save_invocation_context(context, result, sender,
2721 function_name, (gpointer)addr);
2723 g_array_append_vals(*out_param1, &address,
2724 sizeof(bluetooth_device_address_t));
2728 case BT_GET_DEVICE_IDA: {
2729 bluetooth_device_address_t address = { {0} };
2730 bluetooth_device_address_t id_addr = { {0} };
2732 __bt_service_get_parameters(in_param1,
2733 &address, sizeof(bluetooth_device_address_t));
2735 result = _bt_device_get_ida(&address, &id_addr);
2737 if (result == BLUETOOTH_ERROR_NONE) {
2738 g_array_append_vals(*out_param1, &id_addr,
2739 sizeof(bluetooth_device_address_t));
2743 case BT_SET_LE_STATIC_RANDOM_ADDRESS: {
2746 __bt_service_get_parameters(in_param1, &is_enable,
2749 result = _bt_set_le_static_random_address(is_enable);
2753 #ifdef TIZEN_GATT_CLIENT
2755 case BT_GATT_CLIENT_REGISTER: {
2756 bluetooth_device_address_t address = { {0} };
2759 sender = (char*)g_dbus_method_invocation_get_sender(context);
2761 __bt_service_get_parameters(in_param1,
2762 &address, sizeof(bluetooth_device_address_t));
2764 result = _bt_register_gatt_client_instance(sender, &address);
2765 if (BLUETOOTH_ERROR_NONE == result) {
2766 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2768 _bt_convert_addr_type_to_string(addr, address.addr);
2770 /* Save the informations to invocation */
2771 _bt_save_invocation_context(context, result, sender,
2772 function_name, (gpointer)addr);
2777 case BT_GATT_CLIENT_UNREGISTER: {
2780 sender = (char*)g_dbus_method_invocation_get_sender(context);
2781 __bt_service_get_parameters(in_param1,
2782 &client_id, sizeof(int));
2784 result = _bt_unregister_gatt_client_instance(sender, client_id);
2788 /* Async: Remote Interaction */
2789 case BT_GATT_ACQUIRE_WRITE: {
2793 bluetooth_gatt_client_char_prop_info_t param;
2795 sender = (char*)g_dbus_method_invocation_get_sender(context);
2797 __bt_service_get_parameters(in_param1, ¶m,
2798 sizeof(bluetooth_gatt_client_char_prop_info_t));
2801 result = _bt_gatt_acquire_write(¶m , &fd, &mtu);
2803 g_array_append_vals(*out_param1, &mtu, sizeof(int));
2805 if (BLUETOOTH_ERROR_NONE == result)
2806 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
2808 BT_ERR("GATT Client: gatt acquire write failed");
2812 GUnixFDList *fd_list = NULL;
2813 GError *error = NULL;
2815 /* Add socket fd to unix_fd_list */
2816 fd_list = g_unix_fd_list_new();
2817 g_unix_fd_list_append(fd_list, fd, &error);
2818 g_assert_no_error(error);
2820 _bt_service_method_return_with_unix_fd_list(
2821 context, *out_param1, result, fd_list);
2824 g_object_unref(fd_list);
2828 /* Async: Remote Interaction */
2829 case BT_CONNECT_LE: {
2830 bluetooth_device_address_t address = { {0} };
2831 gboolean auto_connect;
2835 sender = (char*)g_dbus_method_invocation_get_sender(context);
2837 __bt_service_get_parameters(in_param1,
2838 &address, sizeof(bluetooth_device_address_t));
2839 __bt_service_get_parameters(in_param2,
2840 &auto_connect, sizeof(gboolean));
2841 __bt_service_get_parameters(in_param3,
2842 &client_id, sizeof(int));
2844 BT_DBG("GATT Client: client_id[%d]", client_id);
2845 result = _bt_connect_le_device(&address, auto_connect, client_id);
2846 if (BLUETOOTH_ERROR_NONE == result) {
2847 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2848 _bt_convert_addr_type_to_string(addr, address.addr);
2850 /* Save the informations to invocation */
2851 _bt_save_invocation_context(context, result, sender,
2852 function_name, (gpointer)addr);
2855 _bt_handle_invocation_context(function_name, (void *)addr);
2857 BT_ERR("GATT Client: gatt connect failed. client_id[%d]", client_id);
2858 g_array_append_vals(*out_param1, &address,
2859 sizeof(bluetooth_device_address_t));
2863 /* Async: Remote Interaction */
2864 case BT_DISCONNECT_LE: {
2865 bluetooth_device_address_t address = { {0} };
2869 sender = (char*)g_dbus_method_invocation_get_sender(context);
2871 __bt_service_get_parameters(in_param1,
2872 &address, sizeof(bluetooth_device_address_t));
2873 __bt_service_get_parameters(in_param2,
2874 &client_id, sizeof(int));
2876 BT_INFO("GATT Disconnect using client Interface [%d]", client_id);
2877 result = _bt_disconnect_le_device(&address, client_id);
2878 if (BLUETOOTH_ERROR_NONE == result) {
2879 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2881 _bt_convert_addr_type_to_string(addr, address.addr);
2883 /* Save the informations to invocation */
2884 _bt_save_invocation_context(context, result, sender,
2885 function_name, (gpointer)addr);
2887 g_array_append_vals(*out_param1, &address,
2888 sizeof(bluetooth_device_address_t));
2893 case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS: {
2894 guint available_packets = 0;
2896 result = _bt_gatt_get_data_batching_available_packets(&available_packets);
2897 BT_DBG("LE batching available packets %u", available_packets);
2898 if (result == BLUETOOTH_ERROR_NONE) {
2899 g_array_append_vals(*out_param1, &available_packets,
2906 case BT_ENABLE_GATT_DATA_BATCHING: {
2907 bluetooth_device_address_t address = { {0} };
2908 int packet_threshold;
2911 __bt_service_get_parameters(in_param1,
2912 &address, sizeof(bluetooth_device_address_t));
2913 __bt_service_get_parameters(in_param2,
2914 &packet_threshold, sizeof(int));
2915 __bt_service_get_parameters(in_param3,
2916 &timeout, sizeof(int));
2917 result = _bt_gatt_enable_data_batching(&address, packet_threshold, timeout);
2922 case BT_DISABLE_GATT_DATA_BATCHING: {
2923 bluetooth_device_address_t address = { {0} };
2925 __bt_service_get_parameters(in_param1,
2926 &address, sizeof(bluetooth_device_address_t));
2927 result = _bt_gatt_disable_data_batching(&address);
2932 case BT_GATT_GET_PRIMARY_SERVICES: {
2935 sender = (char*)g_dbus_method_invocation_get_sender(context);
2936 bluetooth_device_address_t address = { {0} };
2938 __bt_service_get_parameters(in_param1, &address,
2939 sizeof(bluetooth_device_address_t));
2941 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
2942 _bt_convert_addr_type_to_string(addr, address.addr);
2944 result = _bt_gatt_get_primary_services(addr);
2945 if (BLUETOOTH_ERROR_NONE == result) {
2946 _bt_save_invocation_context(context, result, sender,
2947 function_name, (gpointer)addr);
2953 case BT_GATT_GET_SERVICE_PROPERTIES: {
2954 bluetooth_gatt_client_svc_prop_info_t param;
2956 sender = (char*)g_dbus_method_invocation_get_sender(context);
2957 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_svc_prop_info_t));
2959 __bt_service_get_parameters(in_param1, ¶m,
2960 sizeof(bluetooth_gatt_client_svc_prop_info_t));
2962 result = _bt_gatt_get_all_characteristic(¶m);
2963 if (BLUETOOTH_ERROR_NONE == result) {
2964 /* Save the informations to invocation */
2965 _bt_save_invocation_context(context, result, sender,
2967 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_svc_prop_info_t)));
2971 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: {
2972 bluetooth_gatt_client_char_prop_info_t param;
2974 sender = (char*)g_dbus_method_invocation_get_sender(context);
2975 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
2977 __bt_service_get_parameters(in_param1, ¶m,
2978 sizeof(bluetooth_gatt_client_char_prop_info_t));
2980 result = _bt_gatt_get_all_characteristic_properties(¶m);
2981 if (BLUETOOTH_ERROR_NONE == result) {
2982 /* Save the informations to invocation */
2983 _bt_save_invocation_context(context, result, sender,
2985 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
2989 /* Async: Remote Interaction */
2990 case BT_GATT_READ_CHARACTERISTIC: {
2991 bluetooth_gatt_client_char_prop_info_t param;
2993 sender = (char*)g_dbus_method_invocation_get_sender(context);
2994 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
2996 __bt_service_get_parameters(in_param1, ¶m,
2997 sizeof(bluetooth_gatt_client_char_prop_info_t));
2999 result = _bt_gatt_read_characteristic_value(¶m);
3000 if (BLUETOOTH_ERROR_NONE == result) {
3001 /* Save the informations to invocation */
3002 _bt_save_invocation_context(context, result, sender,
3004 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3008 /* Async: Remote Interaction */
3009 case BT_GATT_READ_DESCRIPTOR_VALUE: {
3010 bluetooth_gatt_client_desc_prop_info_t param;
3012 sender = (char*)g_dbus_method_invocation_get_sender(context);
3013 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3015 __bt_service_get_parameters(in_param1, ¶m,
3016 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3018 result = _bt_gatt_read_descriptor_value(¶m);
3019 if (BLUETOOTH_ERROR_NONE == result) {
3020 /* Save the informations to invocation */
3021 _bt_save_invocation_context(context, result, sender,
3023 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3027 /* Async: Remote Interaction */
3028 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: {
3029 bluetooth_gatt_client_char_prop_info_t param;
3030 bluetooth_gatt_att_data_t data;
3031 bluetooth_gatt_write_type_e write_type;
3033 sender = (char*)g_dbus_method_invocation_get_sender(context);
3035 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3036 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3038 __bt_service_get_parameters(in_param1, ¶m,
3039 sizeof(bluetooth_gatt_client_char_prop_info_t));
3040 __bt_service_get_parameters(in_param2, &data,
3041 sizeof(bluetooth_gatt_att_data_t));
3042 __bt_service_get_parameters(in_param3, &write_type,
3043 sizeof(bluetooth_gatt_write_type_e));
3045 result = _bt_gatt_write_characteristic_value_by_type(¶m , &data, write_type);
3046 if (BLUETOOTH_ERROR_NONE == result) {
3047 /* Save the informations to invocation */
3048 _bt_save_invocation_context(context, result, sender,
3050 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3054 /* Async: Remote Interaction */
3055 case BT_GATT_WRITE_DESCRIPTOR_VALUE: {
3056 bluetooth_gatt_client_desc_prop_info_t param;
3057 bluetooth_gatt_att_data_t data;
3058 bluetooth_gatt_write_type_e write_type;
3060 sender = (char*)g_dbus_method_invocation_get_sender(context);
3061 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3062 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3064 __bt_service_get_parameters(in_param1, ¶m,
3065 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3066 __bt_service_get_parameters(in_param2, &data,
3067 sizeof(bluetooth_gatt_att_data_t));
3068 __bt_service_get_parameters(in_param3, &write_type,
3069 sizeof(bluetooth_gatt_write_type_e));
3071 result = _bt_gatt_write_descriptor_value_by_type(¶m, &data, write_type);
3072 if (BLUETOOTH_ERROR_NONE == result) {
3073 /* Save the informations to invocation */
3074 _bt_save_invocation_context(context, result, sender,
3076 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3081 case BT_GATT_WATCH_CHARACTERISTIC: {
3082 bluetooth_gatt_client_char_prop_info_t param;
3087 gboolean is_indicate;
3090 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3092 sender = (char*)g_dbus_method_invocation_get_sender(context);
3094 __bt_service_get_parameters(in_param1, ¶m,
3095 sizeof(bluetooth_gatt_client_char_prop_info_t));
3096 __bt_service_get_parameters(in_param2, &client_id,
3098 __bt_service_get_parameters(in_param3, &is_notify,
3100 __bt_service_get_parameters(in_param4, &is_indicate,
3103 #ifdef TIZEN_FEATURE_BT_GATT_CLIENT_FD_DISABLE
3107 if (is_indicate == false) {
3108 result = _bt_gatt_acquire_notify(¶m , &fd, &mtu);
3109 if (BLUETOOTH_ERROR_NONE == result && fd > -1) {
3110 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
3112 GUnixFDList *fd_list = NULL;
3113 GError *error = NULL;
3115 g_array_append_vals(*out_param1, &mtu, sizeof(int));
3116 /* Add socket fd to unix_fd_list */
3117 fd_list = g_unix_fd_list_new();
3118 g_unix_fd_list_append(fd_list, fd, &error);
3119 g_assert_no_error(error);
3121 _bt_service_method_return_with_unix_fd_list(
3122 context, *out_param1, result, fd_list);
3124 g_object_unref(fd_list);
3130 result = _bt_gatt_watch_characteristic(¶m , client_id, is_notify);
3131 if (BLUETOOTH_ERROR_NONE == result) {
3132 /* Save the informations to invocation */
3133 _bt_save_invocation_context(context, result, sender, function_name,
3134 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3139 case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: {
3140 gboolean is_enabled;
3141 bluetooth_device_address_t address;
3143 sender = (char*)g_dbus_method_invocation_get_sender(context);
3145 __bt_service_get_parameters(in_param1,
3146 &address, sizeof(bluetooth_device_address_t));
3147 __bt_service_get_parameters(in_param2, &is_enabled,
3149 result = _bt_gatt_watch_service_changed_indication(sender, &address, is_enabled);
3150 BT_INFO("Service changed indication from app [%s]", sender);
3154 case BT_LE_CONN_UPDATE: {
3155 char *sender = NULL;
3156 bluetooth_device_address_t local_address = { {0} };
3157 bluetooth_le_connection_param_t parameters = {0};
3159 sender = (char *)g_dbus_method_invocation_get_sender(context);
3161 __bt_service_get_parameters(in_param1, &local_address,
3162 sizeof(bluetooth_device_address_t));
3163 __bt_service_get_parameters(in_param2, ¶meters,
3164 sizeof(bluetooth_le_connection_param_t));
3166 result = _bt_le_connection_update(sender,
3168 parameters.interval_min,
3169 parameters.interval_max,
3171 parameters.timeout);
3175 case BT_START_LE_DISCOVERY: {
3179 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3181 sender = (char *)g_dbus_method_invocation_get_sender(context);
3183 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3184 BT_ERR("Fail to get the sender pid");
3186 result = _bt_start_le_scan(sender, uid, pid);
3187 if (result == BLUETOOTH_ERROR_NONE) {
3188 _bt_save_invocation_context(context, result, sender,
3189 function_name, NULL);
3191 BT_DBG("Remeber pid / uid for the scan operation");
3192 _bt_bm_add_scan_app(SCAN_LE, uid, pid);
3196 case BT_STOP_LE_DISCOVERY: {
3200 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3202 sender = (char *)g_dbus_method_invocation_get_sender(context);
3204 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3205 BT_ERR("Fail to get the sender pid");
3207 result = _bt_stop_le_scan(sender);
3208 if (result == BLUETOOTH_ERROR_NONE) {
3209 _bt_save_invocation_context(context, result, sender,
3210 function_name, NULL);
3213 BT_DBG("Remove pid / uid for the scan operation");
3214 _bt_bm_remove_scan_app(SCAN_LE, uid, pid);
3218 case BT_IS_LE_DISCOVERYING: {
3219 gboolean le_discovering = FALSE;
3221 le_discovering = _bt_is_le_scanning();
3222 g_array_append_vals(*out_param1,
3223 &le_discovering, sizeof(gboolean));
3226 case BT_SET_SCAN_PARAMETERS: {
3227 bluetooth_le_scan_params_t scan_params;
3229 __bt_service_get_parameters(in_param1, &scan_params,
3230 sizeof(bluetooth_le_scan_params_t));
3232 BT_DBG("bluetooth_le_scan_params_t [%f %f %d]",
3233 scan_params.interval, scan_params.window,
3236 result = _bt_prepare_scan_parameters(&scan_params, 0);
3239 case BT_SET_SCAN_TYPE: {
3241 __bt_service_get_parameters(in_param1, &scan_type, sizeof(int));
3243 BT_DBG("bluetooth_le_scan_type [%d]", scan_type);
3244 result = _bt_prepare_scan_parameters(NULL, scan_type);
3247 #ifdef TIZEN_FEATURE_BT_PAN_NAP
3248 case BT_NETWORK_ACTIVATE:
3249 BT_DBG("BT_NETWORK_ACTIVATE Request recieved Request Handler ");
3250 result = _bt_network_activate();
3252 case BT_NETWORK_DEACTIVATE:
3253 result = _bt_network_deactivate();
3255 case BT_NETWORK_CONNECT: {
3256 bluetooth_device_address_t address = { {0} };
3259 __bt_service_get_parameters(in_param1,
3260 &address, sizeof(bluetooth_device_address_t));
3261 __bt_service_get_parameters(in_param2,
3262 &role, sizeof(int));
3264 result = _bt_network_connect(request_id, role, &address);
3265 if (result != BLUETOOTH_ERROR_NONE) {
3266 g_array_append_vals(*out_param1, &address,
3267 sizeof(bluetooth_device_address_t));
3271 case BT_NETWORK_DISCONNECT: {
3272 bluetooth_device_address_t address = { {0} };
3274 __bt_service_get_parameters(in_param1,
3275 &address, sizeof(bluetooth_device_address_t));
3277 result = _bt_network_disconnect(request_id, &address);
3278 if (result != BLUETOOTH_ERROR_NONE) {
3279 g_array_append_vals(*out_param1, &address,
3280 sizeof(bluetooth_device_address_t));
3284 case BT_NETWORK_SERVER_DISCONNECT: {
3285 bluetooth_device_address_t address = { {0} };
3287 __bt_service_get_parameters(in_param1,
3288 &address, sizeof(bluetooth_device_address_t));
3290 result = _bt_network_server_disconnect(request_id, &address);
3291 if (result != BLUETOOTH_ERROR_NONE) {
3292 g_array_append_vals(*out_param1, &address,
3293 sizeof(bluetooth_device_address_t));
3299 #ifdef TIZEN_FEATURE_BT_IPSP
3300 case BT_LE_IPSP_INIT:
3301 result = _bt_initialize_ipsp();
3303 case BT_LE_IPSP_DEINIT:
3304 result = _bt_deinitialize_ipsp();
3306 case BT_LE_IPSP_CONNECT: {
3307 bluetooth_device_address_t address = { {0} };
3308 __bt_service_get_parameters(in_param1, &address,
3309 sizeof(bluetooth_device_address_t));
3310 result = _bt_connect_le_ipsp_device(&address);
3313 case BT_LE_IPSP_DISCONNECT: {
3314 bluetooth_device_address_t address = { {0} };
3315 __bt_service_get_parameters(in_param1, &address,
3316 sizeof(bluetooth_device_address_t));
3317 result = _bt_disconnect_le_ipsp_device(&address);
3321 case BT_IS_ADVERTISING: {
3322 gboolean advertising = FALSE;
3323 advertising = _bt_is_advertising();
3324 g_array_append_vals(*out_param1, &advertising,
3328 case BT_IS_LE_2M_PHY_SUPPORTED: {
3329 gboolean is_2m_phy_supported = FALSE;
3331 is_2m_phy_supported = _bt_is_le_2m_phy_supported();
3332 g_array_append_vals(*out_param1, &is_2m_phy_supported, sizeof(gboolean));
3335 case BT_IS_LE_CODED_PHY_SUPPORTED: {
3336 gboolean is_coded_phy_supported = FALSE;
3338 is_coded_phy_supported = _bt_is_le_coded_phy_supported();
3339 g_array_append_vals(*out_param1, &is_coded_phy_supported, sizeof(gboolean));
3342 case BT_DISCONNECT_DEVICE: {
3343 bluetooth_device_address_t address = { {0} };
3345 __bt_service_get_parameters(in_param1,
3346 &address, sizeof(bluetooth_device_address_t));
3348 result = _bt_disconnect_device(&address);
3351 case BT_REGISTER_SCAN_FILTER: {
3352 bluetooth_le_scan_filter_t scan_filter;
3354 sender = (char*)g_dbus_method_invocation_get_sender(context);
3355 __bt_service_get_parameters(in_param1, &scan_filter,
3356 sizeof(bluetooth_le_scan_filter_t));
3358 BT_DBG("bluetooth_le_scan_filter_t [features : 0x%.2x]",
3359 scan_filter.added_features);
3361 result = _bt_register_scan_filter(sender, &scan_filter);
3365 case BT_MESH_NETWORK_CREATE: {
3366 bluetooth_mesh_node_t node;
3367 GSList *model_list = NULL;
3368 int total_models = 0;
3371 const char *network_name = NULL;
3372 bluetooth_mesh_network_t *network;
3374 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
3375 sender = (char*)g_dbus_method_invocation_get_sender(context);
3377 __bt_service_get_parameters(in_param1,
3378 &node, sizeof(bluetooth_mesh_node_t));
3379 network_name = (const char *)g_variant_get_data(in_param2);
3380 BT_INFO("MESH: Network name [%s]", network_name);
3382 param3 = g_array_new(TRUE, TRUE, sizeof(gchar));
3383 __bt_fill_garray_from_variant(in_param3, param3);
3385 total_models = (param3->len) / sizeof(bluetooth_mesh_model_t);
3386 for (i = 0; i < total_models; i++) {
3387 bluetooth_mesh_model_t *info = NULL;
3388 bluetooth_mesh_model_t *mod = NULL;
3390 info = &g_array_index(param3,
3391 bluetooth_mesh_model_t, i);
3393 mod = g_memdup(info, sizeof(bluetooth_mesh_model_t));
3396 model_list = g_slist_append(model_list,
3399 result = _bt_mesh_network_create(requester_unique_creds,
3400 sender, network_name, &node, model_list);
3402 /* Save invocation */
3403 if (result == BLUETOOTH_ERROR_NONE) {
3404 BT_INFO("Mesh: Save Invoation");
3405 network = g_malloc0(sizeof(bluetooth_mesh_network_t));
3407 /* Save Network name & UUID, Token will be received in event */
3408 _bt_mesh_util_convert_hex_to_string(
3409 (uint8_t *) node.uuid, 16,
3411 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
3412 BT_INFO("Mesh: Mesh Netwok UUID [%s]", network->uuid);
3413 g_strlcpy(network->name.name, network_name,
3414 sizeof(network->name.name));
3415 g_strlcpy(network->app_cred,
3416 requester_unique_creds,
3417 sizeof(network->app_cred));
3418 sender = (char*)g_dbus_method_invocation_get_sender(context);
3419 _bt_save_invocation_context(context,
3421 function_name, (gpointer)network);
3423 BT_ERR("Mesh: Mesh Network creation schedule failed");
3424 g_slist_free_full(model_list, g_free);
3428 BT_INFO("Mesh: Cleanup");
3429 g_free((gpointer)requester_unique_creds);
3430 g_array_free(param3, TRUE);
3431 BT_INFO("Mesh: Cleanup Done");
3434 case BT_MESH_NETWORK_SCAN: {
3435 bluetooth_mesh_network_t network;
3436 bluetooth_mesh_scan_param_t param;
3437 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3438 memset(¶m, 0x00, sizeof(bluetooth_mesh_scan_param_t));
3440 __bt_service_get_parameters(in_param1,
3441 &network, sizeof(bluetooth_mesh_network_t));
3443 __bt_service_get_parameters(in_param2,
3444 ¶m, sizeof(bluetooth_mesh_scan_param_t));
3446 result = _bt_mesh_network_scan(requester_unique_creds,
3447 sender, &network, ¶m);
3449 if (result != BLUETOOTH_ERROR_NONE) {
3450 g_array_append_vals(*out_param1,
3451 &network, sizeof(bluetooth_mesh_network_t));
3453 bluetooth_mesh_network_t *net = \
3454 g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3456 sender = (char*)g_dbus_method_invocation_get_sender(context);
3457 _bt_save_invocation_context(context, result, sender,
3458 function_name, (gpointer)net);
3462 case BT_MESH_NETWORK_CANCEL_SCAN: {
3463 bluetooth_mesh_network_t network;
3464 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3466 __bt_service_get_parameters(in_param1,
3467 &network, sizeof(bluetooth_mesh_network_t));
3469 result = _bt_mesh_network_scan_cancel(requester_unique_creds,
3472 if (result != BLUETOOTH_ERROR_NONE)
3473 g_array_append_vals(*out_param1,
3474 &network, sizeof(bluetooth_mesh_network_t));
3477 case BT_MESH_NETWORK_SET_CAPABILITIES: {
3478 bluetooth_mesh_network_t network;
3479 bluetooth_mesh_provisioner_caps_t caps;
3480 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3481 memset(&caps, 0x00, sizeof(bluetooth_mesh_provisioner_caps_t));
3483 __bt_service_get_parameters(in_param1,
3484 &network, sizeof(bluetooth_mesh_network_t));
3486 __bt_service_get_parameters(in_param2,
3487 &caps, sizeof(bluetooth_mesh_provisioner_caps_t));
3489 result = _bt_mesh_network_set_provisioner_caps(
3490 requester_unique_creds, sender, &network, &caps);
3494 case BT_MESH_NETWORK_PROVISION_DEVICE: {
3495 bluetooth_mesh_provisioning_request_t req;
3496 memset(&req, 0x00, sizeof(bluetooth_mesh_provisioning_request_t));
3498 __bt_service_get_parameters(in_param1,
3499 &req, sizeof(bluetooth_mesh_provisioning_request_t));
3501 result = _bt_mesh_network_provision_device(
3502 requester_unique_creds, sender, &req);
3504 /* Save invocation */
3505 if (result != BLUETOOTH_ERROR_NONE) {
3506 g_array_append_vals(*out_param1, &req,
3507 sizeof(bluetooth_mesh_provisioning_request_t));
3509 bluetooth_mesh_provisioning_request_t *param = \
3510 g_memdup(&req, sizeof(bluetooth_mesh_provisioning_request_t));
3512 sender = (char*)g_dbus_method_invocation_get_sender(context);
3513 _bt_save_invocation_context(context, result, sender,
3514 function_name, (gpointer)param);
3518 case BT_MESH_AUTHENTICATION_REPLY: {
3519 const char *auth_value = NULL;
3520 gboolean authentication_reply = FALSE;
3522 auth_value = g_variant_get_data(in_param2);
3523 __bt_service_get_parameters(in_param3,
3524 &authentication_reply, sizeof(gboolean));
3525 __bt_service_get_parameters(in_param1,
3526 &auth_type, sizeof(int));
3527 result = _bt_mesh_authentication_reply(auth_type,
3528 auth_value, authentication_reply);
3531 case BT_MESH_NETWORK_SET_NAME: {
3532 bluetooth_mesh_network_t network;
3533 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3535 __bt_service_get_parameters(in_param1,
3536 &network, sizeof(bluetooth_mesh_network_t));
3538 result = _bt_mesh_network_set_name(requester_unique_creds, sender, &network);
3542 case BT_MESH_NETWORK_ADD_NETKEY: {
3543 bluetooth_mesh_network_t network;
3544 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3546 __bt_service_get_parameters(in_param1,
3547 &network, sizeof(bluetooth_mesh_network_t));
3549 result = _bt_mesh_network_add_netkey(requester_unique_creds,
3552 if (result != BLUETOOTH_ERROR_NONE) {
3553 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3555 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3557 sender = (char*)g_dbus_method_invocation_get_sender(context);
3558 _bt_save_invocation_context(context, result, sender,
3559 function_name, (gpointer)net);
3563 case BT_MESH_NETWORK_DELETE_NETKEY: {
3564 bluetooth_mesh_network_t network;
3567 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3569 __bt_service_get_parameters(in_param1,
3570 &network, sizeof(bluetooth_mesh_network_t));
3571 __bt_service_get_parameters(in_param2,
3572 &index, sizeof(guint16));
3574 result = _bt_mesh_network_delete_netkey(requester_unique_creds,
3575 sender, &network, index);
3577 if (result != BLUETOOTH_ERROR_NONE) {
3578 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3580 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3582 sender = (char*)g_dbus_method_invocation_get_sender(context);
3583 _bt_save_invocation_context(context, result, sender,
3584 function_name, (gpointer)net);
3588 case BT_MESH_NETWORK_UPDATE_NETKEY: {
3589 bluetooth_mesh_network_t network;
3592 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3594 __bt_service_get_parameters(in_param1,
3595 &network, sizeof(bluetooth_mesh_network_t));
3596 __bt_service_get_parameters(in_param2,
3597 &index, sizeof(guint16));
3599 result = _bt_mesh_network_update_netkey(requester_unique_creds,
3600 sender, &network, index);
3602 if (result != BLUETOOTH_ERROR_NONE) {
3603 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3605 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3607 sender = (char*)g_dbus_method_invocation_get_sender(context);
3608 _bt_save_invocation_context(context, result, sender,
3609 function_name, (gpointer)net);
3613 case BT_MESH_NETWORK_ADD_APPKEY: {
3614 bluetooth_mesh_network_t network;
3617 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3619 __bt_service_get_parameters(in_param1,
3620 &network, sizeof(bluetooth_mesh_network_t));
3621 __bt_service_get_parameters(in_param2,
3622 &net_idx, sizeof(guint16));
3624 result = _bt_mesh_network_add_appkey(requester_unique_creds,
3625 sender, &network, net_idx);
3627 if (result != BLUETOOTH_ERROR_NONE) {
3628 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3630 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3632 sender = (char*)g_dbus_method_invocation_get_sender(context);
3633 _bt_save_invocation_context(context, result, sender,
3634 function_name, (gpointer)net);
3638 case BT_MESH_NETWORK_UPDATE_APPKEY: {
3639 bluetooth_mesh_network_t network;
3643 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3645 __bt_service_get_parameters(in_param1,
3646 &network, sizeof(bluetooth_mesh_network_t));
3647 __bt_service_get_parameters(in_param2,
3648 &net_idx, sizeof(guint16));
3649 __bt_service_get_parameters(in_param3,
3650 &app_idx, sizeof(guint16));
3652 result = _bt_mesh_network_update_appkey(requester_unique_creds,
3653 sender, &network, net_idx, app_idx);
3655 if (result != BLUETOOTH_ERROR_NONE) {
3656 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3658 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3660 sender = (char*)g_dbus_method_invocation_get_sender(context);
3661 _bt_save_invocation_context(context, result, sender,
3662 function_name, (gpointer)net);
3666 case BT_MESH_NETWORK_DELETE_APPKEY: {
3667 bluetooth_mesh_network_t network;
3671 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3673 __bt_service_get_parameters(in_param1,
3674 &network, sizeof(bluetooth_mesh_network_t));
3675 __bt_service_get_parameters(in_param2,
3676 &net_idx, sizeof(guint16));
3677 __bt_service_get_parameters(in_param3,
3678 &app_idx, sizeof(guint16));
3680 result = _bt_mesh_network_delete_appkey(requester_unique_creds,
3681 sender, &network, net_idx, app_idx);
3683 if (result != BLUETOOTH_ERROR_NONE) {
3684 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3686 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3688 sender = (char*)g_dbus_method_invocation_get_sender(context);
3689 _bt_save_invocation_context(context, result, sender,
3690 function_name, (gpointer)net);
3694 case BT_MESH_NETWORK_GET_NETKEYS: {
3695 bluetooth_mesh_network_t network;
3696 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3697 __bt_service_get_parameters(in_param1,
3698 &network, sizeof(bluetooth_mesh_network_t));
3699 result = _bt_mesh_network_get_netkeys(requester_unique_creds,
3700 sender, &network, out_param1);
3703 case BT_MESH_NETWORK_GET_APPKEYS: {
3704 bluetooth_mesh_network_t network;
3707 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3708 __bt_service_get_parameters(in_param1,
3709 &network, sizeof(bluetooth_mesh_network_t));
3710 __bt_service_get_parameters(in_param2,
3711 &net_idx, sizeof(guint16));
3712 result = _bt_mesh_network_get_appkeys(requester_unique_creds,
3713 sender, &network, net_idx, out_param1);
3717 BT_INFO("UnSupported function [%d]", function_name);
3718 result = BLUETOOTH_ERROR_NOT_SUPPORT;
3724 #ifdef TIZEN_FEATURE_BT_OBEX
3725 /* Function definitions*/
3726 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
3731 size = g_variant_get_size(var);
3733 data = (char *)g_variant_get_data(var);
3735 param = g_array_append_vals(param, data, size);
3741 int __bt_obexd_request(int function_name,
3744 GDBusMethodInvocation *context,
3745 GVariant *in_param1,
3746 GVariant *in_param2,
3747 GVariant *in_param3,
3748 GVariant *in_param4,
3749 GArray **out_param1)
3753 int result = BLUETOOTH_ERROR_NONE;
3755 BT_DBG("function_name : %x", function_name);
3757 switch (function_name) {
3758 case BT_OPP_PUSH_FILES: {
3759 BT_DBG("BT_OPP_PUSH_FILES");
3761 bluetooth_device_address_t address = { {0} };
3762 bt_file_path_t *path;
3767 __bt_service_get_parameters(in_param1, &address,
3768 sizeof(bluetooth_device_address_t));
3769 __bt_service_get_parameters(in_param3, &file_count,
3772 file_path = g_new0(char *, file_count + 1);
3774 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
3775 __bt_fill_garray_from_variant(in_param2, param2);
3777 for (i = 0; i < file_count; i++) {
3778 path = &g_array_index(param2, bt_file_path_t, i);
3779 file_path[i] = g_strdup(path->path);
3781 BT_DBG("_bt_opp_client_push_files");
3782 result = _bt_opp_client_push_files(request_id, context,
3783 &address, file_path,
3786 for (i = 0; i < file_count; i++)
3787 g_free(file_path[i]);
3790 g_array_free(param2, TRUE);
3794 case BT_OPP_CANCEL_PUSH: {
3795 result = _bt_opp_client_cancel_push();
3799 case BT_OPP_IS_PUSHING_FILES: {
3800 gboolean is_sending = FALSE;
3802 result = _bt_opp_client_is_sending(&is_sending);
3804 g_array_append_vals(*out_param1, &is_sending,
3808 case BT_OPP_GET_TRANSFER_PROGRESS: {
3811 guint8 progress = 0;
3813 __bt_service_get_parameters(in_param1, &direction,
3815 __bt_service_get_parameters(in_param2, &transfer_id,
3818 result = _bt_opp_get_client_progress(&progress);
3820 result = _bt_opp_get_server_progress(transfer_id, &progress);
3822 g_array_append_vals(*out_param1, &progress,
3828 case BT_MAP_CREATE_SESSION: {
3829 BT_DBG("BT_MAP_CREATE_SESSION");
3830 char *address = (char *)g_variant_get_data(in_param1);
3831 char *session_id = NULL;
3832 result = _bt_create_session_sync(address, &session_id);
3833 if (result == BLUETOOTH_ERROR_NONE)
3834 g_array_append_vals(*out_param1, session_id, strlen(session_id)+1);
3838 case BT_MAP_DESTROY_SESSION: {
3839 BT_DBG("BT_MAP_DESTROY_SESSION");
3840 char* session_id = (char *)g_variant_get_data(in_param1);
3841 result = _bt_destroy_session_sync(session_id);
3842 if (result == BLUETOOTH_ERROR_NONE)
3843 BT_DBG("successfully destroyed session");
3847 case BT_MAP_SET_FOLDER: {
3848 BT_DBG("BT_MAP_SET_FOLDER");
3849 char *session_id = (char *)g_variant_get_data(in_param1);
3850 char *name = (char *)g_variant_get_data(in_param2);
3851 result = _bt_map_client_set_folder(session_id, name);
3855 case BT_MAP_LIST_FOLDERS: {
3856 BT_DBG("BT_MAP_LIST_FOLDERS");
3858 char* session_id = (char *)g_variant_get_data(in_param1);
3859 char* filter_serialized = (char*)g_variant_get_data(in_param2);
3861 result = _bt_map_client_list_folders(request_id, context, session_id, filter_serialized);
3862 if (result == BLUETOOTH_ERROR_NONE)
3863 BT_DBG("_bt_map_client_list_folders succeed");
3868 case BT_MAP_LIST_FILTER_FIELDS: {
3869 BT_DBG("BT_MAP_LIST_FILTER_FIELDS");
3871 char* session_id = (char *)g_variant_get_data(in_param1);
3873 result = _bt_map_client_list_filter_fields(request_id, context, session_id);
3874 if (result == BLUETOOTH_ERROR_NONE)
3875 BT_DBG("_bt_map_client_list_filter_fields succeed");
3880 case BT_MAP_LIST_MESSAGES: {
3881 BT_DBG("BT_MAP_LIST_MESSAGES");
3883 char* session_id = (char*)g_variant_get_data(in_param1);
3884 char* folder = (char*)g_variant_get_data(in_param2);
3885 char* filter_serialized = (char*)g_variant_get_data(in_param3);
3887 result = _bt_map_client_list_messages(request_id, context, session_id, folder, filter_serialized);
3888 if (result == BLUETOOTH_ERROR_NONE)
3889 BT_DBG("_bt_map_client_list_messages succeed");
3891 BT_DBG("_bt_map_client_list_messages failed");
3896 case BT_MAP_UPDATE_INBOX: {
3897 BT_DBG("BT_MAP_UPDATE_INBOX");
3898 char* session_id = (char *)g_variant_get_data(in_param1);
3899 result = _bt_map_client_update_inbox(session_id);
3903 case BT_MAP_PUSH_MESSAGE: {
3904 BT_DBG("BT_MAP_PUSH_MESSAGE");
3906 char* session_id = (char *)g_variant_get_data(in_param1);
3907 char* source_file = (char *)g_variant_get_data(in_param2);
3908 char* folder = (char *)g_variant_get_data(in_param3);
3909 char* args_serialized = (char *)g_variant_get_data(in_param4);
3911 result = _bt_map_client_push_message(
3912 request_id, context, session_id, source_file, folder, args_serialized);
3913 if (result == BLUETOOTH_ERROR_NONE)
3914 BT_DBG("_bt_map_client_push_message succeed");
3916 BT_ERR("_bt_map_client_push_message failed");
3921 case BT_MAP_GET_MESSAGE: {
3922 BT_DBG("BT_MAP_GET_MESSAGE");
3923 // TODO session currently is not used, but should be valid
3924 //char* session_id = (char *)g_variant_get_data(in_param1);
3925 char* message_object = (char *)g_variant_get_data(in_param2);
3926 char* target_file = (char *)g_variant_get_data(in_param3);
3927 bool attachment = false;
3928 __bt_service_get_parameters(in_param4, &attachment, sizeof(bool));
3930 result = _bt_map_client_get_message(request_id, context, message_object,
3931 target_file, attachment);
3932 if (result == BLUETOOTH_ERROR_NONE)
3933 BT_DBG("_bt_map_client_get_message succeed");
3938 case BT_OBEX_SERVER_ALLOCATE: {
3944 sender = (char *)g_dbus_method_invocation_get_sender(context);
3946 path = (char *)g_variant_get_data(in_param1);
3947 __bt_service_get_parameters(in_param2, &is_native,
3949 __bt_service_get_parameters(in_param3, &app_pid,
3952 result = _bt_obex_server_allocate(sender,
3953 path, app_pid, is_native);
3957 case BT_OBEX_SERVER_DEALLOCATE: {
3961 __bt_service_get_parameters(in_param1, &is_native,
3963 __bt_service_get_parameters(in_param2, &app_pid,
3966 result = _bt_obex_server_deallocate(app_pid, is_native);
3969 case BT_OBEX_SERVER_IS_ACTIVATED: {
3970 gboolean is_activated = FALSE;
3972 result = _bt_obex_server_is_activated(&is_activated);
3974 g_array_append_vals(*out_param1, &is_activated,
3979 case BT_OBEX_SERVER_ACCEPT_CONNECTION: {
3980 result = _bt_obex_server_accept_connection(request_id);
3984 case BT_OBEX_SERVER_REJECT_CONNECTION: {
3985 result = _bt_obex_server_reject_connection();
3989 case BT_OBEX_SERVER_ACCEPT_FILE: {
3992 file_name = (char *)g_variant_get_data(in_param1);
3994 result = _bt_obex_server_accept_authorize(file_name, TRUE);
3998 case BT_OBEX_SERVER_REJECT_FILE: {
3999 result = _bt_obex_server_reject_authorize();
4003 case BT_OBEX_SERVER_SET_PATH: {
4005 char *destination_path;
4007 destination_path = (char *)g_variant_get_data(in_param1);
4008 __bt_service_get_parameters(in_param2, &is_native,
4011 result = _bt_obex_server_set_destination_path(destination_path,
4016 case BT_OBEX_SERVER_SET_ROOT: {
4019 root = (char *)g_variant_get_data(in_param1);
4021 result = _bt_obex_server_set_root(root);
4025 case BT_OBEX_SERVER_CANCEL_TRANSFER: {
4028 __bt_service_get_parameters(in_param1, &transfer_id,
4031 result = _bt_obex_server_cancel_transfer(transfer_id);
4035 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS: {
4036 result = _bt_obex_server_cancel_all_transfers();
4040 case BT_OBEX_SERVER_IS_RECEIVING: {
4041 gboolean is_receiving = FALSE;
4043 result = _bt_obex_server_is_receiving(&is_receiving);
4045 g_array_append_vals(*out_param1, &is_receiving,
4049 case BT_PBAP_CONNECT: {
4050 bluetooth_device_address_t address = { {0} };
4052 __bt_service_get_parameters(in_param1, &address,
4053 sizeof(bluetooth_device_address_t));
4055 result = _bt_pbap_connect(&address);
4058 case BT_PBAP_DISCONNECT: {
4059 bluetooth_device_address_t address = { {0} };
4061 __bt_service_get_parameters(in_param1, &address,
4062 sizeof(bluetooth_device_address_t));
4064 result = _bt_pbap_disconnect(&address);
4067 case BT_PBAP_GET_PHONEBOOK_SIZE: {
4068 bluetooth_device_address_t address = { {0} };
4069 bt_pbap_folder_t folder = { 0, };
4071 __bt_service_get_parameters(in_param1, &address,
4072 sizeof(bluetooth_device_address_t));
4073 __bt_service_get_parameters(in_param2, &folder,
4074 sizeof(bt_pbap_folder_t));
4076 result = _bt_pbap_get_phonebook_size(&address,
4077 folder.addressbook, folder.folder_type);
4080 case BT_PBAP_GET_PHONEBOOK: {
4081 bluetooth_device_address_t address = { {0} };
4082 bt_pbap_folder_t folder = { 0, };
4083 bt_pbap_pull_parameters_t app_param = { 0, };
4085 __bt_service_get_parameters(in_param1, &address,
4086 sizeof(bluetooth_device_address_t));
4087 __bt_service_get_parameters(in_param2, &folder,
4088 sizeof(bt_pbap_folder_t));
4089 __bt_service_get_parameters(in_param3, &app_param,
4090 sizeof(bt_pbap_pull_parameters_t));
4092 result = _bt_pbap_get_phonebook(&address, folder.addressbook,
4093 folder.folder_type, &app_param);
4096 case BT_PBAP_GET_LIST: {
4097 bluetooth_device_address_t address = { {0} };
4098 bt_pbap_folder_t folder = { 0, };
4099 bt_pbap_list_parameters_t app_param = { 0, };
4101 __bt_service_get_parameters(in_param1, &address,
4102 sizeof(bluetooth_device_address_t));
4103 __bt_service_get_parameters(in_param2, &folder,
4104 sizeof(bt_pbap_folder_t));
4105 __bt_service_get_parameters(in_param3, &app_param,
4106 sizeof(bt_pbap_list_parameters_t));
4108 result = _bt_pbap_get_list(&address, folder.addressbook,
4109 folder.folder_type, &app_param);
4112 case BT_PBAP_PULL_VCARD: {
4113 bluetooth_device_address_t address = { {0} };
4114 bt_pbap_folder_t folder = { 0, };
4115 bt_pbap_pull_vcard_parameters_t app_param = { 0, };
4117 __bt_service_get_parameters(in_param1, &address,
4118 sizeof(bluetooth_device_address_t));
4119 __bt_service_get_parameters(in_param2, &folder,
4120 sizeof(bt_pbap_folder_t));
4121 __bt_service_get_parameters(in_param3, &app_param,
4122 sizeof(bt_pbap_pull_vcard_parameters_t));
4124 result = _bt_pbap_pull_vcard(&address, folder.addressbook,
4125 folder.folder_type, &app_param);
4128 case BT_PBAP_PHONEBOOK_SEARCH: {
4129 bluetooth_device_address_t address = { {0} };
4130 bt_pbap_folder_t folder = { 0, };
4131 bt_pbap_search_parameters_t app_param = { 0, };
4133 __bt_service_get_parameters(in_param1, &address,
4134 sizeof(bluetooth_device_address_t));
4135 __bt_service_get_parameters(in_param2, &folder,
4136 sizeof(bt_pbap_folder_t));
4137 __bt_service_get_parameters(in_param3, &app_param,
4138 sizeof(bt_pbap_search_parameters_t));
4140 result = _bt_pbap_phonebook_search(&address, folder.addressbook,
4141 folder.folder_type, &app_param);
4146 BT_ERR("Unknown function!");
4147 result = BLUETOOTH_ERROR_INTERNAL;
4156 int __bt_agent_request(int function_name,
4159 GDBusMethodInvocation *context,
4160 GVariant *in_param1,
4161 GVariant *in_param2,
4162 GVariant *in_param3,
4163 GVariant *in_param4,
4164 GArray **out_param1)
4167 switch (function_name) {
4168 case BT_SET_AUTHORIZATION: {
4175 sender = (char *)g_dbus_method_invocation_get_sender(context);
4176 __bt_service_get_parameters(in_param1, &type, sizeof(int));
4177 uuid = (char *)g_variant_get_data(in_param2);
4178 path = (char *)g_variant_get_data(in_param3);
4179 __bt_service_get_parameters(in_param4, &fd, sizeof(int));
4181 result = _bt_register_osp_server_in_agent(sender, type, uuid, path, fd);
4184 case BT_UNSET_AUTHORIZATION: {
4188 __bt_service_get_parameters(in_param1, &type, sizeof(int));
4189 uuid = (char *)g_variant_get_data(in_param2);
4191 result = _bt_unregister_osp_server_in_agent(type, uuid);
4195 BT_ERR("Unknown function!");
4196 result = BLUETOOTH_ERROR_INTERNAL;
4203 int __bt_core_request(int function_name,
4206 GDBusMethodInvocation *context,
4207 GVariant *in_param1)
4211 switch (function_name) {
4212 case BT_ENABLE_ADAPTER:
4215 _bt_set_adapter_request_state(TRUE);
4216 status = _bt_adapter_get_status();
4218 if (status == BT_ACTIVATING) {
4219 BT_DBG("Enabling in progress");
4220 result = BLUETOOTH_ERROR_IN_PROGRESS;
4221 } else if (status == BT_ACTIVATED) {
4222 BT_DBG("Already enabled");
4223 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
4225 _bt_adapter_set_status(BT_ACTIVATING);
4226 result = BLUETOOTH_ERROR_NONE;
4231 case BT_DISABLE_ADAPTER:
4235 status = _bt_adapter_get_status();
4236 if (status == BT_DEACTIVATING) {
4237 BT_DBG("Disabling in progress");
4238 result = BLUETOOTH_ERROR_IN_PROGRESS;
4239 } else if (status == BT_DEACTIVATED) {
4240 BT_DBG("Already disabled");
4241 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
4243 _bt_adapter_set_status(BT_DEACTIVATING);
4244 result = BLUETOOTH_ERROR_NONE;
4249 case BT_ENABLE_ADAPTER_LE:
4251 bt_le_status_t le_status;
4252 _bt_set_le_request_state(TRUE);
4253 le_status = _bt_adapter_get_le_status();
4254 if (le_status == BT_LE_ACTIVATING) {
4255 BT_DBG("Enabling in progress");
4256 result = BLUETOOTH_ERROR_IN_PROGRESS;
4257 } else if (le_status == BT_LE_ACTIVATED) {
4258 BT_DBG("Already enabled");
4259 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
4261 _bt_adapter_set_le_status(BT_LE_ACTIVATING);
4262 result = BLUETOOTH_ERROR_NONE;
4267 case BT_DISABLE_ADAPTER_LE:
4269 bt_le_status_t le_status;
4271 le_status = _bt_adapter_get_le_status();
4272 if (le_status == BT_LE_DEACTIVATING) {
4273 BT_DBG("Disabling in progress");
4274 result = BLUETOOTH_ERROR_IN_PROGRESS;
4275 } else if (le_status == BT_LE_DEACTIVATED) {
4276 BT_DBG("Already disabled");
4277 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
4279 _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
4280 result = BLUETOOTH_ERROR_NONE;
4286 BT_ERR("Unknown function!");
4287 result = BLUETOOTH_ERROR_INTERNAL;
4294 gboolean __bt_service_check_privilege(int function_name,
4296 const char *unique_name)
4299 gboolean result = TRUE;
4300 char *client_creds = NULL;
4301 char *user_creds = NULL;
4302 char *client_session = "";
4303 enum cynara_client_creds client_creds_method = CLIENT_METHOD_SMACK;
4304 enum cynara_user_creds user_creds_method = USER_METHOD_UID;
4305 char err_msg[256] = {0, };
4307 retv_if(unique_name == NULL, FALSE);
4308 retv_if(bt_service_conn == NULL, FALSE);
4310 ret_val = cynara_creds_get_default_client_method(&client_creds_method);
4311 if (ret_val != CYNARA_API_SUCCESS) {
4312 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
4313 BT_ERR("Fail to get default client method: %s", err_msg);
4317 ret_val = cynara_creds_get_default_user_method(&user_creds_method);
4318 if (ret_val != CYNARA_API_SUCCESS) {
4319 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
4320 BT_ERR("Fail to get default user method: %s", err_msg);
4324 ret_val = cynara_creds_gdbus_get_client(bt_service_conn, unique_name, client_creds_method, &client_creds);
4325 if (ret_val != CYNARA_API_SUCCESS) {
4326 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
4327 BT_ERR("Fail to get client credential: %s", err_msg);
4331 ret_val = cynara_creds_gdbus_get_user(bt_service_conn, unique_name, user_creds_method, &user_creds);
4332 if (ret_val != CYNARA_API_SUCCESS) {
4333 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
4334 BT_ERR("Fail to get user credential: %s", err_msg);
4340 // BT_DBG("%s, %s, %s", unique_name, client_creds, user_creds);
4342 switch (function_name) {
4343 case BT_SET_LOCAL_NAME:
4344 case BT_START_DISCOVERY:
4345 case BT_START_CUSTOM_DISCOVERY:
4346 case BT_CANCEL_DISCOVERY:
4347 case BT_OOB_ADD_REMOTE_DATA:
4348 case BT_OOB_REMOVE_REMOTE_DATA:
4349 case BT_OOB_READ_LOCAL_DATA:
4350 case BT_SET_ADVERTISING:
4351 case BT_SET_CUSTOM_ADVERTISING:
4352 case BT_SET_ADVERTISING_PARAMETERS:
4353 case BT_START_LE_DISCOVERY:
4354 case BT_STOP_LE_DISCOVERY:
4355 case BT_SET_SCAN_PARAMETERS:
4356 case BT_SET_SCAN_TYPE:
4358 case BT_BOND_DEVICE:
4359 case BT_CANCEL_BONDING:
4360 case BT_UNBOND_DEVICE:
4362 case BT_SET_AUTHORIZATION:
4363 case BT_UNSET_AUTHORIZATION:
4364 case BT_SEARCH_SERVICE:
4366 case BT_RFCOMM_CLIENT_CONNECT:
4367 if (function_name == BT_RFCOMM_CLIENT_CONNECT)
4368 BT_PERMANENT_LOG("Connect socket");
4369 case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
4370 case BT_RFCOMM_SOCKET_DISCONNECT:
4371 if (function_name == BT_RFCOMM_SOCKET_DISCONNECT)
4372 BT_PERMANENT_LOG("Disconnect socket");
4373 case BT_RFCOMM_SOCKET_WRITE:
4374 case BT_RFCOMM_CREATE_SOCKET:
4375 case BT_RFCOMM_REMOVE_SOCKET:
4376 case BT_RFCOMM_SEND_RX_DETAILS:
4377 case BT_RFCOMM_SEND_TX_DETAILS:
4378 case BT_RFCOMM_UPDATE_CONNECTION_INFO:
4380 case BT_OPP_PUSH_FILES:
4381 case BT_OPP_CANCEL_PUSH:
4382 /* TODO: MAP? MAP functions, see above */
4384 case BT_OBEX_SERVER_ACCEPT_CONNECTION:
4385 case BT_OBEX_SERVER_REJECT_CONNECTION:
4386 case BT_OBEX_SERVER_ACCEPT_FILE:
4387 case BT_OBEX_SERVER_REJECT_FILE:
4388 case BT_OBEX_SERVER_SET_PATH:
4389 case BT_OBEX_SERVER_SET_ROOT:
4390 case BT_OBEX_SERVER_CANCEL_TRANSFER:
4391 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS:
4393 case BT_AUDIO_SELECT_ROLE:
4394 case BT_AUDIO_CONNECT:
4395 case BT_AUDIO_DISCONNECT:
4397 case BT_AG_DISCONNECT:
4399 case BT_AV_DISCONNECT:
4400 case BT_AV_SOURCE_CONNECT:
4401 case BT_AV_SOURCE_DISCONNECT:
4402 case BT_AVRCP_TARGET_CONNECT:
4403 case BT_AVRCP_TARGET_DISCONNECT:
4404 case BT_AVRCP_CONTROL_CONNECT:
4405 case BT_AVRCP_CONTROL_DISCONNECT:
4406 case BT_AVRCP_HANDLE_CONTROL:
4407 case BT_AVRCP_SET_TRACK_INFO:
4408 case BT_AVRCP_SET_PROPERTY:
4409 case BT_AVRCP_SET_PROPERTIES:
4410 case BT_AVRCP_CONTROL_SET_PROPERTY:
4412 #ifdef TIZEN_FEATURE_BT_AVC_TARGET
4413 case BT_AUDIO_SET_ABSOLUTE_VOLUME:
4414 case BT_AUDIO_GET_ABSOLUTE_VOLUME:
4415 case BT_AUDIO_IS_AVC_ACTIVATED:
4419 case BT_HF_DISCONNECT:
4421 case BT_HID_CONNECT:
4422 case BT_HID_DISCONNECT:
4424 case BT_HID_DEVICE_ACTIVATE:
4425 case BT_HID_DEVICE_DEACTIVATE:
4426 case BT_HID_DEVICE_CONNECT:
4427 case BT_HID_DEVICE_DISCONNECT:
4428 case BT_HID_DEVICE_SEND_MOUSE_EVENT:
4429 case BT_HID_DEVICE_SEND_KEY_EVENT:
4430 case BT_HID_DEVICE_SEND_REPLY_TO_REPORT:
4431 case BT_HID_DEVICE_SEND_CUSTOM_EVENT:
4434 case BT_DISCONNECT_LE:
4436 case BT_SET_ADVERTISING_DATA:
4437 case BT_SET_SCAN_RESPONSE_DATA:
4439 case BT_HDP_CONNECT:
4440 case BT_HDP_DISCONNECT:
4441 case BT_HDP_SEND_DATA:
4442 case BT_HDP_REGISTER_SINK_APP:
4443 case BT_HDP_UNREGISTER_SINK_APP:
4446 case BT_DPM_SET_ALLOW_BT_MODE:
4447 case BT_DPM_GET_ALLOW_BT_MODE:
4448 case BT_DPM_SET_DEVICE_RESTRITION:
4449 case BT_DPM_GET_DEVICE_RESTRITION:
4450 case BT_DPM_SET_UUID_RESTRITION:
4451 case BT_DPM_GET_UUID_RESTRITION:
4452 case BT_DPM_ADD_DEVICES_BLACKLIST:
4453 case BT_DPM_ADD_DEVICES_WHITELIST:
4454 case BT_DPM_ADD_UUIDS_BLACKLIST:
4455 case BT_DPM_ADD_UUIDS_WHITELIST:
4456 case BT_DPM_CLEAR_DEVICES_BLACKLIST:
4457 case BT_DPM_CLEAR_DEVICES_WHITELIST:
4458 case BT_DPM_CLEAR_UUIDS_BLACKLIST:
4459 case BT_DPM_CLEAR_UUIDS_WHITELIST:
4460 case BT_DPM_REMOVE_DEVICE_BLACKLIST:
4461 case BT_DPM_REMOVE_DEVICE_WHITELIST:
4462 case BT_DPM_REMOVE_UUID_BLACKLIST:
4463 case BT_DPM_REMOVE_UUID_WHITELIST:
4464 case BT_DPM_GET_DEVICES_BLACKLIST:
4465 case BT_DPM_GET_DEVICES_WHITELIST:
4466 case BT_DPM_GET_UUIDS_BLACKLIST:
4467 case BT_DPM_GET_UUIDS_WHITELIST:
4468 case BT_DPM_SET_ALLOW_OUTGOING_CALL:
4469 case BT_DPM_GET_ALLOW_OUTGOING_CALL:
4470 case BT_DPM_SET_PAIRING_STATE:
4471 case BT_DPM_GET_PAIRING_STATE:
4472 case BT_DPM_SET_PROFILE_STATE:
4473 case BT_DPM_GET_PROFILE_STATE:
4474 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE:
4475 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE:
4476 case BT_DPM_SET_DISCOVERABLE_STATE:
4477 case BT_DPM_GET_DISCOVERABLE_STATE:
4478 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE:
4479 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE:
4480 case BT_DPM_SET_DATA_TRANSFER_STATE:
4481 case BT_DPM_GET_DATA_TRANSFER_STATE:
4483 case BT_NETWORK_ACTIVATE:
4484 case BT_NETWORK_DEACTIVATE:
4485 case BT_NETWORK_CONNECT:
4486 case BT_NETWORK_DISCONNECT:
4487 case BT_NETWORK_SERVER_DISCONNECT:
4489 case BT_GATT_GET_PRIMARY_SERVICES:
4490 #ifdef TIZEN_GATT_CLIENT
4491 case BT_GATT_GET_SERVICE_PROPERTIES: /* GATT Client */
4492 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: /* GATT Client */
4493 case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: /* GATT Client */
4495 case BT_GATT_DISCOVER_CHARACTERISTICS:
4496 case BT_GATT_SET_PROPERTY_REQUEST:
4497 case BT_GATT_READ_CHARACTERISTIC:
4498 #ifdef TIZEN_GATT_CLIENT
4499 case BT_GATT_READ_DESCRIPTOR_VALUE: /* GATT Client */
4500 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: /* GATT Client */
4501 case BT_GATT_ACQUIRE_WRITE:
4502 case BT_GATT_WRITE_DESCRIPTOR_VALUE: /* GATT Client */
4503 case BT_GATT_WATCH_CHARACTERISTIC: /* GATT Client */
4504 case BT_GATT_CLIENT_REGISTER: /* GATT Client */
4505 case BT_GATT_CLIENT_UNREGISTER: /* GATT Client */
4507 case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
4508 case BT_GATT_REGISTER_APPLICATION:
4509 case BT_GATT_REGISTER_SERVICE:
4510 case BT_GATT_SEND_RESPONSE:
4512 case BT_GATT_SERVER_REGISTER:
4513 case BT_GATT_SERVER_ADD_SERVICE:
4514 case BT_GATT_SERVER_ADD_CHARACTERISTIC:
4515 case BT_GATT_SERVER_ADD_DESCRIPTOR:
4516 case BT_GATT_SERVER_START_SERVICE:
4517 case BT_GATT_SERVER_STOP_SERVICE:
4518 case BT_GATT_SERVER_DELETE_SERVICE:
4519 case BT_GATT_SERVER_SEND_RESPONSE:
4520 case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE:
4521 case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE:
4522 case BT_GATT_SERVER_SEND_INDICATION:
4523 case BT_GATT_SERVER_UPDATE_VALUE:
4524 case BT_GATT_SERVER_DEREGISTER:
4526 case BT_REQ_ATT_MTU:
4527 case BT_PBAP_CONNECT:
4528 case BT_PBAP_DISCONNECT:
4529 case BT_PBAP_GET_PHONEBOOK_SIZE:
4530 case BT_PBAP_GET_PHONEBOOK:
4531 case BT_PBAP_GET_LIST:
4532 case BT_PBAP_PULL_VCARD:
4533 case BT_PBAP_PHONEBOOK_SEARCH:
4535 case BT_RFCOMM_LISTEN_AND_ACCEPT:
4536 case BT_MESH_NETWORK_CREATE:
4537 case BT_MESH_NETWORK_SCAN:
4538 case BT_MESH_NETWORK_CANCEL_SCAN:
4539 case BT_MESH_NETWORK_SET_CAPABILITIES:
4540 case BT_MESH_NETWORK_PROVISION_DEVICE:
4541 case BT_MESH_AUTHENTICATION_REPLY:
4542 case BT_MESH_NETWORK_SET_NAME:
4543 case BT_MESH_NETWORK_ADD_NETKEY:
4544 case BT_MESH_NETWORK_DELETE_NETKEY:
4545 case BT_MESH_NETWORK_UPDATE_NETKEY:
4546 case BT_MESH_NETWORK_ADD_APPKEY:
4547 case BT_MESH_NETWORK_DELETE_APPKEY:
4548 case BT_MESH_NETWORK_UPDATE_APPKEY:
4549 case BT_MESH_NETWORK_GET_NETKEYS:
4550 case BT_MESH_NETWORK_GET_APPKEYS:
4552 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
4553 BT_PRIVILEGE_PUBLIC);
4555 BT_INFO("Client Credentials [%s]", client_creds);
4556 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
4557 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PUBLIC);
4561 /* Need to check mediastorage privilege */
4562 if (function_name == BT_PBAP_GET_PHONEBOOK ||
4563 function_name == BT_PBAP_PULL_VCARD) {
4564 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
4565 MEDIASTORAGE_PRIVILEGE);
4567 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
4568 BT_ERR("Fail to access: %s", MEDIASTORAGE_PRIVILEGE);
4574 case BT_ENABLE_ADAPTER:
4575 case BT_DISABLE_ADAPTER:
4576 case BT_RESET_ADAPTER:
4577 case BT_RECOVER_ADAPTER:
4578 case BT_BATTERY_READ_DATA:
4579 case BT_ENABLE_ADAPTER_LE:
4580 case BT_DISABLE_ADAPTER_LE:
4581 case BT_SET_CONNECTABLE:
4582 case BT_SET_DISCOVERABLE_MODE:
4583 case BT_ADD_WHITE_LIST:
4584 case BT_REMOVE_WHITE_LIST:
4585 case BT_CLEAR_WHITE_LIST:
4586 case BT_SET_MANUFACTURER_DATA:
4588 case BT_CANCEL_SEARCH_SERVICE:
4589 case BT_ENABLE_RSSI:
4590 case BT_DISCONNECT_DEVICE:
4592 case BT_RFCOMM_ACCEPT_CONNECTION:
4593 case BT_RFCOMM_REJECT_CONNECTION:
4594 case BT_RFCOMM_LISTEN:
4596 case BT_HID_ENABLE_BARCODE_FEATURE:
4598 case BT_AVRCP_CONTROL_GET_PROPERTY:
4599 case BT_AVRCP_GET_TRACK_INFO:
4600 case BT_AVRCP_TRANSPORT_SET_PROPERTY:
4601 case BT_AVRCP_HANDLE_CONTROL_TO_DEST:
4603 case BT_SET_CONTENT_PROTECT:
4604 case BT_BOND_DEVICE_BY_TYPE:
4605 case BT_SET_LE_PRIVACY:
4606 case BT_SET_LE_STATIC_RANDOM_ADDRESS:
4607 case BT_LE_CONN_UPDATE:
4608 case BT_UPDATE_LE_CONNECTION_MODE:
4609 case BT_GET_DEVICE_IDA:
4610 case BT_LE_READ_MAXIMUM_DATA_LENGTH:
4611 case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH:
4612 case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH:
4613 case BT_LE_SET_DATA_LENGTH:
4614 case BT_LE_OOB_READ_LOCAL_DATA:
4615 case BT_LE_OOB_ADD_REMOTE_DATA:
4617 case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS:
4618 case BT_ENABLE_GATT_DATA_BATCHING:
4619 case BT_DISABLE_GATT_DATA_BATCHING:
4621 case BT_LE_IPSP_INIT:
4622 case BT_LE_IPSP_DEINIT:
4623 case BT_LE_IPSP_CONNECT:
4624 case BT_LE_IPSP_DISCONNECT:
4625 case BT_PXP_MONITOR_SET_PROPERTY:
4626 case BT_PXP_MONITOR_GET_PROPERTY:
4627 case BT_PXP_MONITOR_GET_SUPPORTED_SERIVCES:
4628 case BT_PXP_REPORTER_REGISTER:
4629 case BT_PXP_REPORTER_UNREGISTER:
4630 case BT_PXP_REPORTER_GET_PROPERTY:
4633 case BT_TDS_PROVIDER_REGISTER:
4634 case BT_TDS_PROVIDER_UNREGISTER:
4635 case BT_TDS_PROVIDER_SET_MANUF_DATA:
4636 case BT_TDS_PROVIDER_CREATE:
4637 case BT_TDS_PROVIDER_DESTROY:
4638 case BT_TDS_PROVIDER_SET_TRANSPORT_DATA:
4639 case BT_TDS_SEND_ACTIVATION_RESPONSE:
4640 case BT_TDS_READ_TRANSPORT_DATA:
4641 case BT_TDS_ENABLE_CONTROL_POINT:
4642 case BT_TDS_ACTIVATE_CONTROL_POINT:
4645 case BT_OTP_SERVER_INIT:
4646 case BT_OTP_SERVER_DEINIT:
4647 case BT_OTP_READ_VALUE:
4648 case BT_OTP_ENABLE_NOTIFICATION:
4649 case BT_OTP_WRITE_VALUE:
4650 case BT_LE_OTC_CONNECT:
4651 case BT_LE_OTC_DISCONNECT:
4653 case BT_MAP_CREATE_SESSION:
4654 case BT_MAP_DESTROY_SESSION:
4655 case BT_MAP_SET_FOLDER:
4656 case BT_MAP_LIST_FOLDERS:
4657 case BT_MAP_LIST_FILTER_FIELDS:
4658 case BT_MAP_LIST_MESSAGES:
4659 case BT_MAP_UPDATE_INBOX:
4660 case BT_MAP_PUSH_MESSAGE:
4661 case BT_MAP_GET_MESSAGE:
4663 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
4664 BT_PRIVILEGE_PLATFORM);
4666 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
4667 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PLATFORM);
4672 case BT_CHECK_ADAPTER:
4675 case BT_GET_LOCAL_NAME:
4676 case BT_GET_LOCAL_ADDRESS:
4677 case BT_GET_LOCAL_VERSION:
4678 case BT_IS_SERVICE_USED:
4679 case BT_GET_DISCOVERABLE_MODE:
4680 case BT_GET_DISCOVERABLE_TIME:
4681 case BT_IS_DISCOVERYING:
4682 case BT_IS_LE_DISCOVERYING:
4683 case BT_IS_CONNECTABLE:
4684 case BT_GET_CONNECTABLE:
4685 case BT_GET_BONDED_DEVICES:
4686 case BT_GET_PROFILE_CONNECTED_DEVICES:
4687 case BT_GET_BONDED_DEVICE:
4688 case BT_PASSKEY_REPLY:
4689 case BT_PASSKEY_CONFIRMATION_REPLY:
4690 case BT_GET_IS_ALIAS_SET:
4691 case BT_IS_DEVICE_CONNECTED:
4692 case BT_GET_CONNECTED_LINK_TYPE:
4693 case BT_SET_PROFILE_TRUSTED:
4694 case BT_GET_PROFILE_TRUSTED:
4695 case BT_GET_SPEAKER_GAIN:
4696 case BT_SET_SPEAKER_GAIN:
4697 case BT_RFCOMM_CLIENT_IS_CONNECTED:
4698 case BT_RFCOMM_IS_UUID_AVAILABLE:
4699 case BT_GET_ADVERTISING_DATA:
4700 case BT_GET_SCAN_RESPONSE_DATA:
4701 case BT_IS_ADVERTISING:
4702 case BT_IS_LE_2M_PHY_SUPPORTED:
4703 case BT_IS_LE_CODED_PHY_SUPPORTED:
4704 case BT_REGISTER_SCAN_FILTER:
4705 case BT_IS_SCAN_FILTER_SUPPORTED:
4706 case BT_GET_ATT_MTU:
4708 case BT_OBEX_SERVER_ALLOCATE:
4709 case BT_OBEX_SERVER_DEALLOCATE:
4710 case BT_OBEX_SERVER_IS_ACTIVATED:
4711 case BT_OPP_GET_TRANSFER_PROGRESS:
4712 /* Non-privilege control */
4715 BT_ERR("Unknown function!");
4720 if (client_creds && function_name >= BT_FUNC_MESH_BASE) {
4721 BT_INFO("MESH Function called creds [%s]", client_creds);
4722 requester_unique_creds = g_strdup(client_creds);
4726 BT_INFO("Non MESH Function called client creds [%s]", client_creds);
4734 GDBusNodeInfo *__bt_service_create_method_node_info
4735 (const gchar *introspection_data)
4738 GDBusNodeInfo *node_info = NULL;
4740 if (introspection_data == NULL) {
4741 BT_ERR("Introspection XML not present");
4745 node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
4748 BT_ERR("Unable to create node: %s", err->message);
4749 g_clear_error(&err);
4754 int __bt_service_register_object(GDBusConnection *conn,
4755 GDBusNodeInfo *node_info, gboolean reg)
4757 static guint service_id = 0;
4758 GError *error = NULL;
4761 if (node_info == NULL)
4764 service_id = g_dbus_connection_register_object(conn,
4766 node_info->interfaces[0],
4768 NULL, NULL, &error);
4769 if (service_id == 0)
4772 if (service_id > 0) {
4773 g_dbus_connection_unregister_object(conn,
4782 static void __name_owner_changed(GDBusConnection *connection,
4783 const gchar *sender_name,
4784 const gchar *object_path,
4785 const gchar *interface_name,
4786 const gchar *signal_name,
4787 GVariant *parameters,
4790 const char *name = NULL;
4791 const char *old_owner = NULL;
4792 const char *new_owner = NULL;
4794 g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
4795 if (*new_owner != '\0')
4798 _bt_check_hdp_app_termination(name);
4800 /* Advertising App Termination */
4801 _bt_check_adv_app_termination(name);
4803 /* Check if le_scanning app is terminated */
4804 _bt_check_le_scanner_app_termination(name);
4806 /* Check if RFCOMM app is terminated */
4807 _bt_rfcomm_check_termination(name);
4810 static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
4811 const gchar *name, gpointer user_data)
4813 GDBusNodeInfo *node_info = NULL;
4815 BT_INFO("bus acquired");
4817 ret_if(connection == NULL);
4819 node_info = __bt_service_create_method_node_info(
4820 bt_service_introspection_xml);
4821 ret_if(node_info == NULL);
4823 __bt_service_register_object(connection, node_info, TRUE);
4824 g_dbus_node_info_unref(node_info);
4826 bt_service_conn = connection;
4829 static void __bt_service_name_acquired_handler(GDBusConnection *connection,
4830 const gchar *name, gpointer user_data)
4832 BT_INFO("name acquired");
4833 name_acquired = TRUE;
4836 static void __bt_service_name_lost_handler(GDBusConnection *connection,
4837 const gchar *name, gpointer user_data)
4839 BT_INFO("name lost");
4840 name_acquired = FALSE;
4843 gboolean _is_name_acquired(void)
4845 return name_acquired;
4848 void _bt_service_unref_connection(void)
4852 if (bt_service_conn) {
4853 g_dbus_connection_flush_sync(bt_service_conn, NULL, NULL);
4854 g_object_unref(bt_service_conn);
4855 bt_service_conn = NULL;
4861 int _bt_service_register(void)
4863 GDBusConnection *conn;
4866 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
4867 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
4868 bt_service_conn = conn;
4870 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
4872 G_BUS_NAME_OWNER_FLAGS_NONE,
4873 __bt_service_bus_acquired_handler,
4874 __bt_service_name_acquired_handler,
4875 __bt_service_name_lost_handler,
4877 BT_DBG("owner_id is [%d]", owner_id);
4881 /* Subscribe for name owner changed signal */
4882 owner_sig_id = g_dbus_connection_signal_subscribe(conn,
4883 BT_FREEDESKTOP_SERVICE, BT_FREEDESKTOP_INTERFACE,
4884 BT_NAME_OWNER_CHANGED, NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
4885 __name_owner_changed, NULL, NULL);
4886 BT_INFO("owner_sig_id: %d", owner_sig_id);
4888 return BLUETOOTH_ERROR_NONE;
4891 if (bt_service_conn) {
4892 g_object_unref(bt_service_conn);
4893 bt_service_conn = NULL;
4896 return BLUETOOTH_ERROR_INTERNAL;
4899 void _bt_service_unregister(void)
4901 if (bt_service_conn) {
4902 sd_notify(0, "STOPPING=1");
4904 if (owner_sig_id > 0) {
4905 g_dbus_connection_signal_unsubscribe(
4906 bt_service_conn, owner_sig_id);
4911 g_bus_unown_name(owner_id);
4915 __bt_service_register_object(bt_service_conn, NULL, FALSE);
4919 int _bt_service_cynara_init(void)
4922 char err_msg[256] = {0, };
4924 retv_if(p_cynara != NULL, BLUETOOTH_ERROR_ALREADY_INITIALIZED);
4926 result = cynara_initialize(&p_cynara, conf);
4928 if (result != CYNARA_API_SUCCESS) {
4929 cynara_strerror(result, err_msg, sizeof(err_msg));
4930 BT_ERR("Fail to initialize cynara: [%s]", err_msg);
4931 return BLUETOOTH_ERROR_INTERNAL;
4934 return BLUETOOTH_ERROR_NONE;
4937 void _bt_service_cynara_deinit(void)
4940 char err_msg[256] = {0, };
4942 ret_if(p_cynara == NULL);
4944 result = cynara_finish(p_cynara);
4946 if (result != CYNARA_API_SUCCESS) {
4947 cynara_strerror(result, err_msg, sizeof(err_msg));
4948 BT_ERR("Fail to finish cynara: [%s]", err_msg);
4956 void _bt_service_method_return(GDBusMethodInvocation *invocation,
4957 GArray *out_param, int result)
4961 out_var = g_variant_new_from_data((const GVariantType *)"ay",
4962 out_param->data, out_param->len, TRUE, NULL, NULL);
4964 g_dbus_method_invocation_return_value(invocation,
4965 g_variant_new("(iv)", result, out_var));
4968 void _bt_service_method_return_with_unix_fd_list(GDBusMethodInvocation *invocation,
4969 GArray *out_param, int result, GUnixFDList *fd_list)
4973 out_var = g_variant_new_from_data((const GVariantType *)"ay",
4974 out_param->data, out_param->len, TRUE, NULL, NULL);
4976 g_dbus_method_invocation_return_value_with_unix_fd_list(invocation,
4977 g_variant_new("(iv)", result, out_var), fd_list);