2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <gio/gunixfdlist.h>
24 #include <cynara-client.h>
25 #include <cynara-creds-gdbus.h>
26 #include <systemd/sd-daemon.h>
29 #include "bluetooth-api.h"
30 #include "bluetooth-audio-api.h"
31 #include "bluetooth-gatt-server-api.h"
32 #include "bluetooth-mesh-api.h"
33 #include "bt-request-handler.h"
34 #include "bt-service-common.h"
35 #include "bt-service-util.h"
37 #include "bt-service-core-adapter.h"
38 #include "bt-service-core-adapter-le.h"
39 #include "bt-service-core-device.h"
41 #include "bt-service-audio-common.h"
42 #include "bt-service-avrcp-tg.h"
43 #include "bt-service-avrcp-ctrl.h"
44 #include "bt-service-gatt.h"
45 #include "bt-service-mesh-main.h"
46 #include "bt-service-mesh-util.h"
47 #include "bt-service-mesh-network.h"
48 #include "bt-service-mesh-config-client.h"
49 #include "bt-service-mesh-model.h"
50 #include "bt-service-dpm.h"
51 #include "bt-service-hidhost.h"
52 #include "bt-service-rfcomm.h"
53 #include "bt-service-hdp.h"
54 #include "bt-service-tds.h"
57 #include "bt-service-obex-server.h"
58 #include "bt-service-opp-client.h"
59 #include "bt-service-map-client.h"
60 #include "bt-service-pbap.h"
61 #include "bt-service-oob.h"
63 #include "bt-service-battery-monitor.h"
65 #include "bt-service-l2cap-le.h"
67 #ifdef TIZEN_FEATURE_BT_PAN_NAP
68 #include "bt-service-network.h"
71 #ifdef TIZEN_FEATURE_BT_IPSP
72 #include "bt-service-ipsp.h"
74 /* For maintaining Application Sync API call requests */
75 static GSList *invocation_list = NULL;
77 #ifdef TIZEN_FEATURE_BT_CONTAINER
80 gboolean is_container;
82 static GSList *nspid_list = NULL;
85 static GDBusConnection *bt_service_conn;
86 static guint owner_id = 0;
87 static guint owner_sig_id = 0;
88 static gboolean is_le_intended = FALSE;
90 static cynara *p_cynara;
91 static cynara_configuration *conf;
92 static const char *requester_unique_creds = NULL;
94 static const gchar bt_service_introspection_xml[] =
95 "<node name='/org/projectx/bt_service'>"
96 " <interface name='org.projectx.bt'>"
97 " <method name='service_request'>"
98 /* Input Parameters */
99 " <arg type='i' name='service_type' direction='in' />"
100 " <arg type='i' name='service_function' direction='in' />"
101 " <arg type='i' name='request_type' direction='in' />"
102 " <arg type='ay' name='input_param1' direction='in' />"
103 " <arg type='ay' name='input_param2' direction='in' />"
104 " <arg type='ay' name='input_param3' direction='in' />"
105 " <arg type='ay' name='input_param4' direction='in' />"
106 " <arg type='ay' name='input_param5' direction='in' />"
107 /* Return Parameters */
108 " <arg type='i' name='output_param1' direction='out' />"
109 " <arg type='v' name='output_param2' direction='out' />"
111 " <method name='get_avc_mode'>"
113 " <arg type='u' name='avc_mode' direction='out' />"
118 static gboolean name_acquired = FALSE;
120 static char *current_sender_playing = NULL;
122 GDBusNodeInfo *node_info_g = NULL;
124 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param);
126 static void __bt_service_method(GDBusConnection *connection,
128 const gchar *object_path,
129 const gchar *interface_name,
130 const gchar *method_name,
131 GVariant *parameters,
132 GDBusMethodInvocation *invocation,
135 int __bt_bluez_request(int function_name,
138 GDBusMethodInvocation *context,
143 GArray **out_param1);
144 int __bt_obexd_request(int function_name,
147 GDBusMethodInvocation *context,
152 GArray **out_param1);
153 int __bt_agent_request(int function_name,
156 GDBusMethodInvocation *context,
161 GArray **out_param1);
162 int __bt_core_request(int function_name,
165 GDBusMethodInvocation *context,
166 GVariant *in_param1);
168 gboolean __bt_service_check_privilege(int function_name,
170 const char *unique_name);
172 /* Function definitions*/
173 GSList *_bt_get_invocation_list(void)
175 return invocation_list;
178 void _bt_free_info_from_invocation_list(invocation_info_t *req_info)
180 ret_if(NULL == req_info);
181 invocation_list = g_slist_remove(invocation_list, req_info);
182 g_free(req_info->sender);
183 g_free(req_info->user_data);
187 void _bt_set_le_intended_status(gboolean value)
189 is_le_intended = value;
192 static void __bt_service_get_parameters(GVariant *in_param,
193 void *value, int size)
196 buf = (void *)g_variant_get_data(in_param);
197 memcpy(value, buf, size);
200 static gboolean __bt_is_sync_function(int service_function)
202 /*TODO: Keep adding sync methods with expect replies from bluetooth service */
203 if (service_function == BT_GET_LOCAL_ADDRESS
204 || service_function == BT_GET_LOCAL_NAME
205 || service_function == BT_GET_LOCAL_VERSION
206 || service_function == BT_GET_BONDED_DEVICES
207 || service_function == BT_GET_BONDED_DEVICE
208 || service_function == BT_GET_PROFILE_CONNECTED_DEVICES
209 || service_function == BT_GET_IS_ALIAS_SET
210 || service_function == BT_GET_CONNECTED_LINK_TYPE
211 || service_function == BT_IS_SERVICE_USED
212 || service_function == BT_RFCOMM_LISTEN_AND_ACCEPT
213 || service_function == BT_RFCOMM_LISTEN
214 || service_function == BT_HDP_REGISTER_SINK_APP
215 || service_function == BT_HDP_UNREGISTER_SINK_APP
216 || service_function == BT_HDP_GET_FD
217 || service_function == BT_AVRCP_GET_TRACK_INFO
218 || service_function == BT_AVRCP_CONTROL_GET_PROPERTY
219 || service_function == BT_SET_ADVERTISING_DATA
220 || service_function == BT_SET_SCAN_RESPONSE_DATA
221 || service_function == BT_SET_ADVERTISING
222 || service_function == BT_SET_CUSTOM_ADVERTISING
223 || service_function == BT_GATT_SERVER_REGISTER
224 || service_function == BT_GATT_SERVER_ADD_SERVICE
225 || service_function == BT_GATT_SERVER_ADD_CHARACTERISTIC
226 || service_function == BT_GATT_SERVER_ADD_DESCRIPTOR
227 || service_function == BT_GATT_SERVER_START_SERVICE
228 || service_function == BT_GATT_SERVER_STOP_SERVICE
229 || service_function == BT_GATT_SERVER_DELETE_SERVICE
230 || service_function == BT_START_LE_DISCOVERY
231 || service_function == BT_STOP_LE_DISCOVERY
232 || service_function == BT_GET_CONNECTABLE
233 || service_function == BT_GATT_CLIENT_REGISTER
234 || service_function == BT_GATT_GET_PRIMARY_SERVICES
235 || service_function == BT_GATT_GET_SERVICE_PROPERTIES
236 || service_function == BT_GATT_GET_INCLUDED_SERVICES
237 || service_function == BT_GATT_GET_CHARACTERISTIC_PROPERTIES
238 || service_function == BT_GATT_WATCH_CHARACTERISTIC
239 || service_function == BT_GATT_ACQUIRE_WRITE
240 || service_function == BT_AUDIO_SELECT_ROLE
242 || service_function == BT_MESH_INIT
243 || service_function == BT_MESH_NETWORK_CREATE
244 || service_function == BT_MESH_NETWORK_DESTROY
245 || service_function == BT_MESH_NETWORK_LOAD
246 || service_function == BT_MESH_NETWORK_SCAN
247 || service_function == BT_MESH_NETWORK_ADD_NETKEY
248 || service_function == BT_MESH_NETWORK_DELETE_NETKEY
249 || service_function == BT_MESH_NETWORK_UPDATE_NETKEY
250 || service_function == BT_MESH_NETWORK_ADD_APPKEY
251 || service_function == BT_MESH_NETWORK_DELETE_APPKEY
252 || service_function == BT_MESH_NETWORK_UPDATE_APPKEY
253 || service_function == BT_L2CAP_LE_LISTEN_AND_ACCEPT
254 || service_function == BT_L2CAP_LE_LISTEN
255 || service_function == BT_REQ_ATT_MTU)
261 void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
262 char *sender, int service_function,
263 gpointer invocation_data)
265 invocation_info_t *info;
266 info = g_malloc0(sizeof(invocation_info_t));
267 info->context = invocation;
268 info->result = result;
269 info->sender = g_strdup(sender);
270 info->service_function = service_function;
271 info->user_data = invocation_data;
272 invocation_list = g_slist_append(invocation_list, info);
276 static int __bt_service_get_sender_pid(const char *unique_name, pid_t *pid)
279 char err_msg[256] = {0, };
281 retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
283 ret = cynara_creds_gdbus_get_pid(bt_service_conn, unique_name, pid);
284 if (ret != CYNARA_API_SUCCESS) {
285 cynara_strerror(ret, err_msg, sizeof(err_msg));
286 BT_ERR("Fail to get user credential: %s", err_msg);
288 return BLUETOOTH_ERROR_INTERNAL;
291 return BLUETOOTH_ERROR_NONE;
294 static int __bt_bm_request_data(_bt_battery_data_t *latest)
296 int ret = _bt_bm_read_data(latest);
297 if (ret == BLUETOOTH_ERROR_NONE) {
298 BT_DBG("Received data from bluetooth battery monitor: %ld %ld %d %d",
299 latest->session_start_time, latest->session_end_time,
300 latest->session_scan_time, latest->session_connected_time);
302 if (latest->atm_list == NULL) {
303 BT_DBG("No app data transaction for this session");
307 for (GSList *l = latest->atm_list; l != NULL; l = g_slist_next(l)) {
308 _bt_battery_app_data_t *t = (_bt_battery_app_data_t *)(l->data);
309 BT_DBG("%ld %ld %d %d", (long int)(t->uid), (long int)(t->pid), t->rx_bytes, t->tx_bytes);
313 BT_ERR("Error encountered");
317 static void __bt_service_method(GDBusConnection *connection,
319 const gchar *object_path,
320 const gchar *interface_name,
321 const gchar *method_name,
322 GVariant *parameters,
323 GDBusMethodInvocation *invocation,
328 BT_DBG("Method[%s] Object Path[%s] Interface Name[%s]",
329 method_name, object_path, interface_name);
331 if (g_strcmp0(method_name, "service_request") == 0) {
333 int service_function;
335 GVariant *param1 = NULL;
336 GVariant *param2 = NULL;
337 GVariant *param3 = NULL;
338 GVariant *param4 = NULL;
339 GVariant *param5 = NULL;
340 GArray *out_param1 = NULL;
341 GVariant *out_var = NULL;
342 GVariant *temp = NULL;
345 const char *unique_name = NULL;
347 g_variant_get(parameters, "(iii@ay@ay@ay@ay@ay)", &service_type,
348 &service_function, &request_type,
349 ¶m1, ¶m2, ¶m3, ¶m4, ¶m5);
351 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
353 #ifdef TIZEN_FEATURE_BT_CONTAINER
354 /* In case of the bt-service in container, only privilege check request is coming
355 * from the bt-service in host. At this time, the original sender's privilege
356 * should be checked not bt-service's privilege */
357 if (_bt_service_is_container() == TRUE)
358 unique_name = (const char *)g_variant_get_data(param1);
360 unique_name = sender;
362 unique_name = sender;
365 if (service_type == BT_CORE_SERVICE) {
366 BT_DBG("No need to check privilege from bt-core");
367 } else if (__bt_service_check_privilege(service_function,
368 service_type, unique_name) == FALSE) {
369 BT_ERR("Client don't have the privilege to excute this function");
370 result = BLUETOOTH_ERROR_PERMISSION_DEINED;
374 BT_DBG("SERVICE TYPE [%d] SERVICE FUNC [%d]",
375 service_type, service_function);
376 switch (service_type) {
377 case BT_BLUEZ_SERVICE:
378 result = __bt_bluez_request(service_function,
379 request_type, request_id,
380 invocation, param1, param2,
381 param3, param4, &out_param1);
383 case BT_OBEX_SERVICE:
384 result = __bt_obexd_request(service_function,
385 request_type, request_id,
388 param4, &out_param1);
390 case BT_AGENT_SERVICE:
391 result = __bt_agent_request(service_function,
392 request_type, request_id,
395 param4, &out_param1);
397 case BT_CORE_SERVICE:
398 result = __bt_core_request(service_function,
399 request_type, request_id,
402 case BT_CHECK_PRIVILEGE:
403 result = BLUETOOTH_ERROR_NONE;
406 BT_ERR("Unknown service type");
407 result = BLUETOOTH_ERROR_INTERNAL;
411 if (result != BLUETOOTH_ERROR_NONE)
414 if (service_type == BT_CHECK_PRIVILEGE)
417 if (service_function == BT_OPP_PUSH_FILES)
420 if (request_type == BT_ASYNC_REQ ||
421 __bt_is_sync_function(service_function)) {
422 /* Do not send reply to bt-api over dbus,
423 Invocation context is already saved in service_function */
428 out_var = g_variant_new_from_data((const GVariantType *)"ay",
429 out_param1->data, out_param1->len,
432 temp = g_variant_new("(iv)", result, out_var);
433 g_dbus_method_invocation_return_value(invocation, temp);
434 g_array_free(out_param1, TRUE);
438 g_variant_unref(param1);
439 g_variant_unref(param2);
440 g_variant_unref(param3);
441 g_variant_unref(param4);
442 g_variant_unref(param5);
446 BT_ERR_C("Request is failed [%s] [0x%x]",
447 _bt_convert_error_to_string(result), result);
449 out_var = g_variant_new_from_data((const GVariantType *)"ay",
450 out_param1->data, out_param1->len,
453 temp = g_variant_new("(iv)", result, out_var);
454 g_dbus_method_invocation_return_value(invocation, temp);
456 g_array_free(out_param1, TRUE);
459 g_variant_unref(param1);
460 g_variant_unref(param2);
461 g_variant_unref(param3);
462 g_variant_unref(param4);
463 g_variant_unref(param5);
465 else if (g_strcmp0(method_name, "get_avc_mode") == 0) {
466 unsigned int mode = 0;
468 if (_bt_audio_get_avc_mode(&mode) != BLUETOOTH_ERROR_NONE)
469 BT_ERR("Fail to get the avc mode");
471 BT_DBG("Absolute Volume Control mode: %d", mode);
473 g_dbus_method_invocation_return_value(invocation,
474 g_variant_new("(u)", mode));
482 static const GDBusInterfaceVTable method_table = {
489 int __bt_bluez_request(int function_name,
492 GDBusMethodInvocation *context,
499 int result = BLUETOOTH_ERROR_NONE;
502 switch (function_name) {
503 case BT_ENABLE_ADAPTER: {
504 result = _bt_enable_adapter();
505 _bt_adapter_start_enable_timer();
508 case BT_DISABLE_ADAPTER: {
509 result = _bt_disable_adapter();
512 case BT_RECOVER_ADAPTER:
513 result = _bt_recover_adapter();
515 case BT_RESET_ADAPTER:
516 result = _bt_reset_adapter();
518 case BT_BATTERY_READ_DATA: {
519 _bt_battery_data_t *data = NULL;
520 data = g_malloc0(sizeof(_bt_battery_data_t));
521 result = __bt_bm_request_data(data);
523 bt_battery_dbus_data_t dbus_data;
524 memset(&dbus_data, 0, sizeof(bt_battery_dbus_data_t));
525 dbus_data.session_start_time = data->session_start_time;
526 dbus_data.session_end_time = data->session_end_time;
527 dbus_data.session_scan_time = data->session_scan_time;
528 dbus_data.session_connected_time = data->session_connected_time;
529 dbus_data.tx_time = data->tx_time;
530 dbus_data.rx_time = data->rx_time;
531 dbus_data.idle_time = data->idle_time;
533 /*Populating app data*/
535 for (GSList *l = data->atm_list; l != NULL; l = g_slist_next(l)) {
536 bt_battery_app_data *t = (bt_battery_app_data *)(l->data);
537 memcpy(&dbus_data.app_data[n], t, sizeof(bt_battery_app_data));
540 dbus_data.num_app = n;
541 g_array_append_vals(*out_param1, &dbus_data, sizeof(bt_battery_dbus_data_t));
542 g_slist_free_full(data->atm_list, g_free);
547 case BT_CHECK_ADAPTER: {
548 int enabled = BT_ADAPTER_DISABLED;
549 result = _bt_check_adapter(&enabled);
551 g_array_append_vals(*out_param1, &enabled,
555 case BT_ENABLE_ADAPTER_LE:
556 _bt_set_le_intended_status(TRUE);
557 result = _bt_enable_adapter_le();
559 case BT_DISABLE_ADAPTER_LE:
560 _bt_set_le_intended_status(FALSE);
561 result = _bt_disable_adapter_le();
563 case BT_START_DISCOVERY: {
564 unsigned short max_response;
565 unsigned short discovery_duration;
566 unsigned int classOfDeviceMask;
569 __bt_service_get_parameters(in_param1,
570 &max_response, sizeof(unsigned short));
571 __bt_service_get_parameters(in_param2,
572 &discovery_duration, sizeof(unsigned short));
573 __bt_service_get_parameters(in_param3,
574 &classOfDeviceMask, sizeof(unsigned int));
575 __bt_service_get_parameters(in_param4, &uid, sizeof(uid_t));
577 result = _bt_start_discovery(max_response, discovery_duration, classOfDeviceMask);
579 if (result == BLUETOOTH_ERROR_NONE) {
582 sender = (char*)g_dbus_method_invocation_get_sender(context);
584 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
585 BT_ERR("Fail to get the sender pid");
587 BT_DBG("Remeber pid / uid for the scan operation");
588 _bt_bm_add_scan_app(SCAN_REGACY, uid, pid);
593 case BT_START_CUSTOM_DISCOVERY: {
594 bt_discovery_role_type_t role;
596 __bt_service_get_parameters(in_param1,
597 &role, sizeof(bt_discovery_role_type_t));
598 result = _bt_start_custom_discovery(role);
602 case BT_CANCEL_DISCOVERY:
603 result = _bt_cancel_discovery();
605 case BT_IS_DISCOVERYING: {
606 gboolean discovering = FALSE;
607 discovering = _bt_is_discovering();
608 g_array_append_vals(*out_param1,
609 &discovering, sizeof(gboolean));
612 case BT_GET_LOCAL_ADDRESS: {
613 result = _bt_get_local_address();
615 /* Save invocation */
616 if (result == BLUETOOTH_ERROR_NONE) {
617 sender = (char*)g_dbus_method_invocation_get_sender(context);
618 _bt_save_invocation_context(context, result, sender,
619 function_name, NULL);
623 case BT_GET_LOCAL_VERSION: {
624 result = _bt_get_local_version();
626 /* Save invocation */
627 if (result == BLUETOOTH_ERROR_NONE) {
628 sender = (char*)g_dbus_method_invocation_get_sender(context);
629 _bt_save_invocation_context(context, result, sender,
630 function_name, NULL);
634 case BT_GET_LOCAL_NAME: {
635 result = _bt_get_local_name();
637 /* Save invocation */
638 if (result == BLUETOOTH_ERROR_NONE) {
639 sender = (char*)g_dbus_method_invocation_get_sender(context);
640 _bt_save_invocation_context(context, result, sender,
641 function_name, NULL);
645 case BT_SET_LOCAL_NAME: {
646 bluetooth_device_name_t local_name = { {0} };
647 __bt_service_get_parameters(in_param1,
648 &local_name, sizeof(bluetooth_device_name_t));
649 result = _bt_set_local_name(local_name.name);
652 case BT_GET_DISCOVERABLE_MODE: {
653 int discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
654 result = _bt_get_discoverable_mode(&discoverable_mode);
655 g_array_append_vals(*out_param1, &discoverable_mode, sizeof(int));
658 case BT_GET_DISCOVERABLE_TIME: {
661 result = _bt_get_timeout_value(&timeout);
662 g_array_append_vals(*out_param1, &timeout, sizeof(int));
665 case BT_SET_DISCOVERABLE_MODE: {
666 int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
669 __bt_service_get_parameters(in_param1, &mode, sizeof(int));
670 __bt_service_get_parameters(in_param2, &time, sizeof(int));
672 result = _bt_set_discoverable_mode(mode, time);
675 case BT_IS_CONNECTABLE: {
676 gboolean is_connectable = FALSE;
678 is_connectable = _bt_is_connectable();
679 g_array_append_vals(*out_param1, &is_connectable, sizeof(gboolean));
682 case BT_GET_CONNECTABLE: {
683 result = _bt_get_connectable();
685 /* Save invocation */
686 if (result == BLUETOOTH_ERROR_NONE) {
687 sender = (char*)g_dbus_method_invocation_get_sender(context);
688 _bt_save_invocation_context(context, result, sender,
689 function_name, NULL);
693 case BT_SET_CONNECTABLE: {
694 gboolean is_connectable;
696 __bt_service_get_parameters(in_param1,
697 &is_connectable, sizeof(gboolean));
698 result = _bt_set_connectable(is_connectable);
701 case BT_IS_SERVICE_USED: {
704 uuid = (char *)g_variant_get_data(in_param1);
705 BT_INFO("UUID to be searched [%s]", uuid);
706 result = _bt_is_service_used();
708 /* Save invocation */
709 if (result == BLUETOOTH_ERROR_NONE) {
710 sender = (char*)g_dbus_method_invocation_get_sender(context);
711 _bt_save_invocation_context(context, result, sender,
712 function_name, g_strdup(uuid));
716 case BT_GET_BONDED_DEVICES: {
717 result = _bt_get_bonded_devices();
718 /* Save invocation */
719 if (result == BLUETOOTH_ERROR_NONE) {
720 sender = (char*)g_dbus_method_invocation_get_sender(context);
721 _bt_save_invocation_context(context, result, sender,
722 function_name, NULL);
726 case BT_GET_BONDED_DEVICE: {
727 bluetooth_device_address_t address = { {0} };
729 __bt_service_get_parameters(in_param1,
730 &address, sizeof(bluetooth_device_address_t));
732 result = _bt_get_bonded_device_info(&address);
733 /* Save invocation */
734 if (result == BLUETOOTH_ERROR_NONE) {
735 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
737 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
741 _bt_convert_addr_type_to_string(addr, address.addr);
742 sender = (char*)g_dbus_method_invocation_get_sender(context);
743 _bt_save_invocation_context(context, result, sender,
744 function_name, addr);
748 case BT_GET_PROFILE_CONNECTED_DEVICES: {
750 uuid = (char *)g_variant_get_data(in_param1);
751 result = _bt_get_profile_connected_devices(uuid);
753 /* Save invocation */
754 if (result == BLUETOOTH_ERROR_NONE) {
755 sender = (char *)g_dbus_method_invocation_get_sender(context);
756 _bt_save_invocation_context(context, result, sender,
757 function_name, NULL);
762 bluetooth_device_address_t address = { {0} };
763 const char *local_name;
765 __bt_service_get_parameters(in_param1,
766 &address, sizeof(bluetooth_device_address_t));
767 local_name = (const char *)g_variant_get_data(in_param2);
769 result = _bt_set_alias(&address, local_name);
772 case BT_BOND_DEVICE: {
773 bluetooth_device_address_t address = { {0} };
775 __bt_service_get_parameters(in_param1,
776 &address, sizeof(bluetooth_device_address_t));
777 result = _bt_bond_device(&address, BLUETOOTH_DEV_CONN_DEFAULT, out_param1);
779 /* Save invocation */
780 if (result == BLUETOOTH_ERROR_NONE) {
781 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
782 _bt_convert_addr_type_to_string(addr, address.addr);
783 sender = (char*)g_dbus_method_invocation_get_sender(context);
784 _bt_save_invocation_context(context, result, sender,
785 function_name, (gpointer)addr);
787 bluetooth_device_info_t dev_info;
789 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
790 memcpy(&dev_info.device_address, &address,
791 sizeof(bluetooth_device_address_t));
792 g_array_append_vals(*out_param1, &dev_info,
793 sizeof(bluetooth_device_info_t));
797 case BT_BOND_DEVICE_BY_TYPE: {
798 bluetooth_device_address_t address = { {0} };
799 unsigned short conn_type = 0;
801 __bt_service_get_parameters(in_param1,
802 &address, sizeof(bluetooth_device_address_t));
803 __bt_service_get_parameters(in_param2,
804 &conn_type, sizeof(unsigned short));
806 result = _bt_bond_device(&address, conn_type, 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 bluetooth_device_info_t dev_info;
817 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
818 memcpy(&dev_info.device_address, &address,
819 sizeof(bluetooth_device_address_t));
820 g_array_append_vals(*out_param1, &dev_info,
821 sizeof(bluetooth_device_info_t));
825 case BT_UNBOND_DEVICE: {
826 bluetooth_device_address_t address = { {0} };
828 __bt_service_get_parameters(in_param1,
829 &address, sizeof(bluetooth_device_address_t));
830 result = _bt_unbond_device(&address, out_param1);
832 /* Save invocation */
833 if (result == BLUETOOTH_ERROR_NONE) {
834 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
835 _bt_convert_addr_type_to_string(addr, address.addr);
836 sender = (char*)g_dbus_method_invocation_get_sender(context);
837 _bt_save_invocation_context(context, result, sender,
838 function_name, (gpointer)addr);
840 g_array_append_vals(*out_param1, &address,
841 sizeof(bluetooth_device_address_t));
845 case BT_CANCEL_BONDING:{
846 result = _bt_cancel_bonding();
849 case BT_SEARCH_SERVICE: {
850 bluetooth_device_address_t address = { {0} };
851 __bt_service_get_parameters(in_param1,
852 &address, sizeof(bluetooth_device_address_t));
853 result = _bt_search_device(&address);
854 /* Save invocation */
855 if (result == BLUETOOTH_ERROR_NONE) {
856 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
857 _bt_convert_addr_type_to_string(addr, address.addr);
858 sender = (char*)g_dbus_method_invocation_get_sender(context);
859 _bt_save_invocation_context(context, result, sender,
860 function_name, (gpointer)addr);
862 bt_sdp_info_t sdp_info;
864 memset(&sdp_info, 0x00, sizeof(bt_sdp_info_t));
865 memcpy(&sdp_info.device_addr, &address,
866 sizeof(bluetooth_device_address_t));
867 g_array_append_vals(*out_param1, &sdp_info, sizeof(bt_sdp_info_t));
871 case BT_CANCEL_SEARCH_SERVICE: {
872 result = _bt_cancel_search_device();
875 case BT_SET_PASSKEY_NOTIFICATION: {
879 sender = (char *)g_dbus_method_invocation_get_sender(context);
880 __bt_service_get_parameters(in_param1,
881 &enable, sizeof(gboolean));
883 result = _bt_set_passkey_notification(sender, enable);
886 case BT_SET_PIN_CODE: {
887 bluetooth_device_address_t address = { {0} };
888 bluetooth_device_pin_code_t pin_code = { {0} };
890 __bt_service_get_parameters(in_param1,
891 &address, sizeof(bluetooth_device_address_t));
892 __bt_service_get_parameters(in_param2,
893 &pin_code, sizeof(bluetooth_device_pin_code_t));
895 result = _bt_set_pin_code(&address, &pin_code);
898 case BT_UNSET_PIN_CODE: {
899 bluetooth_device_address_t address = { {0} };
901 __bt_service_get_parameters(in_param1,
902 &address, sizeof(bluetooth_device_address_t));
904 result = _bt_unset_pin_code(&address);
907 case BT_PASSKEY_REPLY: {
908 const char *passkey = NULL;
909 gboolean authentication_reply = FALSE;
910 passkey = g_variant_get_data(in_param1);
911 __bt_service_get_parameters(in_param2,
912 &authentication_reply, sizeof(gboolean));
913 result = _bt_passkey_reply(passkey, authentication_reply);
916 case BT_PASSKEY_CONFIRMATION_REPLY: {
917 gboolean confirmation_reply = FALSE;
918 __bt_service_get_parameters(in_param1,
919 &confirmation_reply, sizeof(gboolean));
920 result = _bt_passkey_confirmation_reply(confirmation_reply);
923 case BT_GET_IS_ALIAS_SET: {
924 bluetooth_device_address_t address = { {0} };
926 __bt_service_get_parameters(in_param1,
927 &address, sizeof(bluetooth_device_address_t));
929 result = _bt_is_alias_set(&address);
930 if (result == BLUETOOTH_ERROR_NONE) {
931 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
933 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
937 _bt_convert_addr_type_to_string(addr, address.addr);
938 sender = (char*)g_dbus_method_invocation_get_sender(context);
939 _bt_save_invocation_context(context, result, sender,
940 function_name, addr);
944 case BT_SET_AUTHORIZATION: {
945 bluetooth_device_address_t address = { {0} };
947 __bt_service_get_parameters(in_param1,
948 &address, sizeof(bluetooth_device_address_t));
949 __bt_service_get_parameters(in_param2,
950 &authorize, sizeof(gboolean));
951 result = _bt_set_authorization(&address, authorize);
954 case BT_SET_LE_PRIVACY: {
955 gboolean set_privacy;
956 __bt_service_get_parameters(in_param1, &set_privacy,
958 result = _bt_set_le_privacy(set_privacy);
961 case BT_ADD_ALLOW_LIST: {
962 bluetooth_device_address_t address = { {0} };
963 int address_type = 0;
965 __bt_service_get_parameters(in_param1,
966 &address, sizeof(bluetooth_device_address_t));
967 __bt_service_get_parameters(in_param2,
968 &address_type, sizeof(int));
969 result = _bt_set_allow_list(&address, address_type, is_add);
972 case BT_REMOVE_ALLOW_LIST: {
973 bluetooth_device_address_t address = { {0} };
974 int address_type = 0;
976 __bt_service_get_parameters(in_param1,
977 &address, sizeof(bluetooth_device_address_t));
978 __bt_service_get_parameters(in_param2,
979 &address_type, sizeof(int));
980 result = _bt_set_allow_list(&address, address_type, is_add);
983 case BT_UPDATE_LE_CONNECTION_MODE: {
985 bluetooth_device_address_t remote_address = { { 0 } };
986 bluetooth_le_connection_param_t parameters = { 0 };
987 bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED;
989 __bt_service_get_parameters(in_param1, &remote_address,
990 sizeof(bluetooth_device_address_t));
991 __bt_service_get_parameters(in_param2, &mode,
992 sizeof(bluetooth_le_connection_mode_t));
994 result = _bt_get_le_connection_parameter(mode, ¶meters);
995 if (result != BLUETOOTH_ERROR_NONE)
998 sender = (char *)g_dbus_method_invocation_get_sender(context);
1000 result = _bt_le_connection_update(sender,
1001 remote_address.addr,
1002 parameters.interval_min,
1003 parameters.interval_max,
1005 parameters.timeout);
1008 case BT_SET_MANUFACTURER_DATA: {
1009 bluetooth_manufacturer_data_t m_data = { 0 };
1010 __bt_service_get_parameters(in_param1,
1011 &m_data, sizeof(bluetooth_manufacturer_data_t));
1012 result = _bt_set_manufacturer_data(&m_data);
1016 case BT_IS_DEVICE_CONNECTED: {
1017 bluetooth_device_address_t address = { {0} };
1018 gboolean connected = FALSE;
1021 __bt_service_get_parameters(in_param1,
1022 &address, sizeof(bluetooth_device_address_t));
1023 __bt_service_get_parameters(in_param2,
1024 &service_type, sizeof(int));
1026 #if defined(TIZEN_FEATURE_BT_PAN_NAP)
1027 if ((service_type == BLUETOOTH_NAP_SERVICE) || (service_type == BLUETOOTH_NAP_SERVER_SERVICE))
1028 connected = _bt_is_nap_panu_device_connected(&address, service_type);
1030 connected = _bt_is_device_connected(&address, service_type);
1032 connected = _bt_is_device_connected(&address, service_type);
1034 BT_INFO("is_connected: %d", connected);
1035 g_array_append_vals(*out_param1, &connected, sizeof(gboolean));
1038 case BT_GET_CONNECTED_LINK_TYPE: {
1039 bluetooth_device_address_t address = { {0} };
1041 __bt_service_get_parameters(in_param1,
1042 &address, sizeof(bluetooth_device_address_t));
1044 result = _bt_get_connected_link(&address);
1045 if (result == BLUETOOTH_ERROR_NONE) {
1046 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
1048 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
1052 _bt_convert_addr_type_to_string(addr, address.addr);
1053 sender = (char*)g_dbus_method_invocation_get_sender(context);
1054 _bt_save_invocation_context(context, result, sender,
1055 function_name, addr);
1059 case BT_IS_SCAN_FILTER_SUPPORTED:{
1060 int is_supported = 0;
1062 if (_bt_is_scan_filter_supported() == TRUE)
1065 g_array_append_vals(*out_param1,
1066 &is_supported, sizeof(int));
1070 case BT_ENABLE_RSSI: {
1071 bluetooth_device_address_t bd_addr;
1073 bt_rssi_threshold_t rssi_threshold;
1075 int in_range_threshold;
1078 BT_DBG("Enable RSSI");
1080 __bt_service_get_parameters(in_param1,
1081 &bd_addr, sizeof(bluetooth_device_address_t));
1082 __bt_service_get_parameters(in_param2,
1083 &link_type, sizeof(int));
1084 __bt_service_get_parameters(in_param3,
1085 &rssi_threshold, sizeof(bt_rssi_threshold_t));
1087 low_threshold = rssi_threshold.low_threshold;
1088 in_range_threshold = rssi_threshold.in_range_threshold;
1089 high_threshold = rssi_threshold.high_threshold;
1091 result = _bt_enable_rssi(&bd_addr, link_type, low_threshold,
1092 in_range_threshold, high_threshold);
1097 bluetooth_device_address_t bd_addr;
1099 BT_DBG("Get RSSI Strength");
1101 __bt_service_get_parameters(in_param1,
1102 &bd_addr, sizeof(bluetooth_device_address_t));
1103 __bt_service_get_parameters(in_param2,
1104 &link_type, sizeof(int));
1106 result = _bt_get_rssi_strength(&bd_addr, link_type);
1109 case BT_SET_PROFILE_TRUSTED: {
1110 bluetooth_device_address_t bd_addr = { {0} };
1114 __bt_service_get_parameters(in_param1, &bd_addr,
1115 sizeof(bluetooth_device_address_t));
1116 __bt_service_get_parameters(in_param2, &profile, sizeof(int));
1117 __bt_service_get_parameters(in_param3, &trust, sizeof(int));
1119 result = _bt_set_trust_profile(&bd_addr, profile, trust);
1122 case BT_GET_PROFILE_TRUSTED: {
1123 bluetooth_device_address_t bd_addr = { {0} };
1125 guint trusted_profile = 0;
1127 __bt_service_get_parameters(in_param1, &bd_addr,
1128 sizeof(bluetooth_device_address_t));
1129 __bt_service_get_parameters(in_param2, &profile, sizeof(int));
1131 result = _bt_get_trust_profile(&bd_addr, profile, &trusted_profile);
1132 BT_DBG("TRUST %d", trusted_profile);
1133 if (result == BLUETOOTH_ERROR_NONE) {
1134 g_array_append_vals(*out_param1, &trusted_profile,
1140 case BT_HID_CONNECT: {
1141 bluetooth_device_address_t address = { {0} };
1143 __bt_service_get_parameters(in_param1,
1144 &address, sizeof(bluetooth_device_address_t));
1146 result = _bt_hid_connect(&address);
1147 if (result != BLUETOOTH_ERROR_NONE) {
1148 g_array_append_vals(*out_param1, &address,
1149 sizeof(bluetooth_device_address_t));
1151 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1152 _bt_convert_addr_type_to_string(addr, address.addr);
1153 sender = (char*)g_dbus_method_invocation_get_sender(context);
1154 _bt_save_invocation_context(context, result, sender,
1155 function_name, (gpointer)addr);
1159 case BT_HID_DISCONNECT: {
1160 bluetooth_device_address_t address = { {0} };
1162 __bt_service_get_parameters(in_param1,
1163 &address, sizeof(bluetooth_device_address_t));
1165 result = _bt_hid_disconnect(&address);
1166 if (result != BLUETOOTH_ERROR_NONE) {
1167 g_array_append_vals(*out_param1, &address,
1168 sizeof(bluetooth_device_address_t));
1170 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1171 _bt_convert_addr_type_to_string(addr, address.addr);
1172 sender = (char*)g_dbus_method_invocation_get_sender(context);
1173 _bt_save_invocation_context(context, result, sender,
1174 function_name, (gpointer)addr);
1178 case BT_DPM_SET_ALLOW_BT_MODE: {
1179 dpm_bt_allow_t value = DPM_BT_ERROR;
1181 __bt_service_get_parameters(in_param1, &value,
1184 result = _bt_dpm_set_allow_bluetooth_mode(value);
1187 case BT_DPM_GET_ALLOW_BT_MODE: {
1188 int value = DPM_BT_ERROR;
1190 result = _bt_dpm_get_allow_bluetooth_mode(&value);
1191 g_array_append_vals(*out_param1, &value, sizeof(int));
1194 case BT_DPM_SET_DEVICE_RESTRITION: {
1195 dpm_status_t value = DPM_STATUS_ERROR;
1197 __bt_service_get_parameters(in_param1, &value,
1200 result = _bt_dpm_activate_bluetooth_device_restriction(value);
1203 case BT_DPM_GET_DEVICE_RESTRITION: {
1204 int value = DPM_STATUS_ERROR;
1206 result = _bt_dpm_is_bluetooth_device_restriction_active(&value);
1207 g_array_append_vals(*out_param1, &value, sizeof(int));
1210 case BT_DPM_SET_UUID_RESTRITION: {
1211 dpm_status_t value = DPM_STATUS_ERROR;
1213 __bt_service_get_parameters(in_param1, &value,
1216 result = _bt_dpm_activate_bluetoooth_uuid_restriction(value);
1219 case BT_DPM_GET_UUID_RESTRITION: {
1220 int value = DPM_STATUS_ERROR;
1222 result = _bt_dpm_is_bluetooth_uuid_restriction_active(&value);
1223 g_array_append_vals(*out_param1, &value, sizeof(int));
1226 case BT_DPM_ADD_DEVICES_BLOCKLIST: {
1227 bluetooth_device_address_t address = { {0} };
1229 __bt_service_get_parameters(in_param1, &address,
1230 sizeof(bluetooth_device_address_t));
1232 result = _bt_dpm_add_bluetooth_devices_to_blocklist(&address);
1235 case BT_DPM_ADD_DEVICES_ALLOWLIST: {
1236 bluetooth_device_address_t address = { {0} };
1238 __bt_service_get_parameters(in_param1, &address,
1239 sizeof(bluetooth_device_address_t));
1241 result = _bt_dpm_add_bluetooth_devices_to_allowlist(&address);
1244 case BT_DPM_ADD_UUIDS_BLOCKLIST: {
1245 const char *uuid = NULL;
1247 uuid = g_variant_get_data(in_param1);
1249 result = _bt_dpm_add_bluetooth_uuids_to_blocklist(uuid);
1252 case BT_DPM_ADD_UUIDS_ALLOWLIST: {
1253 const char *uuid = NULL;
1255 uuid = g_variant_get_data(in_param1);
1257 result = _bt_dpm_add_bluetooth_uuids_to_allowlist(uuid);
1260 case BT_DPM_CLEAR_DEVICES_BLOCKLIST: {
1261 result = _bt_dpm_clear_bluetooth_devices_from_blocklist();
1264 case BT_DPM_CLEAR_DEVICES_ALLOWLIST: {
1265 result = _bt_dpm_clear_bluetooth_devices_from_allowlist();
1268 case BT_DPM_CLEAR_UUIDS_BLOCKLIST: {
1269 result = _bt_dpm_clear_bluetooth_uuids_from_blocklist();
1272 case BT_DPM_CLEAR_UUIDS_ALLOWLIST: {
1273 result = _bt_dpm_clear_bluetooth_uuids_from_allowlist();
1276 case BT_DPM_REMOVE_DEVICE_BLOCKLIST: {
1277 bluetooth_device_address_t address = { {0} };
1279 __bt_service_get_parameters(in_param1, &address,
1280 sizeof(bluetooth_device_address_t));
1282 result = _bt_dpm_remove_bluetooth_devices_from_blocklist(&address);
1285 case BT_DPM_REMOVE_DEVICE_ALLOWLIST: {
1286 bluetooth_device_address_t address = { {0} };
1288 __bt_service_get_parameters(in_param1, &address,
1289 sizeof(bluetooth_device_address_t));
1291 result = _bt_dpm_remove_bluetooth_devices_from_allowlist(&address);
1294 case BT_DPM_REMOVE_UUID_BLOCKLIST: {
1295 const char *uuid = NULL;
1297 uuid = g_variant_get_data(in_param1);
1299 result = _bt_dpm_remove_bluetooth_uuids_from_blocklist(uuid);
1302 case BT_DPM_REMOVE_UUID_ALLOWLIST: {
1303 const char *uuid = NULL;
1305 uuid = g_variant_get_data(in_param1);
1307 result = _bt_dpm_remove_bluetooth_uuids_from_allowlist(uuid);
1311 case BT_DPM_GET_DEVICES_BLOCKLIST: {
1312 result = _bt_dpm_get_bluetooth_devices_from_blocklist(out_param1);
1315 case BT_DPM_GET_DEVICES_ALLOWLIST: {
1316 result = _bt_dpm_get_bluetooth_devices_from_allowlist(out_param1);
1320 case BT_DPM_GET_UUIDS_BLOCKLIST: {
1321 result = _bt_dpm_get_bluetooth_uuids_from_blocklist(out_param1);
1324 case BT_DPM_GET_UUIDS_ALLOWLIST: {
1325 result = _bt_dpm_get_bluetooth_uuids_from_allowlist(out_param1);
1328 case BT_DPM_SET_ALLOW_OUTGOING_CALL: {
1329 dpm_status_t value = DPM_STATUS_ERROR;
1331 __bt_service_get_parameters(in_param1, &value,
1334 result = _bt_dpm_set_allow_bluetooth_outgoing_call(value);
1338 case BT_DPM_GET_ALLOW_OUTGOING_CALL: {
1339 int value = DPM_STATUS_ERROR;
1341 result = _bt_dpm_get_allow_bluetooth_outgoing_call(&value);
1342 g_array_append_vals(*out_param1, &value, sizeof(int));
1345 case BT_DPM_SET_PAIRING_STATE: {
1346 dpm_status_t value = DPM_STATUS_ERROR;
1348 __bt_service_get_parameters(in_param1, &value,
1351 result = _bt_dpm_set_bluetooth_pairing_state(value);
1355 case BT_DPM_GET_PAIRING_STATE: {
1356 int value = DPM_STATUS_ERROR;
1358 result = _bt_dpm_get_bluetooth_pairing_state(&value);
1359 g_array_append_vals(*out_param1, &value, sizeof(int));
1362 case BT_DPM_SET_PROFILE_STATE: {
1363 int value = DPM_STATUS_ERROR;
1364 int profile = DPM_PROFILE_NONE;
1366 __bt_service_get_parameters(in_param1, &profile,
1368 __bt_service_get_parameters(in_param2, &value,
1371 result = _bt_dpm_set_bluetooth_profile_state(profile, value);
1375 case BT_DPM_GET_PROFILE_STATE: {
1376 int value = DPM_STATUS_ERROR;
1377 int profile = DPM_PROFILE_NONE;
1379 __bt_service_get_parameters(in_param1, &profile,
1382 result = _bt_dpm_get_bluetooth_profile_state(profile, &value);
1383 g_array_append_vals(*out_param1, &value, sizeof(int));
1386 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE: {
1387 int value = DPM_BT_ERROR;
1389 __bt_service_get_parameters(in_param1, &value,
1392 result = _bt_dpm_set_bluetooth_desktop_connectivity_state(value);
1396 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE: {
1397 int value = DPM_STATUS_ERROR;
1399 result = _bt_dpm_get_bluetooth_desktop_connectivity_state(&value);
1400 g_array_append_vals(*out_param1, &value, sizeof(int));
1403 case BT_DPM_SET_DISCOVERABLE_STATE: {
1404 int value = DPM_STATUS_ERROR;
1406 __bt_service_get_parameters(in_param1, &value,
1409 result = _bt_dpm_set_bluetooth_discoverable_state(value);
1413 case BT_DPM_GET_DISCOVERABLE_STATE: {
1414 int value = DPM_STATUS_ERROR;
1416 result = _bt_dpm_get_bluetooth_discoverable_state(&value);
1417 g_array_append_vals(*out_param1, &value, sizeof(int));
1420 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE: {
1421 int value = DPM_STATUS_ERROR;
1423 __bt_service_get_parameters(in_param1, &value,
1426 result = _bt_dpm_set_bluetooth_limited_discoverable_state(value);
1430 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE: {
1431 int value = DPM_STATUS_ERROR;
1433 result = _bt_dpm_get_bluetooth_limited_discoverable_state(&value);
1434 g_array_append_vals(*out_param1, &value, sizeof(int));
1437 case BT_DPM_SET_DATA_TRANSFER_STATE: {
1438 int value = DPM_STATUS_ERROR;
1440 __bt_service_get_parameters(in_param1, &value,
1443 result = _bt_dpm_set_bluetooth_data_transfer_state(value);
1447 case BT_DPM_GET_DATA_TRANSFER_STATE: {
1448 int value = DPM_STATUS_ERROR;
1450 result = _bt_dpm_get_allow_bluetooth_data_transfer_state(&value);
1451 g_array_append_vals(*out_param1, &value, sizeof(int));
1454 case BT_RFCOMM_CLIENT_CONNECT: {
1455 bluetooth_device_address_t address = { {0} };
1459 __bt_service_get_parameters(in_param1,
1460 &address, sizeof(bluetooth_device_address_t));
1461 input_string = (char *)g_variant_get_data(in_param2);
1462 __bt_service_get_parameters(in_param3, &connect_type, sizeof(int));
1464 if (connect_type == BT_RFCOMM_UUID)
1465 result = _bt_rfcomm_connect_using_uuid(&address, input_string);
1467 result = _bt_rfcomm_connect_using_channel(&address, input_string);
1469 if (result != BLUETOOTH_ERROR_NONE) {
1470 bluetooth_rfcomm_connection_t conn_info;
1472 BT_ERR("BT_RFCOMM_CLIENT_CONNECT failed, send error");
1473 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
1474 if (connect_type == BT_RFCOMM_UUID)
1475 g_strlcpy(conn_info.uuid, input_string, BLUETOOTH_UUID_STRING_MAX);
1477 g_strlcpy(conn_info.uuid, "not_used", BLUETOOTH_UUID_STRING_MAX);
1479 conn_info.device_role = RFCOMM_ROLE_CLIENT;
1480 conn_info.socket_fd = -1;
1481 memcpy(&conn_info.device_addr, &address, sizeof(bluetooth_device_address_t));
1482 g_array_append_vals(*out_param1, &conn_info,
1483 sizeof(bluetooth_rfcomm_connection_t));
1485 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1486 _bt_convert_addr_type_to_string(addr, address.addr);
1487 sender = (char*)g_dbus_method_invocation_get_sender(context);
1488 _bt_save_invocation_context(context, result, sender, function_name, addr);
1492 case BT_RFCOMM_SOCKET_DISCONNECT: {
1494 * Bluetooth RFCOMM socket disconnection will be done from bt-api, call to bt-service
1495 * is only used for privilege check, so return BLUETOOTH_ERROR_NONE from here.
1497 result = BLUETOOTH_ERROR_NONE;
1500 case BT_RFCOMM_SOCKET_WRITE: {
1502 * This call to bt-service is only used for privilege check, so return
1503 * BLUETOOTH_ERROR_NONE from here.
1505 result = BLUETOOTH_ERROR_NONE;
1508 case BT_RFCOMM_CREATE_SOCKET: {
1510 * This call to bt-service is only used for privilege check, so return
1511 * BLUETOOTH_ERROR_NONE from here.
1513 result = BLUETOOTH_ERROR_NONE;
1516 case BT_RFCOMM_LISTEN_AND_ACCEPT: {
1520 sender = (char *)g_dbus_method_invocation_get_sender(context);
1521 uuid = (char *)g_variant_get_data(in_param1);
1523 result = _bt_rfcomm_socket_listen(sender, uuid, true);
1525 result = BLUETOOTH_ERROR_NONE;
1526 _bt_save_invocation_context(context,
1527 result, sender, function_name, NULL);
1529 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1533 case BT_RFCOMM_LISTEN: {
1537 sender = (char *)g_dbus_method_invocation_get_sender(context);
1538 uuid = (char *)g_variant_get_data(in_param1);
1540 result = _bt_rfcomm_socket_listen(sender, uuid, false);
1542 result = BLUETOOTH_ERROR_NONE;
1543 _bt_save_invocation_context(context,
1544 result, sender, function_name, NULL);
1546 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1550 case BT_RFCOMM_ACCEPT_CONNECTION: {
1553 address = (char *)g_variant_get_data(in_param1);
1554 result = _bt_socket_reply_conn_authorization(address, TRUE);
1557 case BT_RFCOMM_REJECT_CONNECTION: {
1560 address = (char *)g_variant_get_data(in_param1);
1561 result = _bt_socket_reply_conn_authorization(address, FALSE);
1564 case BT_RFCOMM_REMOVE_SOCKET: {
1566 * This call to bt-service is only used for privilege check, so return
1567 * BLUETOOTH_ERROR_NONE from here.
1569 result = BLUETOOTH_ERROR_NONE;
1572 case BT_RFCOMM_SEND_RX_DETAILS: {
1576 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
1577 __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t));
1578 __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int));
1579 _bt_bm_add_transaction_details(uid, pid, size, RX_DATA);
1582 case BT_RFCOMM_SEND_TX_DETAILS: {
1586 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
1587 __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t));
1588 __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int));
1589 _bt_bm_add_transaction_details(uid, pid, size, TX_DATA);
1592 case BT_RFCOMM_UPDATE_CONNECTION_INFO: {
1593 gboolean connected = FALSE;
1595 int role = RFCOMM_ROLE_SERVER;
1597 sender = (char *)g_dbus_method_invocation_get_sender(context);
1599 __bt_service_get_parameters(in_param1, &role, sizeof(int));
1600 __bt_service_get_parameters(in_param2, &connected, sizeof(gboolean));
1601 __bt_service_get_parameters(in_param3, &socket_fd, sizeof(int));
1603 if (connected == TRUE)
1604 result = _bt_rfcomm_conn_added(sender, role, socket_fd);
1606 result = _bt_rfcomm_conn_removed(sender, role, socket_fd);
1610 case BT_AUDIO_SELECT_ROLE: {
1611 bluetooth_audio_role_t role;
1613 __bt_service_get_parameters(in_param1,
1614 &role, sizeof(bluetooth_audio_role_t));
1616 result = _bt_audio_select_role(role);
1617 if (result == BLUETOOTH_ERROR_NONE) {
1618 sender = (char*)g_dbus_method_invocation_get_sender(context);
1619 _bt_save_invocation_context(context, result, sender,
1620 function_name, NULL);
1624 case BT_AUDIO_SET_ABSOLUTE_VOLUME: {
1625 unsigned int volume = 0;
1627 __bt_service_get_parameters(in_param1,
1628 &volume, sizeof(unsigned int));
1630 result = _bt_audio_set_absolute_volume(volume);
1633 case BT_AUDIO_GET_ABSOLUTE_VOLUME: {
1634 unsigned int volume = 0;
1636 result = _bt_audio_get_absolute_volume(&volume);
1637 g_array_append_vals(*out_param1, &volume, sizeof(unsigned int));
1640 case BT_AUDIO_IS_AVC_ACTIVATED: {
1643 result = _bt_audio_is_avc_activated(&activated);
1644 g_array_append_vals(*out_param1, &activated, sizeof(bool));
1647 case BT_AV_CONNECT: {
1648 bluetooth_device_address_t address = { {0} };
1649 __bt_service_get_parameters(in_param1,
1650 &address, sizeof(bluetooth_device_address_t));
1652 result = _bt_audio_is_profile_connection_in_progress(BT_AV_CONNECT, &address);
1654 if (result == BLUETOOTH_ERROR_NONE)
1655 result = _bt_audio_connect(BT_AUDIO_A2DP, &address);
1657 if (result != BLUETOOTH_ERROR_NONE) {
1658 BT_ERR("AV Connect Request has failed to execute");
1659 char addr[BT_ADDRESS_STRING_SIZE];
1660 _bt_convert_addr_type_to_string(addr, address.addr);
1661 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1663 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1664 _bt_convert_addr_type_to_string(addr, address.addr);
1665 sender = (char*)g_dbus_method_invocation_get_sender(context);
1666 _bt_save_invocation_context(context, result, sender,
1667 function_name, (gpointer)addr);
1671 case BT_AUDIO_CONNECT: {
1672 bluetooth_device_address_t address = { {0} };
1673 __bt_service_get_parameters(in_param1,
1674 &address, sizeof(bluetooth_device_address_t));
1676 result = _bt_audio_is_profile_connection_in_progress(BT_AUDIO_CONNECT, &address);
1678 if (result == BLUETOOTH_ERROR_NONE)
1679 result = _bt_audio_connect(BT_AUDIO_ALL, &address);
1681 if (result != BLUETOOTH_ERROR_NONE) {
1682 BT_ERR("Audio All Connect Request has failed to execute");
1683 char addr[BT_ADDRESS_STRING_SIZE];
1684 _bt_convert_addr_type_to_string(addr, address.addr);
1685 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1687 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1688 _bt_convert_addr_type_to_string(addr, address.addr);
1689 sender = (char*)g_dbus_method_invocation_get_sender(context);
1690 _bt_save_invocation_context(context, result, sender,
1691 function_name, (gpointer)addr);
1695 case BT_AUDIO_DISCONNECT: {
1696 bluetooth_device_address_t address = { {0} };
1697 __bt_service_get_parameters(in_param1,
1698 &address, sizeof(bluetooth_device_address_t));
1700 result = _bt_audio_disconnect(BT_AUDIO_ALL, &address);
1702 if (result != BLUETOOTH_ERROR_NONE) {
1703 char addr[BT_ADDRESS_STRING_SIZE];
1704 _bt_convert_addr_type_to_string(addr, address.addr);
1705 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1707 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1708 _bt_convert_addr_type_to_string(addr, address.addr);
1709 sender = (char*)g_dbus_method_invocation_get_sender(context);
1710 _bt_save_invocation_context(context, result, sender,
1711 function_name, (gpointer)addr);
1715 case BT_AV_DISCONNECT: {
1716 bluetooth_device_address_t address = { {0} };
1717 __bt_service_get_parameters(in_param1,
1718 &address, sizeof(bluetooth_device_address_t));
1720 result = _bt_audio_disconnect(BT_AUDIO_A2DP, &address);
1722 if (result != BLUETOOTH_ERROR_NONE) {
1723 char addr[BT_ADDRESS_STRING_SIZE];
1724 _bt_convert_addr_type_to_string(addr, address.addr);
1725 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1727 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1728 _bt_convert_addr_type_to_string(addr, address.addr);
1729 sender = (char*)g_dbus_method_invocation_get_sender(context);
1730 _bt_save_invocation_context(context, result, sender,
1731 function_name, (gpointer)addr);
1735 case BT_AG_CONNECT: {
1736 bluetooth_device_address_t address = { {0} };
1737 __bt_service_get_parameters(in_param1,
1738 &address, sizeof(bluetooth_device_address_t));
1740 result = _bt_audio_is_profile_connection_in_progress(BT_AG_CONNECT, &address);
1742 if (result == BLUETOOTH_ERROR_NONE)
1743 result = _bt_audio_connect(BT_AUDIO_HSP, &address);
1745 if (result != BLUETOOTH_ERROR_NONE) {
1746 BT_ERR("AG Connect Request has failed to execute");
1747 char addr[BT_ADDRESS_STRING_SIZE];
1748 _bt_convert_addr_type_to_string(addr, address.addr);
1749 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1751 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1752 _bt_convert_addr_type_to_string(addr, address.addr);
1753 sender = (char*)g_dbus_method_invocation_get_sender(context);
1754 _bt_save_invocation_context(context, result, sender,
1755 function_name, (gpointer)addr);
1759 case BT_AG_DISCONNECT: {
1760 bluetooth_device_address_t address = { {0} };
1762 __bt_service_get_parameters(in_param1,
1763 &address, sizeof(bluetooth_device_address_t));
1765 result = _bt_audio_disconnect(BT_AUDIO_HSP, &address);
1767 if (result != BLUETOOTH_ERROR_NONE) {
1768 char addr[BT_ADDRESS_STRING_SIZE];
1769 _bt_convert_addr_type_to_string(addr, address.addr);
1770 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1772 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1773 _bt_convert_addr_type_to_string(addr, address.addr);
1774 sender = (char*)g_dbus_method_invocation_get_sender(context);
1775 _bt_save_invocation_context(context, result, sender,
1776 function_name, (gpointer)addr);
1780 case BT_AV_SOURCE_CONNECT: {
1781 bluetooth_device_address_t address = { {0} };
1783 __bt_service_get_parameters(in_param1,
1784 &address, sizeof(bluetooth_device_address_t));
1786 result = _bt_audio_is_profile_connection_in_progress(BT_AV_SOURCE_CONNECT,
1789 if (result == BLUETOOTH_ERROR_NONE)
1790 result = _bt_audio_connect(BT_AUDIO_A2DP_SOURCE, &address);
1792 if (result != BLUETOOTH_ERROR_NONE) {
1793 BT_ERR("A2DP Source Connect Request has failed to execute");
1794 char addr[BT_ADDRESS_STRING_SIZE];
1795 _bt_convert_addr_type_to_string(addr, address.addr);
1796 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1798 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1799 _bt_convert_addr_type_to_string(addr, address.addr);
1800 sender = (char*)g_dbus_method_invocation_get_sender(context);
1801 _bt_save_invocation_context(context, result, sender,
1802 function_name, (gpointer)addr);
1806 case BT_AV_SOURCE_DISCONNECT: {
1807 bluetooth_device_address_t address = { {0} };
1809 __bt_service_get_parameters(in_param1,
1810 &address, sizeof(bluetooth_device_address_t));
1812 result = _bt_audio_disconnect(BT_AUDIO_A2DP_SOURCE, &address);
1813 if (result != BLUETOOTH_ERROR_NONE) {
1814 char addr[BT_ADDRESS_STRING_SIZE];
1815 _bt_convert_addr_type_to_string(addr, address.addr);
1816 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1818 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1819 _bt_convert_addr_type_to_string(addr, address.addr);
1820 sender = (char*)g_dbus_method_invocation_get_sender(context);
1821 _bt_save_invocation_context(context, result, sender,
1822 function_name, (gpointer)addr);
1826 case BT_HF_CONNECT: {
1827 bluetooth_device_address_t address = { {0} };
1829 __bt_service_get_parameters(in_param1,
1830 &address, sizeof(bluetooth_device_address_t));
1832 result = _bt_audio_is_profile_connection_in_progress(BT_HF_CONNECT,
1835 if (result == BLUETOOTH_ERROR_NONE)
1836 result = _bt_hf_connect(&address);
1838 if (result != BLUETOOTH_ERROR_NONE) {
1839 BT_ERR("HF Connect Request has failed to execute");
1840 char addr[BT_ADDRESS_STRING_SIZE];
1841 _bt_convert_addr_type_to_string(addr, address.addr);
1842 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1844 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1845 _bt_convert_addr_type_to_string(addr, address.addr);
1846 sender = (char*)g_dbus_method_invocation_get_sender(context);
1847 _bt_save_invocation_context(context, result, sender,
1848 function_name, (gpointer)addr);
1852 case BT_HF_DISCONNECT: {
1853 bluetooth_device_address_t address = { {0} };
1855 __bt_service_get_parameters(in_param1,
1856 &address, sizeof(bluetooth_device_address_t));
1858 result = _bt_hf_disconnect(&address);
1859 if (result != BLUETOOTH_ERROR_NONE) {
1860 char addr[BT_ADDRESS_STRING_SIZE];
1861 _bt_convert_addr_type_to_string(addr, address.addr);
1862 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1864 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1865 _bt_convert_addr_type_to_string(addr, address.addr);
1866 sender = (char*)g_dbus_method_invocation_get_sender(context);
1867 _bt_save_invocation_context(context, result, sender,
1868 function_name, (gpointer)addr);
1872 case BT_AVRCP_TARGET_CONNECT: {
1873 bluetooth_device_address_t address = { {0} };
1875 __bt_service_get_parameters(in_param1,
1876 &address, sizeof(bluetooth_device_address_t));
1878 result = _bt_audio_is_profile_connection_in_progress(BT_AVRCP_TARGET_CONNECT,
1881 if (result == BLUETOOTH_ERROR_NONE)
1882 result = _bt_audio_connect(BT_AVRCP_TARGET, &address);
1884 if (result != BLUETOOTH_ERROR_NONE) {
1885 BT_ERR("AVRCP Target Connect Request has failed to execute");
1886 char addr[BT_ADDRESS_STRING_SIZE];
1887 _bt_convert_addr_type_to_string(addr, address.addr);
1888 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1890 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1891 _bt_convert_addr_type_to_string(addr, address.addr);
1892 sender = (char*)g_dbus_method_invocation_get_sender(context);
1893 _bt_save_invocation_context(context, result, sender,
1894 function_name, (gpointer)addr);
1898 case BT_AVRCP_TARGET_DISCONNECT: {
1899 bluetooth_device_address_t address = { {0} };
1901 __bt_service_get_parameters(in_param1,
1902 &address, sizeof(bluetooth_device_address_t));
1904 result = _bt_audio_disconnect(BT_AVRCP_TARGET, &address);
1905 if (result != BLUETOOTH_ERROR_NONE) {
1906 char addr[BT_ADDRESS_STRING_SIZE];
1907 _bt_convert_addr_type_to_string(addr, address.addr);
1908 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1910 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1911 _bt_convert_addr_type_to_string(addr, address.addr);
1912 sender = (char*)g_dbus_method_invocation_get_sender(context);
1913 _bt_save_invocation_context(context, result, sender,
1914 function_name, (gpointer)addr);
1918 case BT_AVRCP_CONTROL_CONNECT: {
1919 bluetooth_device_address_t address = { {0} };
1921 __bt_service_get_parameters(in_param1,
1922 &address, sizeof(bluetooth_device_address_t));
1924 result = _bt_audio_is_profile_connection_in_progress(BT_AVRCP_CONTROL_CONNECT,
1927 if (result == BLUETOOTH_ERROR_NONE)
1928 result = _bt_audio_connect(BT_AVRCP, &address);
1930 if (result != BLUETOOTH_ERROR_NONE) {
1931 BT_ERR("AVRCP Control Connect Request has failed to execute");
1932 char addr[BT_ADDRESS_STRING_SIZE];
1933 _bt_convert_addr_type_to_string(addr, address.addr);
1934 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1936 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1937 _bt_convert_addr_type_to_string(addr, address.addr);
1938 sender = (char*)g_dbus_method_invocation_get_sender(context);
1939 _bt_save_invocation_context(context, result, sender,
1940 function_name, (gpointer)addr);
1944 case BT_AVRCP_CONTROL_DISCONNECT: {
1945 bluetooth_device_address_t address = { {0} };
1947 __bt_service_get_parameters(in_param1,
1948 &address, sizeof(bluetooth_device_address_t));
1950 result = _bt_audio_disconnect(BT_AVRCP, &address);
1951 if (result != BLUETOOTH_ERROR_NONE) {
1952 char addr[BT_ADDRESS_STRING_SIZE];
1953 _bt_convert_addr_type_to_string(addr, address.addr);
1954 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1956 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1957 _bt_convert_addr_type_to_string(addr, address.addr);
1958 sender = (char*)g_dbus_method_invocation_get_sender(context);
1959 _bt_save_invocation_context(context, result, sender,
1960 function_name, (gpointer)addr);
1964 case BT_AVRCP_HANDLE_CONTROL: {
1966 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1967 result = _bt_avrcp_control_cmd(key_code);
1970 case BT_AVRCP_HANDLE_CONTROL_TO_DEST: {
1972 bluetooth_device_address_t address = { { 0 } };
1974 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1975 __bt_service_get_parameters(in_param2,
1976 &address, sizeof(bluetooth_device_address_t));
1978 result = _bt_avrcp_control_cmd_to_dest(key_code, &address);
1981 case BT_AVRCP_CONTROL_SET_PROPERTY: {
1985 __bt_service_get_parameters(in_param1,
1986 &type, sizeof(int));
1987 __bt_service_get_parameters(in_param2,
1988 &value, sizeof(unsigned int));
1990 result = _bt_avrcp_control_set_property(type, value);
1993 case BT_AVRCP_TRANSPORT_SET_PROPERTY: {
1998 __bt_service_get_parameters(in_param1,
1999 &type, sizeof(int));
2000 __bt_service_get_parameters(in_param2,
2001 &value, sizeof(unsigned int));
2003 result = _bt_avrcp_transport_set_property(type, value);
2007 case BT_AVRCP_CONTROL_GET_PROPERTY: {
2010 __bt_service_get_parameters(in_param1, &type, sizeof(int));
2012 result = _bt_avrcp_control_get_property(type);
2013 /* Save invocation */
2014 if (result == BLUETOOTH_ERROR_NONE) {
2015 sender = (char*)g_dbus_method_invocation_get_sender(context);
2016 _bt_save_invocation_context(context, result, sender,
2017 function_name, g_memdup2(&type, sizeof(int)));
2021 case BT_AVRCP_GET_TRACK_INFO: {
2022 result = _bt_avrcp_control_get_track_info();
2023 /* Save invocation */
2024 if (result == BLUETOOTH_ERROR_NONE) {
2025 sender = (char*)g_dbus_method_invocation_get_sender(context);
2026 _bt_save_invocation_context(context, result, sender,
2027 function_name, NULL);
2031 case BT_HDP_REGISTER_SINK_APP: {
2032 unsigned short data_type;
2033 bt_hdp_role_type_t role;
2034 bt_hdp_qos_type_t channel_type;
2035 int *app_id = g_new0(int, 1);
2037 __bt_service_get_parameters(in_param1,
2038 &data_type, sizeof(short));
2039 __bt_service_get_parameters(in_param2,
2040 &role, sizeof(bt_hdp_role_type_t));
2041 __bt_service_get_parameters(in_param3,
2042 &channel_type, sizeof(bt_hdp_qos_type_t));
2043 sender = (char*)g_dbus_method_invocation_get_sender(context);
2045 result = _bt_hdp_app_register(role,
2046 channel_type, data_type, sender, app_id);
2047 if (result != BLUETOOTH_ERROR_NONE) {
2048 g_array_append_vals(*out_param1, &app_id, sizeof(app_id));
2051 _bt_save_invocation_context(context, result, sender,
2052 function_name, (gpointer)app_id);
2056 case BT_HDP_UNREGISTER_SINK_APP: {
2058 int *app_id = g_new0(int, 1);
2060 app_handle = (char *)g_variant_get_data(in_param1);
2061 sscanf(app_handle, "health_app_%d", app_id);
2062 result = _bt_hdp_app_unregister(*app_id);
2063 if (result != BLUETOOTH_ERROR_NONE) {
2066 sender = (char*)g_dbus_method_invocation_get_sender(context);
2067 _bt_save_invocation_context(context, result, sender,
2068 function_name, (gpointer)app_id);
2072 case BT_HDP_CONNECT: {
2076 bt_hdp_connected_t *conn_info = NULL;
2078 conn_info = g_malloc0(sizeof(bt_hdp_connected_t));
2080 app_handle = (char *)g_variant_get_data(in_param1);
2081 conn_info->app_handle = app_handle;
2082 sscanf(app_handle, "health_app_%d", &app_id);
2084 __bt_service_get_parameters(in_param2,
2085 &(conn_info->type), sizeof(bt_hdp_qos_type_t));
2086 __bt_service_get_parameters(in_param3,
2087 &(conn_info->device_address),
2088 sizeof(bluetooth_device_address_t));
2090 result = _bt_hdp_connect(app_id, &(conn_info->device_address),
2091 conn_info->type, (int *)(&(conn_info->channel_id)));
2092 if (result != BLUETOOTH_ERROR_NONE) {
2093 g_array_append_vals(*out_param1, conn_info,
2094 sizeof(bt_hdp_connected_t));
2097 sender = (char*)g_dbus_method_invocation_get_sender(context);
2098 _bt_save_invocation_context(context, result, sender,
2099 function_name, (gpointer)conn_info);
2103 case BT_HDP_DISCONNECT: {
2104 bt_hdp_disconnected_t *hdp_disconn_info = NULL;
2106 hdp_disconn_info = g_malloc0(sizeof(bt_hdp_disconnected_t));
2108 __bt_service_get_parameters(in_param1,
2109 &(hdp_disconn_info->channel_id), sizeof(int));
2110 __bt_service_get_parameters(in_param2,
2111 &(hdp_disconn_info->device_address),
2112 sizeof(bluetooth_device_address_t));
2114 result = _bt_hdp_disconnect(hdp_disconn_info->channel_id);
2115 if (result != BLUETOOTH_ERROR_NONE) {
2116 g_array_append_vals(*out_param1, hdp_disconn_info,
2117 sizeof(bt_hdp_disconnected_t));
2118 g_free(hdp_disconn_info);
2120 sender = (char*)g_dbus_method_invocation_get_sender(context);
2121 _bt_save_invocation_context(context, result, sender,
2122 function_name, (gpointer)hdp_disconn_info);
2126 case BT_HDP_GET_FD: {
2127 int *channel_id = g_new0(int, 1);
2129 __bt_service_get_parameters(in_param1, channel_id, sizeof(int));
2131 result = _bt_hdp_get_fd(*channel_id);
2132 if (result != BLUETOOTH_ERROR_NONE) {
2135 sender = (char*)g_dbus_method_invocation_get_sender(context);
2136 _bt_save_invocation_context(context, result, sender,
2137 function_name, (gpointer)channel_id);
2141 case BT_HDP_SEND_DATA: {
2143 * This call to bt-service is only used for privilege check, so return
2144 * BLUETOOTH_ERROR_NONE from here.
2146 result = BLUETOOTH_ERROR_NONE;
2149 case BT_OOB_READ_LOCAL_DATA: { //208
2150 bt_oob_data_t local_oob_data;
2152 memset(&local_oob_data, 0x00, sizeof(bt_oob_data_t));
2153 result = _bt_oob_read_local_data(&local_oob_data);
2155 g_array_append_vals(*out_param1, &local_oob_data,
2156 sizeof(bt_oob_data_t));
2160 case BT_OOB_ADD_REMOTE_DATA: { //209
2161 bluetooth_device_address_t address = { {0} };
2162 unsigned short address_type;
2163 bt_oob_data_t remote_oob_data;
2165 __bt_service_get_parameters(in_param1,
2166 &address, sizeof(bluetooth_device_address_t));
2167 __bt_service_get_parameters(in_param2,
2168 &address_type, sizeof(unsigned short));
2169 __bt_service_get_parameters(in_param3,
2170 &remote_oob_data, sizeof(bt_oob_data_t));
2172 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2176 case BT_OOB_REMOVE_REMOTE_DATA: { //210
2177 bluetooth_device_address_t address = { {0} };
2179 __bt_service_get_parameters(in_param1,
2180 &address, sizeof(bluetooth_device_address_t));
2182 result = _bt_oob_remove_remote_data(&address);
2186 case BT_LE_OOB_READ_LOCAL_DATA: {
2187 bt_oob_data_t local_oob_data;
2188 bt_oob_data_t *local_oob_cache_data;
2190 local_oob_cache_data = _bt_le_oob_get_local_cache_data();
2191 if (local_oob_cache_data && local_oob_cache_data->eir_len) {
2192 g_array_append_vals(*out_param1, local_oob_cache_data,
2193 sizeof(bt_oob_data_t));
2194 return BLUETOOTH_ERROR_NONE;
2197 /* We should modify this logic in later */
2198 if (_bt_is_le_static_random_address_enabled() == false) {
2199 /* Seperate BT & LE address */
2200 _bt_set_le_static_random_address(TRUE);
2203 result = _bt_le_oob_read_local_data(&local_oob_data);
2204 _bt_le_oob_set_local_cache_data(&local_oob_data);
2206 g_array_append_vals(*out_param1, &local_oob_data,
2207 sizeof(bt_oob_data_t));
2211 case BT_LE_OOB_ADD_REMOTE_DATA: {
2212 bluetooth_device_address_t address = { {0} };
2213 unsigned short address_type;
2214 bt_oob_data_t remote_oob_data;
2216 __bt_service_get_parameters(in_param1,
2217 &address, sizeof(bluetooth_device_address_t));
2218 __bt_service_get_parameters(in_param2,
2219 &address_type, sizeof(unsigned short));
2220 __bt_service_get_parameters(in_param3,
2221 &remote_oob_data, sizeof(bt_oob_data_t));
2223 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2227 case BT_AVRCP_SET_TRACK_INFO: {
2228 media_metadata_t data;
2229 media_metadata_attributes_t meta_data;
2231 memset(&data, 0x00, sizeof(media_metadata_t));
2232 memset(&meta_data, 0x00, sizeof(media_metadata_attributes_t));
2234 __bt_service_get_parameters(in_param1,
2235 &data, sizeof(media_metadata_t));
2237 meta_data.title = g_strdup(data.title);
2238 meta_data.artist = g_strdup(data.artist);
2239 meta_data.album = g_strdup(data.album);
2240 meta_data.genre = g_strdup(data.genre);
2241 meta_data.total_tracks = data.total_tracks;
2242 meta_data.number = data.number;
2243 meta_data.duration = (int64_t) data.duration;
2245 result = _bt_avrcp_set_track_info(&meta_data);
2247 g_free((gpointer)meta_data.title);
2248 g_free((gpointer)meta_data.artist);
2249 g_free((gpointer)meta_data.album);
2250 g_free((gpointer)meta_data.genre);
2254 case BT_AVRCP_SET_PROPERTY: {
2258 sender = (char *)g_dbus_method_invocation_get_sender(context);
2260 __bt_service_get_parameters(in_param1,
2261 &type, sizeof(int));
2262 __bt_service_get_parameters(in_param2,
2263 &value, sizeof(unsigned int));
2265 if (value == STATUS_PLAYING) {
2266 if (current_sender_playing)
2267 g_free(current_sender_playing);
2268 current_sender_playing = g_strdup(sender);
2270 if (g_strcmp0(sender, current_sender_playing) == 0 ||
2271 current_sender_playing == NULL) {
2272 BT_INFO("Current Player Status %d type %d Sender %s", value, type, sender);
2274 BT_INFO("Current Player and this sender (%s) are different", sender);
2275 result = BLUETOOTH_ERROR_NONE;
2278 result = _bt_avrcp_set_property(type, value);
2282 case BT_AVRCP_SET_PROPERTIES: {
2283 media_player_settings_t properties;
2285 memset(&properties, 0x00, sizeof(media_player_settings_t));
2286 __bt_service_get_parameters(in_param1,
2287 &properties, sizeof(media_player_settings_t));
2289 result = _bt_avrcp_set_properties(&properties);
2293 case BT_SET_ADVERTISING_DATA: {
2296 bluetooth_advertising_data_t adv = { {0} };
2298 bluetooth_le_slot_and_adv_type_t rs_at;
2299 rs_at.is_legacy = TRUE;
2300 rs_at.use_reserved_slot = FALSE;
2302 app = (char *)g_dbus_method_invocation_get_sender(context);
2303 adv_handle = g_malloc0(sizeof(int));
2305 __bt_service_get_parameters(in_param1,
2306 adv_handle, sizeof(int));
2307 __bt_service_get_parameters(in_param3,
2308 &length, sizeof(int));
2309 __bt_service_get_parameters(in_param2,
2311 __bt_service_get_parameters(in_param4,
2312 &rs_at, sizeof(bluetooth_le_slot_and_adv_type_t));
2313 result = _bt_set_advertising_data(app, *adv_handle,
2314 &adv, length, &rs_at);
2315 if (result != BLUETOOTH_ERROR_NONE) {
2316 BT_ERR("Set Advertising data failed!!");
2319 _bt_save_invocation_context(context, result, app,
2320 function_name, (gpointer)adv_handle);
2324 case BT_SET_SCAN_RESPONSE_DATA: {
2327 bluetooth_scan_resp_data_t rsp = { {0} };
2329 gboolean use_reserved_slot = FALSE;
2331 app = (char *)g_dbus_method_invocation_get_sender(context);
2332 adv_handle = g_malloc0(sizeof(int));
2334 __bt_service_get_parameters(in_param1,
2335 adv_handle, sizeof(int));
2336 __bt_service_get_parameters(in_param3,
2337 &length, sizeof(int));
2338 __bt_service_get_parameters(in_param2,
2340 __bt_service_get_parameters(in_param4,
2341 &use_reserved_slot, sizeof(gboolean));
2343 result = _bt_set_scan_response_data(app, *adv_handle,
2344 &rsp, length, use_reserved_slot);
2346 if (result != BLUETOOTH_ERROR_NONE) {
2347 BT_ERR("Set Scan Response Data failed!!");
2350 _bt_save_invocation_context(context, result, app,
2351 function_name, (gpointer)adv_handle);
2355 case BT_SET_ADVERTISING: {
2358 gboolean enable = FALSE;
2359 gboolean use_reserved_slot = FALSE;
2361 adv_handle = g_malloc0(sizeof(int));
2362 __bt_service_get_parameters(in_param1,
2363 adv_handle, sizeof(int));
2364 __bt_service_get_parameters(in_param2,
2365 &enable, sizeof(gboolean));
2366 __bt_service_get_parameters(in_param3,
2367 &use_reserved_slot, sizeof(gboolean));
2369 app = (char *)g_dbus_method_invocation_get_sender(context);
2371 result = _bt_set_advertising(app, *adv_handle,
2372 enable, use_reserved_slot);
2373 if (result != BLUETOOTH_ERROR_NONE) {
2374 BT_ERR("Start Advertising failed!!");
2377 _bt_save_invocation_context(context, result, app,
2378 function_name, (gpointer)adv_handle);
2382 case BT_SET_CUSTOM_ADVERTISING: {
2385 gboolean enable = FALSE;
2386 bluetooth_advertising_params_t adv_params;
2387 gboolean use_reserved_slot = FALSE;
2389 app = (char *)g_dbus_method_invocation_get_sender(context);
2390 adv_handle = g_malloc0(sizeof(int));
2392 __bt_service_get_parameters(in_param1, adv_handle,
2394 __bt_service_get_parameters(in_param2, &enable,
2396 __bt_service_get_parameters(in_param3, &adv_params,
2397 sizeof(bluetooth_advertising_params_t));
2398 __bt_service_get_parameters(in_param4, &use_reserved_slot,
2401 BT_DBG("bluetooth_advertising_params_t [%d %d %d %d %d]",
2402 adv_params.interval_min, adv_params.interval_max,
2403 adv_params.filter_policy, adv_params.type, adv_params.tx_power_level);
2404 result = _bt_set_custom_advertising(app, *adv_handle,
2405 enable, &adv_params, use_reserved_slot);
2406 if (result != BLUETOOTH_ERROR_NONE) {
2407 BT_ERR("Start Custom Advertising failed!!");
2410 _bt_save_invocation_context(context, result, app,
2411 function_name, (gpointer)adv_handle);
2415 case BT_GET_SCAN_RESPONSE_DATA: {
2416 bluetooth_scan_resp_data_t rsp = { {0} };
2420 app = (char *)g_dbus_method_invocation_get_sender(context);
2422 __bt_service_get_parameters(in_param1, &adv_handle,
2425 result = _bt_get_scan_response_data(app, adv_handle, &rsp, &length);
2426 if (result == BLUETOOTH_ERROR_NONE)
2427 g_array_append_vals(*out_param1, rsp.data, length);
2431 case BT_GET_ADVERTISING_DATA: {
2432 bluetooth_advertising_data_t adv = { {0} };
2436 app = (char *)g_dbus_method_invocation_get_sender(context);
2438 __bt_service_get_parameters(in_param1, &adv_handle,
2441 result = _bt_get_advertising_data(app, adv_handle, &adv, &length);
2442 if (result == BLUETOOTH_ERROR_NONE)
2443 g_array_append_vals(*out_param1, adv.data, length);
2447 case BT_GATT_REGISTER_APPLICATION: {
2448 BT_DBG("Register GATT application:Unhandled!!");
2451 case BT_GATT_SERVER_REGISTER: {
2452 BT_DBG("GATT Server instance initialization");
2455 app = (char *)g_dbus_method_invocation_get_sender(context);
2456 BT_DBG("GATT Server Unique Name [%s]", app);
2458 /* No ADV handle: Set 0 */
2459 result = _bt_register_server_instance(app, 0);
2461 if (result != BLUETOOTH_ERROR_NONE) {
2462 BT_ERR("GATT Server registration failed. result %d", result);
2464 _bt_save_invocation_context(context, result, app,
2465 function_name, NULL);
2469 case BT_GATT_SERVER_DEREGISTER: {
2471 app = (char*)g_dbus_method_invocation_get_sender(context);
2473 result = _bt_unregister_server_instance(app, 0/* Adv Handle*/);
2476 case BT_GATT_SERVER_ADD_SERVICE: {
2477 BT_DBG("GATT Server Add Service");
2483 int *tmp_inst_id = NULL;
2485 app = (char *)g_dbus_method_invocation_get_sender(context);
2487 __bt_service_get_parameters(in_param1, &service_type,
2489 __bt_service_get_parameters(in_param2, &num_handles,
2491 svc_uuid = (char *)g_variant_get_data(in_param3);
2492 __bt_service_get_parameters(in_param4, &instance_id,
2495 result = _bt_gatt_server_add_service(app, service_type, num_handles, svc_uuid, instance_id);
2496 if (result != BLUETOOTH_ERROR_NONE) {
2497 BT_ERR("GATT Server Add Service failed!!");
2499 tmp_inst_id = g_malloc0(sizeof(int));
2500 *tmp_inst_id = instance_id;
2501 _bt_save_invocation_context(context, result, app,
2502 function_name, (gpointer)tmp_inst_id);
2506 case BT_GATT_SERVER_ADD_CHARACTERISTIC: {
2507 BT_DBG("GATT Server Add Characteristic");
2510 int *tmp_inst_id = NULL;
2511 bluetooth_gatt_server_attribute_params_t param;
2512 memset(¶m, 0, sizeof(bluetooth_gatt_server_attribute_params_t));
2514 app = (char*)g_dbus_method_invocation_get_sender(context);
2516 __bt_service_get_parameters(in_param1, ¶m,
2517 sizeof(bluetooth_gatt_server_attribute_params_t));
2518 char_uuid = (char *)g_variant_get_data(in_param2);
2520 result = _bt_gatt_server_add_characteristic(app, char_uuid, ¶m);
2521 if (result != BLUETOOTH_ERROR_NONE) {
2522 BT_ERR("GATT Server Add Service failed!!");
2524 tmp_inst_id = g_malloc0(sizeof(int));
2525 *tmp_inst_id = param.instance_id;
2527 _bt_save_invocation_context(context, result, app,
2528 function_name, (gpointer)tmp_inst_id);
2532 case BT_GATT_SERVER_ADD_DESCRIPTOR: {
2533 BT_DBG("GATT Server Add Descriptor");
2537 bt_gatt_permission_t perm;
2539 int *tmp_inst_id = NULL;
2540 memset(&perm, 0, sizeof(bt_gatt_permission_t));
2542 app = (char *)g_dbus_method_invocation_get_sender(context);
2544 __bt_service_get_parameters(in_param1, &service_handle,
2546 __bt_service_get_parameters(in_param2, &instance_id,
2548 desc_uuid = (char *)g_variant_get_data(in_param4);
2549 __bt_service_get_parameters(in_param3, &perm,
2550 sizeof(bt_gatt_permission_t));
2552 result = _bt_gatt_server_add_descriptor(app, desc_uuid, &perm, service_handle, instance_id);
2553 if (result != BLUETOOTH_ERROR_NONE) {
2554 BT_ERR("GATT Server Add Service failed!!");
2556 tmp_inst_id = g_malloc0(sizeof(int));
2557 *tmp_inst_id = instance_id;
2558 _bt_save_invocation_context(context, result, app,
2559 function_name, (gpointer)tmp_inst_id);
2563 case BT_GATT_SERVER_START_SERVICE: {
2568 int *tmp_inst_id = NULL;
2569 app = (char*)g_dbus_method_invocation_get_sender(context);
2571 __bt_service_get_parameters(in_param1, &service_handle,
2573 __bt_service_get_parameters(in_param2, &instance_id,
2576 result = _bt_gatt_server_start_service(app, service_handle, instance_id);
2578 if (BLUETOOTH_ERROR_NONE == result) {
2579 tmp_inst_id = g_malloc0(sizeof(int));
2580 *tmp_inst_id = instance_id;
2581 _bt_save_invocation_context(context, result, app,
2582 function_name, (gpointer)tmp_inst_id);
2586 case BT_GATT_SERVER_STOP_SERVICE: {
2590 int *tmp_inst_id = NULL;
2591 app = (char*)g_dbus_method_invocation_get_sender(context);
2593 __bt_service_get_parameters(in_param1, &service_handle,
2595 __bt_service_get_parameters(in_param2, &instance_id,
2598 result = _bt_gatt_server_stop_service(app, service_handle, instance_id);
2600 if (BLUETOOTH_ERROR_NONE == result) {
2601 tmp_inst_id = g_malloc0(sizeof(int));
2602 *tmp_inst_id = instance_id;
2603 _bt_save_invocation_context(context, result, app,
2604 function_name, (gpointer)tmp_inst_id);
2608 case BT_GATT_SERVER_DELETE_SERVICE: {
2611 int *tmp_inst_id = NULL;
2613 app = (char*)g_dbus_method_invocation_get_sender(context);
2615 __bt_service_get_parameters(in_param1, &service_handle,
2617 __bt_service_get_parameters(in_param2, &instance_id,
2620 result = _bt_gatt_server_delete_service(app, service_handle, instance_id);
2622 if (BLUETOOTH_ERROR_NONE == result) {
2623 tmp_inst_id = g_malloc0(sizeof(int));
2624 *tmp_inst_id = instance_id;
2625 _bt_save_invocation_context(context, result, app,
2626 function_name, (gpointer)tmp_inst_id);
2630 case BT_GATT_SERVER_SET_SERVICE_PERSISTENCE: {
2632 uuid = (char *)g_variant_get_data(in_param1);
2633 result = _bt_gatt_server_set_service_persistence(uuid);
2636 case BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE: {
2638 uuid = (char *)g_variant_get_data(in_param1);
2639 result = _bt_gatt_server_unset_service_persistence(uuid);
2642 case BT_GATT_SERVER_SEND_RESPONSE: {
2643 bluetooth_gatt_server_response_params_t param;
2644 bluetooth_gatt_att_data_t data;
2647 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_response_params_t));
2648 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2650 app = (char*)g_dbus_method_invocation_get_sender(context);
2652 __bt_service_get_parameters(in_param1, &data,
2653 sizeof(bluetooth_gatt_att_data_t));
2654 __bt_service_get_parameters(in_param2, ¶m,
2655 sizeof(bluetooth_gatt_server_response_params_t));
2657 result = _bt_gatt_server_send_response(app, &data, ¶m);
2661 case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE: {
2663 bluetooth_gatt_server_acquire_response_params_t param;
2666 msg = g_dbus_method_invocation_get_message(context);
2667 GUnixFDList *fd_list;
2672 fd_list = g_dbus_message_get_unix_fd_list(msg);
2674 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2676 app = (char*)g_dbus_method_invocation_get_sender(context);
2678 __bt_service_get_parameters(in_param1, ¶m,
2679 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2681 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2682 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2683 fd = fd_list_array[0];
2686 result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
2690 case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE: {
2692 bluetooth_gatt_server_acquire_response_params_t param;
2695 msg = g_dbus_method_invocation_get_message(context);
2696 GUnixFDList *fd_list;
2701 fd_list = g_dbus_message_get_unix_fd_list(msg);
2703 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2705 app = (char*)g_dbus_method_invocation_get_sender(context);
2707 __bt_service_get_parameters(in_param1, ¶m,
2708 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2710 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2711 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2712 fd = fd_list_array[0];
2715 result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
2719 case BT_GATT_SERVER_SEND_INDICATION: {
2720 bluetooth_gatt_server_indication_params_t param;
2721 bluetooth_gatt_att_data_t data;
2722 bluetooth_device_address_t address;
2725 app = (char*)g_dbus_method_invocation_get_sender(context);
2727 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_indication_params_t));
2728 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2729 memset(&address, 0x00, sizeof(bluetooth_device_address_t));
2731 __bt_service_get_parameters(in_param1, &data,
2732 sizeof(bluetooth_gatt_att_data_t));
2733 __bt_service_get_parameters(in_param2, ¶m,
2734 sizeof(bluetooth_gatt_server_indication_params_t));
2735 __bt_service_get_parameters(in_param3, &address,
2736 sizeof(bluetooth_device_address_t));
2738 result = _bt_gatt_server_send_indication(app, &address, &data, ¶m);
2742 case BT_GATT_SERVER_UPDATE_VALUE: {
2743 bluetooth_gatt_server_update_value_t param;
2747 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_update_value_t));
2749 app = (char*)g_dbus_method_invocation_get_sender(context);
2751 __bt_service_get_parameters(in_param1, &instance_id,
2753 __bt_service_get_parameters(in_param2, ¶m,
2754 sizeof(bluetooth_gatt_server_update_value_t));
2756 result = _bt_gatt_server_update_attribute_value(app, instance_id, ¶m);
2759 case BT_GATT_SERVER_READ_PHY: {
2760 bluetooth_device_address_t address = { {0} };
2762 sender = (char*)g_dbus_method_invocation_get_sender(context);
2764 __bt_service_get_parameters(in_param1,
2765 &address, sizeof(bluetooth_device_address_t));
2767 result = _bt_gatt_server_read_phy(&address);
2770 case BT_GATT_SERVER_SET_PHY: {
2771 bluetooth_device_address_t address = { {0} };
2776 sender = (char*)g_dbus_method_invocation_get_sender(context);
2778 __bt_service_get_parameters(in_param1,
2779 &address, sizeof(bluetooth_device_address_t));
2780 __bt_service_get_parameters(in_param2,
2781 &tx_phy, sizeof(int));
2782 __bt_service_get_parameters(in_param3,
2783 &rx_phy, sizeof(int));
2784 __bt_service_get_parameters(in_param4,
2785 &phy_options, sizeof(int));
2787 result = _bt_gatt_server_set_phy(&address, tx_phy, rx_phy, phy_options);
2790 case BT_GATT_CLIENT_READ_PHY: {
2791 bluetooth_device_address_t address = { {0} };
2793 sender = (char*)g_dbus_method_invocation_get_sender(context);
2795 __bt_service_get_parameters(in_param1,
2796 &address, sizeof(bluetooth_device_address_t));
2798 result = _bt_gatt_client_read_phy(&address);
2801 case BT_GATT_CLIENT_SET_PHY: {
2802 bluetooth_device_address_t address = { {0} };
2807 sender = (char*)g_dbus_method_invocation_get_sender(context);
2809 __bt_service_get_parameters(in_param1,
2810 &address, sizeof(bluetooth_device_address_t));
2811 __bt_service_get_parameters(in_param2,
2812 &tx_phy, sizeof(int));
2813 __bt_service_get_parameters(in_param3,
2814 &rx_phy, sizeof(int));
2815 __bt_service_get_parameters(in_param4,
2816 &phy_options, sizeof(int));
2818 result = _bt_gatt_client_set_phy(&address, tx_phy, rx_phy, phy_options);
2821 case BT_GET_ATT_MTU: {
2822 bluetooth_device_address_t address = { {0} };
2823 unsigned int mtu = 0;
2825 __bt_service_get_parameters(in_param1,
2826 &address, sizeof(bluetooth_device_address_t));
2827 result = _bt_get_att_mtu(&address, &mtu);
2828 BT_DBG("MTU: %d", mtu);
2830 if (result == BLUETOOTH_ERROR_NONE) {
2831 g_array_append_vals(*out_param1, &mtu,
2832 sizeof(unsigned int));
2836 case BT_REQ_ATT_MTU: {
2837 bluetooth_device_address_t address = { {0} };
2841 sender = (char*)g_dbus_method_invocation_get_sender(context);
2843 __bt_service_get_parameters(in_param1,
2844 &address, sizeof(bluetooth_device_address_t));
2845 __bt_service_get_parameters(in_param2,
2846 &mtu, sizeof(unsigned int));
2847 BT_DBG("BT_REQ_ATT_MTU: %d", mtu);
2848 result = _bt_request_att_mtu(&address, mtu);
2849 if (BLUETOOTH_ERROR_NONE == result) {
2850 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2852 _bt_convert_addr_type_to_string(addr, address.addr);
2854 /* Save the informations to invocation */
2855 _bt_save_invocation_context(context, result, sender,
2856 function_name, (gpointer)addr);
2858 g_array_append_vals(*out_param1, &address,
2859 sizeof(bluetooth_device_address_t));
2863 case BT_GET_DEVICE_IDA: {
2864 bluetooth_device_address_t address = { {0} };
2865 bluetooth_device_address_t id_addr = { {0} };
2867 __bt_service_get_parameters(in_param1,
2868 &address, sizeof(bluetooth_device_address_t));
2870 result = _bt_device_get_ida(&address, &id_addr);
2872 if (result == BLUETOOTH_ERROR_NONE) {
2873 g_array_append_vals(*out_param1, &id_addr,
2874 sizeof(bluetooth_device_address_t));
2878 case BT_SET_LE_STATIC_RANDOM_ADDRESS: {
2881 __bt_service_get_parameters(in_param1, &is_enable,
2884 result = _bt_set_le_static_random_address(is_enable);
2889 case BT_GATT_CLIENT_REGISTER: {
2890 bluetooth_device_address_t address = { {0} };
2893 sender = (char*)g_dbus_method_invocation_get_sender(context);
2895 __bt_service_get_parameters(in_param1,
2896 &address, sizeof(bluetooth_device_address_t));
2898 result = _bt_register_gatt_client_instance(sender, &address);
2899 if (BLUETOOTH_ERROR_NONE == result) {
2900 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2902 _bt_convert_addr_type_to_string(addr, address.addr);
2904 /* Save the informations to invocation */
2905 _bt_save_invocation_context(context, result, sender,
2906 function_name, (gpointer)addr);
2911 case BT_GATT_CLIENT_UNREGISTER: {
2914 sender = (char*)g_dbus_method_invocation_get_sender(context);
2915 __bt_service_get_parameters(in_param1,
2916 &client_id, sizeof(int));
2918 result = _bt_unregister_gatt_client_instance(sender, client_id);
2922 /* Async: Remote Interaction */
2923 case BT_GATT_ACQUIRE_WRITE: {
2927 bluetooth_gatt_client_char_prop_info_t param;
2929 sender = (char*)g_dbus_method_invocation_get_sender(context);
2931 __bt_service_get_parameters(in_param1, ¶m,
2932 sizeof(bluetooth_gatt_client_char_prop_info_t));
2935 result = _bt_gatt_acquire_write(¶m , &fd, &mtu);
2937 g_array_append_vals(*out_param1, &mtu, sizeof(int));
2939 if (BLUETOOTH_ERROR_NONE == result)
2940 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
2942 BT_ERR("GATT Client: gatt acquire write failed");
2946 GUnixFDList *fd_list = NULL;
2947 GError *error = NULL;
2949 /* Add socket fd to unix_fd_list */
2950 fd_list = g_unix_fd_list_new();
2951 g_unix_fd_list_append(fd_list, fd, &error);
2952 g_assert_no_error(error);
2954 _bt_service_method_return_with_unix_fd_list(
2955 context, *out_param1, result, fd_list);
2958 g_object_unref(fd_list);
2962 /* Async: Remote Interaction */
2963 case BT_CONNECT_LE: {
2964 bluetooth_device_address_t address = { {0} };
2965 gboolean auto_connect;
2969 sender = (char*)g_dbus_method_invocation_get_sender(context);
2971 __bt_service_get_parameters(in_param1,
2972 &address, sizeof(bluetooth_device_address_t));
2973 __bt_service_get_parameters(in_param2,
2974 &auto_connect, sizeof(gboolean));
2975 __bt_service_get_parameters(in_param3,
2976 &client_id, sizeof(int));
2978 BT_DBG("GATT Client: client_id[%d]", client_id);
2979 result = _bt_connect_le_device(&address, auto_connect, client_id);
2980 if (BLUETOOTH_ERROR_NONE == result) {
2981 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2982 _bt_convert_addr_type_to_string(addr, address.addr);
2984 /* Save the informations to invocation */
2985 _bt_save_invocation_context(context, result, sender,
2986 function_name, (gpointer)addr);
2989 _bt_handle_invocation_context(function_name, (void *)addr);
2991 BT_ERR("GATT Client: gatt connect failed. client_id[%d]", client_id);
2992 g_array_append_vals(*out_param1, &address,
2993 sizeof(bluetooth_device_address_t));
2997 /* Async: Remote Interaction */
2998 case BT_DISCONNECT_LE: {
2999 bluetooth_device_address_t address = { {0} };
3003 sender = (char*)g_dbus_method_invocation_get_sender(context);
3005 __bt_service_get_parameters(in_param1,
3006 &address, sizeof(bluetooth_device_address_t));
3007 __bt_service_get_parameters(in_param2,
3008 &client_id, sizeof(int));
3010 BT_INFO("GATT Disconnect using client Interface [%d]", client_id);
3011 result = _bt_disconnect_le_device(&address, client_id);
3012 if (BLUETOOTH_ERROR_NONE == result) {
3013 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
3015 _bt_convert_addr_type_to_string(addr, address.addr);
3017 /* Save the informations to invocation */
3018 _bt_save_invocation_context(context, result, sender,
3019 function_name, (gpointer)addr);
3021 g_array_append_vals(*out_param1, &address,
3022 sizeof(bluetooth_device_address_t));
3027 case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS: {
3028 guint available_packets = 0;
3030 result = _bt_gatt_get_data_batching_available_packets(&available_packets);
3031 BT_DBG("LE batching available packets %u", available_packets);
3032 if (result == BLUETOOTH_ERROR_NONE) {
3033 g_array_append_vals(*out_param1, &available_packets,
3040 case BT_ENABLE_GATT_DATA_BATCHING: {
3041 bluetooth_device_address_t address = { {0} };
3042 int packet_threshold;
3045 __bt_service_get_parameters(in_param1,
3046 &address, sizeof(bluetooth_device_address_t));
3047 __bt_service_get_parameters(in_param2,
3048 &packet_threshold, sizeof(int));
3049 __bt_service_get_parameters(in_param3,
3050 &timeout, sizeof(int));
3051 result = _bt_gatt_enable_data_batching(&address, packet_threshold, timeout);
3056 case BT_DISABLE_GATT_DATA_BATCHING: {
3057 bluetooth_device_address_t address = { {0} };
3059 __bt_service_get_parameters(in_param1,
3060 &address, sizeof(bluetooth_device_address_t));
3061 result = _bt_gatt_disable_data_batching(&address);
3066 case BT_GATT_GET_PRIMARY_SERVICES: {
3069 sender = (char*)g_dbus_method_invocation_get_sender(context);
3070 bluetooth_device_address_t address = { {0} };
3072 __bt_service_get_parameters(in_param1, &address,
3073 sizeof(bluetooth_device_address_t));
3075 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
3076 _bt_convert_addr_type_to_string(addr, address.addr);
3078 result = _bt_gatt_get_primary_services(addr);
3079 if (BLUETOOTH_ERROR_NONE == result) {
3080 _bt_save_invocation_context(context, result, sender,
3081 function_name, (gpointer)addr);
3087 case BT_GATT_GET_SERVICE_PROPERTIES: {
3088 bluetooth_gatt_client_svc_prop_info_t param;
3090 sender = (char*)g_dbus_method_invocation_get_sender(context);
3091 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_svc_prop_info_t));
3093 __bt_service_get_parameters(in_param1, ¶m,
3094 sizeof(bluetooth_gatt_client_svc_prop_info_t));
3096 result = _bt_gatt_get_all_characteristic(¶m);
3097 if (BLUETOOTH_ERROR_NONE == result) {
3098 /* Save the informations to invocation */
3099 _bt_save_invocation_context(context, result, sender,
3101 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_svc_prop_info_t)));
3105 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: {
3106 bluetooth_gatt_client_char_prop_info_t param;
3108 sender = (char*)g_dbus_method_invocation_get_sender(context);
3109 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3111 __bt_service_get_parameters(in_param1, ¶m,
3112 sizeof(bluetooth_gatt_client_char_prop_info_t));
3114 result = _bt_gatt_get_all_characteristic_properties(¶m);
3115 if (BLUETOOTH_ERROR_NONE == result) {
3116 /* Save the informations to invocation */
3117 _bt_save_invocation_context(context, result, sender,
3119 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3123 /* Async: Remote Interaction */
3124 case BT_GATT_READ_CHARACTERISTIC: {
3125 bluetooth_gatt_client_char_prop_info_t param;
3127 sender = (char*)g_dbus_method_invocation_get_sender(context);
3128 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3130 __bt_service_get_parameters(in_param1, ¶m,
3131 sizeof(bluetooth_gatt_client_char_prop_info_t));
3133 result = _bt_gatt_read_characteristic_value(¶m);
3134 if (BLUETOOTH_ERROR_NONE == result) {
3135 /* Save the informations to invocation */
3136 _bt_save_invocation_context(context, result, sender,
3138 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3142 /* Async: Remote Interaction */
3143 case BT_GATT_READ_DESCRIPTOR_VALUE: {
3144 bluetooth_gatt_client_desc_prop_info_t param;
3146 sender = (char*)g_dbus_method_invocation_get_sender(context);
3147 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3149 __bt_service_get_parameters(in_param1, ¶m,
3150 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3152 result = _bt_gatt_read_descriptor_value(¶m);
3153 if (BLUETOOTH_ERROR_NONE == result) {
3154 /* Save the informations to invocation */
3155 _bt_save_invocation_context(context, result, sender,
3157 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3161 /* Async: Remote Interaction */
3162 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: {
3163 bluetooth_gatt_client_char_prop_info_t param;
3164 bluetooth_gatt_att_data_t data;
3165 bluetooth_gatt_write_type_e write_type;
3167 sender = (char*)g_dbus_method_invocation_get_sender(context);
3169 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3170 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3172 __bt_service_get_parameters(in_param1, ¶m,
3173 sizeof(bluetooth_gatt_client_char_prop_info_t));
3174 __bt_service_get_parameters(in_param2, &data,
3175 sizeof(bluetooth_gatt_att_data_t));
3176 __bt_service_get_parameters(in_param3, &write_type,
3177 sizeof(bluetooth_gatt_write_type_e));
3179 result = _bt_gatt_write_characteristic_value_by_type(¶m , &data, write_type);
3180 if (BLUETOOTH_ERROR_NONE == result) {
3181 /* Save the informations to invocation */
3182 _bt_save_invocation_context(context, result, sender,
3184 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3188 /* Async: Remote Interaction */
3189 case BT_GATT_WRITE_DESCRIPTOR_VALUE: {
3190 bluetooth_gatt_client_desc_prop_info_t param;
3191 bluetooth_gatt_att_data_t data;
3192 bluetooth_gatt_write_type_e write_type;
3194 sender = (char*)g_dbus_method_invocation_get_sender(context);
3195 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3196 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3198 __bt_service_get_parameters(in_param1, ¶m,
3199 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3200 __bt_service_get_parameters(in_param2, &data,
3201 sizeof(bluetooth_gatt_att_data_t));
3202 __bt_service_get_parameters(in_param3, &write_type,
3203 sizeof(bluetooth_gatt_write_type_e));
3205 result = _bt_gatt_write_descriptor_value_by_type(¶m, &data, write_type);
3206 if (BLUETOOTH_ERROR_NONE == result) {
3207 /* Save the informations to invocation */
3208 _bt_save_invocation_context(context, result, sender,
3210 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3215 case BT_GATT_WATCH_CHARACTERISTIC: {
3216 bluetooth_gatt_client_char_prop_info_t param;
3221 gboolean is_indicate;
3224 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3226 sender = (char*)g_dbus_method_invocation_get_sender(context);
3228 __bt_service_get_parameters(in_param1, ¶m,
3229 sizeof(bluetooth_gatt_client_char_prop_info_t));
3230 __bt_service_get_parameters(in_param2, &client_id,
3232 __bt_service_get_parameters(in_param3, &is_notify,
3234 __bt_service_get_parameters(in_param4, &is_indicate,
3237 #ifdef TIZEN_FEATURE_BT_GATT_CLIENT_FD_DISABLE
3241 if (is_indicate == false) {
3242 result = _bt_gatt_acquire_notify(¶m , &fd, &mtu);
3243 if (BLUETOOTH_ERROR_NONE == result && fd > -1) {
3244 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
3246 GUnixFDList *fd_list = NULL;
3247 GError *error = NULL;
3249 g_array_append_vals(*out_param1, &mtu, sizeof(int));
3250 /* Add socket fd to unix_fd_list */
3251 fd_list = g_unix_fd_list_new();
3252 g_unix_fd_list_append(fd_list, fd, &error);
3253 g_assert_no_error(error);
3255 _bt_service_method_return_with_unix_fd_list(
3256 context, *out_param1, result, fd_list);
3258 g_object_unref(fd_list);
3264 result = _bt_gatt_watch_characteristic(¶m , client_id, is_notify);
3265 if (BLUETOOTH_ERROR_NONE == result) {
3266 /* Save the informations to invocation */
3267 _bt_save_invocation_context(context, result, sender, function_name,
3268 (gpointer)g_memdup2(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3273 case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: {
3274 gboolean is_enabled;
3275 bluetooth_device_address_t address;
3277 sender = (char*)g_dbus_method_invocation_get_sender(context);
3279 __bt_service_get_parameters(in_param1,
3280 &address, sizeof(bluetooth_device_address_t));
3281 __bt_service_get_parameters(in_param2, &is_enabled,
3283 result = _bt_gatt_watch_service_changed_indication(sender, &address, is_enabled);
3284 BT_INFO("Service changed indication from app [%s]", sender);
3288 case BT_LE_CONN_UPDATE: {
3289 char *sender = NULL;
3290 bluetooth_device_address_t local_address = { {0} };
3291 bluetooth_le_connection_param_t parameters = {0};
3293 sender = (char *)g_dbus_method_invocation_get_sender(context);
3295 __bt_service_get_parameters(in_param1, &local_address,
3296 sizeof(bluetooth_device_address_t));
3297 __bt_service_get_parameters(in_param2, ¶meters,
3298 sizeof(bluetooth_le_connection_param_t));
3300 result = _bt_le_connection_update(sender,
3302 parameters.interval_min,
3303 parameters.interval_max,
3305 parameters.timeout);
3308 case BT_START_LE_DISCOVERY: {
3312 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3314 sender = (char *)g_dbus_method_invocation_get_sender(context);
3316 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3317 BT_ERR("Fail to get the sender pid");
3319 result = _bt_start_le_scan(sender, uid, pid);
3320 if (result == BLUETOOTH_ERROR_NONE) {
3321 _bt_save_invocation_context(context, result, sender,
3322 function_name, NULL);
3324 BT_DBG("Remeber pid / uid for the scan operation");
3325 _bt_bm_add_scan_app(SCAN_LE, uid, pid);
3329 case BT_STOP_LE_DISCOVERY: {
3333 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3335 sender = (char *)g_dbus_method_invocation_get_sender(context);
3337 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3338 BT_ERR("Fail to get the sender pid");
3340 result = _bt_stop_le_scan(sender);
3341 if (result == BLUETOOTH_ERROR_NONE) {
3342 _bt_save_invocation_context(context, result, sender,
3343 function_name, NULL);
3346 BT_DBG("Remove pid / uid for the scan operation");
3347 _bt_bm_remove_scan_app(SCAN_LE, uid, pid);
3351 case BT_IS_LE_DISCOVERYING: {
3352 gboolean le_discovering = FALSE;
3354 le_discovering = _bt_is_le_scanning();
3355 g_array_append_vals(*out_param1,
3356 &le_discovering, sizeof(gboolean));
3359 case BT_SET_SCAN_PARAMETERS: {
3360 bluetooth_le_scan_params_t scan_params;
3362 __bt_service_get_parameters(in_param1, &scan_params,
3363 sizeof(bluetooth_le_scan_params_t));
3365 BT_DBG("bluetooth_le_scan_params_t [%f %f %d]",
3366 scan_params.interval, scan_params.window,
3369 result = _bt_prepare_scan_parameters(&scan_params, 0);
3372 case BT_SET_SCAN_TYPE: {
3374 __bt_service_get_parameters(in_param1, &scan_type, sizeof(int));
3376 BT_DBG("bluetooth_le_scan_type [%d]", scan_type);
3377 result = _bt_prepare_scan_parameters(NULL, scan_type);
3380 #ifdef TIZEN_FEATURE_BT_PAN_NAP
3381 case BT_NETWORK_ACTIVATE:
3382 BT_DBG("BT_NETWORK_ACTIVATE Request recieved Request Handler ");
3383 result = _bt_network_activate();
3385 case BT_NETWORK_DEACTIVATE:
3386 result = _bt_network_deactivate();
3388 case BT_NETWORK_CONNECT: {
3389 bluetooth_device_address_t address = { {0} };
3392 __bt_service_get_parameters(in_param1,
3393 &address, sizeof(bluetooth_device_address_t));
3394 __bt_service_get_parameters(in_param2,
3395 &role, sizeof(int));
3397 result = _bt_network_connect(request_id, role, &address);
3398 if (result != BLUETOOTH_ERROR_NONE) {
3399 g_array_append_vals(*out_param1, &address,
3400 sizeof(bluetooth_device_address_t));
3404 case BT_NETWORK_DISCONNECT: {
3405 bluetooth_device_address_t address = { {0} };
3407 __bt_service_get_parameters(in_param1,
3408 &address, sizeof(bluetooth_device_address_t));
3410 result = _bt_network_disconnect(request_id, &address);
3411 if (result != BLUETOOTH_ERROR_NONE) {
3412 g_array_append_vals(*out_param1, &address,
3413 sizeof(bluetooth_device_address_t));
3417 case BT_NETWORK_SERVER_DISCONNECT: {
3418 bluetooth_device_address_t address = { {0} };
3420 __bt_service_get_parameters(in_param1,
3421 &address, sizeof(bluetooth_device_address_t));
3423 result = _bt_network_server_disconnect(request_id, &address);
3424 if (result != BLUETOOTH_ERROR_NONE) {
3425 g_array_append_vals(*out_param1, &address,
3426 sizeof(bluetooth_device_address_t));
3432 #ifdef TIZEN_FEATURE_BT_IPSP
3433 case BT_LE_IPSP_INIT:
3434 result = _bt_initialize_ipsp();
3436 case BT_LE_IPSP_DEINIT:
3437 result = _bt_deinitialize_ipsp();
3439 case BT_LE_IPSP_CONNECT: {
3440 bluetooth_device_address_t address = { {0} };
3441 __bt_service_get_parameters(in_param1, &address,
3442 sizeof(bluetooth_device_address_t));
3443 result = _bt_connect_le_ipsp_device(&address);
3446 case BT_LE_IPSP_DISCONNECT: {
3447 bluetooth_device_address_t address = { {0} };
3448 __bt_service_get_parameters(in_param1, &address,
3449 sizeof(bluetooth_device_address_t));
3450 result = _bt_disconnect_le_ipsp_device(&address);
3454 case BT_IS_ADVERTISING: {
3455 gboolean advertising = FALSE;
3456 advertising = _bt_is_advertising();
3457 g_array_append_vals(*out_param1, &advertising,
3461 case BT_IS_LE_2M_PHY_SUPPORTED: {
3462 gboolean is_2m_phy_supported = FALSE;
3464 is_2m_phy_supported = _bt_is_le_2m_phy_supported();
3465 g_array_append_vals(*out_param1, &is_2m_phy_supported, sizeof(gboolean));
3468 case BT_IS_LE_CODED_PHY_SUPPORTED: {
3469 gboolean is_coded_phy_supported = FALSE;
3471 is_coded_phy_supported = _bt_is_le_coded_phy_supported();
3472 g_array_append_vals(*out_param1, &is_coded_phy_supported, sizeof(gboolean));
3475 case BT_IS_LE_EXTENDED_ADVERTISING_SUPPORTED: {
3476 gboolean is_extended_advertising_supported = FALSE;
3478 is_extended_advertising_supported = _bt_is_le_extended_advertising_supported();
3479 g_array_append_vals(*out_param1, &is_extended_advertising_supported,
3483 case BT_IS_LE_EXTENDED_SCAN_SUPPORTED: {
3484 gboolean is_extended_scan_supported = FALSE;
3486 is_extended_scan_supported = _bt_is_le_extended_scan_supported();
3487 g_array_append_vals(*out_param1, &is_extended_scan_supported, sizeof(gboolean));
3490 case BT_LE_MAX_ADVERTISING_DATA_LEN: {
3491 gint max_advertising_len = 0;
3493 max_advertising_len = _bt_le_get_maximum_advertising_len();
3494 g_array_append_vals(*out_param1, &max_advertising_len, sizeof(gint));
3497 case BT_DISCONNECT_DEVICE: {
3498 bluetooth_device_address_t address = { {0} };
3500 __bt_service_get_parameters(in_param1,
3501 &address, sizeof(bluetooth_device_address_t));
3503 result = _bt_disconnect_device(&address);
3506 case BT_SET_SCANNING_PHY: {
3508 sender = (char*)g_dbus_method_invocation_get_sender(context);
3509 __bt_service_get_parameters(in_param1, &phy, sizeof(int));
3511 result = _bt_set_scan_phy(sender, phy);
3515 case BT_SET_SCANNING_ROLE: {
3517 sender = (char*)g_dbus_method_invocation_get_sender(context);
3518 __bt_service_get_parameters(in_param1, &role, sizeof(int));
3520 result = _bt_set_scan_role(sender, role);
3524 case BT_REGISTER_SCAN_FILTER: {
3525 bluetooth_le_scan_filter_t scan_filter;
3527 sender = (char*)g_dbus_method_invocation_get_sender(context);
3528 __bt_service_get_parameters(in_param1, &scan_filter,
3529 sizeof(bluetooth_le_scan_filter_t));
3531 BT_DBG("bluetooth_le_scan_filter_t [features : 0x%.2x]",
3532 scan_filter.added_features);
3534 result = _bt_register_scan_filter(sender, &scan_filter);
3539 case BT_TDS_PROVIDER_REGISTER: {
3540 char *sender = NULL;
3542 sender = (char *)g_dbus_method_invocation_get_sender(context);
3543 result = _bt_tds_provider_register(sender);
3548 case BT_TDS_PROVIDER_UNREGISTER: {
3549 char *sender = NULL;
3551 sender = (char *)g_dbus_method_invocation_get_sender(context);
3552 result = _bt_tds_provider_unregister(sender);
3557 case BT_TDS_PROVIDER_SET_MANUF_DATA: {
3558 char *sender = NULL;
3559 unsigned int length = 0;
3560 bluetooth_advertising_data_t manuf_data;
3562 __bt_service_get_parameters(in_param1,
3563 &length, sizeof(unsigned int));
3564 __bt_service_get_parameters(in_param2,
3565 &manuf_data, sizeof(bluetooth_advertising_data_t));
3566 sender = (char *)g_dbus_method_invocation_get_sender(context);
3568 result = _bt_tds_provider_set_manuf_data(sender, manuf_data.data, length);
3572 case BT_TDS_PROVIDER_CREATE: {
3573 char *sender = NULL;
3574 unsigned int tds_handle = 0;
3577 __bt_service_get_parameters(in_param1,
3578 &tds_handle, sizeof(unsigned int));
3579 __bt_service_get_parameters(in_param2,
3580 &transport, sizeof(int));
3581 sender = (char *)g_dbus_method_invocation_get_sender(context);
3582 result = _bt_tds_provider_transport_create(sender, transport, tds_handle);
3587 case BT_TDS_PROVIDER_DESTROY: {
3588 char *sender = NULL;
3589 unsigned int tds_handle = 0;
3591 __bt_service_get_parameters(in_param1,
3592 &tds_handle, sizeof(unsigned int));
3593 sender = (char *)g_dbus_method_invocation_get_sender(context);
3594 result = _bt_tds_provider_transport_remove(sender, tds_handle);
3599 case BT_TDS_PROVIDER_SET_TRANSPORT_DATA: {
3600 char *sender = NULL;
3601 unsigned int tds_handle = 0;
3602 int transport_state = 0;
3603 bluetooth_tds_data_t tds_data;
3605 __bt_service_get_parameters(in_param1,
3606 &tds_handle, sizeof(unsigned int));
3607 __bt_service_get_parameters(in_param2,
3608 &transport_state, sizeof(int));
3609 __bt_service_get_parameters(in_param3,
3610 &tds_data, sizeof(bluetooth_tds_data_t));
3611 sender = (char *)g_dbus_method_invocation_get_sender(context);
3613 result = _bt_tds_provider_set_transport_data(sender, tds_handle,
3614 transport_state, tds_data.data, tds_data.length);
3618 case BT_TDS_SEND_ACTIVATION_RESPONSE: {
3619 bluetooth_device_address_t address = { {0} };
3620 bluetooth_tds_data_t tds_data;
3621 char *sender = NULL;
3622 unsigned int tds_handle = 0;
3625 __bt_service_get_parameters(in_param1,
3626 &tds_handle, sizeof(unsigned int));
3627 __bt_service_get_parameters(in_param2,
3628 &response, sizeof(int));
3629 __bt_service_get_parameters(in_param3, &address,
3630 sizeof(bluetooth_device_address_t));
3631 __bt_service_get_parameters(in_param4,
3632 &tds_data, sizeof(bluetooth_tds_data_t));
3633 sender = (char *)g_dbus_method_invocation_get_sender(context);
3635 result = _bt_tds_provider_send_activation_response(sender, tds_handle,
3636 &address, response, tds_data.data, tds_data.length);
3641 sender = (char*)g_dbus_method_invocation_get_sender(context);
3642 BT_INFO("Mesh: Init by [%s]", sender);
3643 result = _bt_mesh_init(sender);
3644 /* Save invocation */
3645 if (result == BLUETOOTH_ERROR_NONE) {
3646 BT_INFO("Mesh: Save Invoation");
3647 sender = (char*)g_dbus_method_invocation_get_sender(context);
3648 _bt_save_invocation_context(context,
3650 function_name, NULL);
3654 case BT_MESH_DEINIT:
3655 sender = (char*)g_dbus_method_invocation_get_sender(context);
3656 BT_INFO("Mesh: De-Init by [%s]", sender);
3657 result = _bt_mesh_deinit(sender);
3660 case BT_MESH_NETWORK_CREATE: {
3661 bluetooth_mesh_node_t node;
3662 GSList *model_list = NULL;
3663 int total_models = 0;
3666 const char *network_name = NULL;
3667 bluetooth_mesh_network_t *network;
3669 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
3670 sender = (char*)g_dbus_method_invocation_get_sender(context);
3672 __bt_service_get_parameters(in_param1,
3673 &node, sizeof(bluetooth_mesh_node_t));
3674 network_name = (const char *)g_variant_get_data(in_param2);
3676 BT_INFO("MESH: Network name [%s]", network_name);
3678 param3 = g_array_new(TRUE, TRUE, sizeof(gchar));
3679 __bt_fill_garray_from_variant(in_param3, param3);
3681 total_models = (param3->len) / sizeof(bluetooth_mesh_model_t);
3682 for (i = 0; i < total_models; i++) {
3683 bluetooth_mesh_model_t *info = NULL;
3684 bluetooth_mesh_model_t *mod = NULL;
3686 info = &g_array_index(param3,
3687 bluetooth_mesh_model_t, i);
3689 mod = g_memdup2(info, sizeof(bluetooth_mesh_model_t));
3692 model_list = g_slist_append(model_list,
3695 result = _bt_mesh_network_create(requester_unique_creds,
3696 sender, network_name, &node, model_list);
3698 /* Save invocation */
3699 if (result == BLUETOOTH_ERROR_NONE) {
3700 BT_INFO("Mesh: Save Invoation");
3701 network = g_malloc0(sizeof(bluetooth_mesh_network_t));
3703 /* Save Network name & UUID, Token will be received in event */
3704 _bt_mesh_util_convert_hex_to_string(
3705 (uint8_t *) node.uuid, 16,
3707 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
3708 BT_INFO("Mesh: Mesh Netwok UUID [%s]", network->uuid);
3709 g_strlcpy(network->name.name, network_name,
3710 sizeof(network->name.name));
3711 g_strlcpy(network->app_cred,
3712 requester_unique_creds,
3713 sizeof(network->app_cred));
3714 sender = (char*)g_dbus_method_invocation_get_sender(context);
3715 BT_INFO("Mesh: Network Create by [%s]", sender);
3716 _bt_save_invocation_context(context,
3718 function_name, (gpointer)network);
3720 g_array_append_vals(*out_param1, &node, sizeof(bluetooth_mesh_node_t));
3721 BT_ERR("Mesh: Mesh Network creation schedule failed");
3722 g_slist_free_full(model_list, g_free);
3726 BT_INFO("Mesh: Cleanup");
3727 g_free((gpointer)requester_unique_creds);
3728 g_array_free(param3, TRUE);
3729 BT_INFO("Mesh: Cleanup Done");
3732 case BT_MESH_NETWORK_DESTROY: {
3733 bluetooth_mesh_network_t network;
3734 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3736 __bt_service_get_parameters(in_param1,
3737 &network, sizeof(bluetooth_mesh_network_t));
3739 BT_INFO("Mesh: Destroy Network");
3740 result = _bt_mesh_network_destroy(requester_unique_creds,
3743 if (result != BLUETOOTH_ERROR_NONE) {
3744 g_array_append_vals(*out_param1,
3745 &network, sizeof(bluetooth_mesh_network_t));
3747 BT_INFO("Mesh: Destroy Network scheduled: add invocation");
3748 bluetooth_mesh_network_t *net = \
3749 g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
3751 sender = (char*)g_dbus_method_invocation_get_sender(context);
3752 _bt_save_invocation_context(context, result, sender,
3753 function_name, (gpointer)net);
3757 case BT_MESH_NETWORK_LOAD: {
3759 bluetooth_mesh_network_t *network;
3760 token = (char *)g_variant_get_data(in_param1);
3761 BT_INFO("MESH: Network Load: Token string [%s]", token);
3762 result = _bt_mesh_network_load(requester_unique_creds, sender, token);
3763 /* Save invocation */
3764 if (result == BLUETOOTH_ERROR_NONE) {
3765 network = g_malloc0(sizeof(bluetooth_mesh_network_t));
3766 g_strlcpy(network->token.token, token,
3767 BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
3768 g_strlcpy(network->app_cred, requester_unique_creds,
3769 sizeof(network->app_cred));
3771 sender = (char*)g_dbus_method_invocation_get_sender(context);
3772 _bt_save_invocation_context(context, result, sender,
3773 function_name, (gpointer)network);
3775 g_free((gpointer)requester_unique_creds);
3778 case BT_MESH_NETWORK_UNLOAD: {
3779 bluetooth_mesh_network_t network;
3780 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3782 __bt_service_get_parameters(in_param1,
3783 &network, sizeof(bluetooth_mesh_network_t));
3785 BT_INFO("MESH: Network Unload: Network UUID [%s]", network.uuid);
3786 result = _bt_mesh_network_unload(requester_unique_creds,
3790 case BT_MESH_NETWORK_JOIN: {
3791 bluetooth_mesh_node_t node;
3792 GSList *model_list = NULL;
3793 int total_models = 0;
3797 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
3798 sender = (char*)g_dbus_method_invocation_get_sender(context);
3800 __bt_service_get_parameters(in_param1,
3801 &node, sizeof(bluetooth_mesh_node_t));
3803 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
3804 __bt_fill_garray_from_variant(in_param2, param2);
3806 total_models = (param2->len) / sizeof(bluetooth_mesh_model_t);
3807 for (i = 0; i < total_models; i++) {
3808 bluetooth_mesh_model_t *info = NULL;
3809 bluetooth_mesh_model_t *mod = NULL;
3810 info = &g_array_index(param2,
3811 bluetooth_mesh_model_t, i);
3812 mod = g_memdup2(info, sizeof(bluetooth_mesh_model_t));
3815 model_list = g_slist_append(model_list,
3819 BT_INFO("MESH: Network Join bt-service");
3820 //result = BLUETOOTH_ERROR_NONE;
3821 result = _bt_mesh_network_join(requester_unique_creds,
3822 sender, &node, model_list);
3823 if (result != BLUETOOTH_ERROR_NONE) {
3824 g_array_append_vals(*out_param1, &node, sizeof(bluetooth_mesh_node_t));
3825 BT_ERR("Mesh: Mesh Join Network schedule failed");
3826 g_slist_free_full(model_list, g_free);
3829 BT_INFO("return of _bt_mesh_network_join : [%d]", result);
3832 case BT_MESH_CANCEL_JOIN: {
3833 bluetooth_mesh_node_info_t node;
3834 memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t));
3836 __bt_service_get_parameters(in_param1,
3837 &node, sizeof(bluetooth_mesh_node_info_t));
3839 BT_INFO("Mesh: Cancel Join request");
3840 result = _bt_mesh_cancel_join(requester_unique_creds,
3842 if (result != BLUETOOTH_ERROR_NONE) {
3843 g_array_append_vals(*out_param1,
3844 &node, sizeof(bluetooth_mesh_node_t));
3848 case BT_MESH_NETWORK_SCAN: {
3849 bluetooth_mesh_network_t network;
3850 bluetooth_mesh_scan_param_t param;
3851 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3852 memset(¶m, 0x00, sizeof(bluetooth_mesh_scan_param_t));
3854 __bt_service_get_parameters(in_param1,
3855 &network, sizeof(bluetooth_mesh_network_t));
3857 __bt_service_get_parameters(in_param2,
3858 ¶m, sizeof(bluetooth_mesh_scan_param_t));
3860 result = _bt_mesh_network_scan(requester_unique_creds,
3861 sender, &network, ¶m);
3863 if (result != BLUETOOTH_ERROR_NONE) {
3864 g_array_append_vals(*out_param1,
3865 &network, sizeof(bluetooth_mesh_network_t));
3867 bluetooth_mesh_network_t *net = \
3868 g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
3870 sender = (char*)g_dbus_method_invocation_get_sender(context);
3871 _bt_save_invocation_context(context, result, sender,
3872 function_name, (gpointer)net);
3876 case BT_MESH_NETWORK_CANCEL_SCAN: {
3877 bluetooth_mesh_network_t network;
3878 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3880 __bt_service_get_parameters(in_param1,
3881 &network, sizeof(bluetooth_mesh_network_t));
3883 result = _bt_mesh_network_scan_cancel(requester_unique_creds,
3886 if (result != BLUETOOTH_ERROR_NONE)
3887 g_array_append_vals(*out_param1,
3888 &network, sizeof(bluetooth_mesh_network_t));
3891 case BT_MESH_NETWORK_SET_CAPABILITIES: {
3892 bluetooth_mesh_network_t network;
3893 bluetooth_mesh_provisioner_caps_t caps;
3894 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3895 memset(&caps, 0x00, sizeof(bluetooth_mesh_provisioner_caps_t));
3897 __bt_service_get_parameters(in_param1,
3898 &network, sizeof(bluetooth_mesh_network_t));
3900 __bt_service_get_parameters(in_param2,
3901 &caps, sizeof(bluetooth_mesh_provisioner_caps_t));
3903 result = _bt_mesh_network_set_provisioner_caps(
3904 requester_unique_creds, sender, &network, &caps);
3908 case BT_MESH_NETWORK_PROVISION_DEVICE: {
3909 bluetooth_mesh_provisioning_request_t req;
3910 memset(&req, 0x00, sizeof(bluetooth_mesh_provisioning_request_t));
3912 __bt_service_get_parameters(in_param1,
3913 &req, sizeof(bluetooth_mesh_provisioning_request_t));
3915 BT_INFO("Mesh: Provision Device UUID [%s]", req.dev_uuid);
3916 BT_INFO("Mesh: Provision Device in network[%s]", req.net_uuid);
3918 result = _bt_mesh_network_provision_device(
3919 requester_unique_creds, sender, &req);
3921 /* Save invocation */
3922 if (result != BLUETOOTH_ERROR_NONE) {
3923 g_array_append_vals(*out_param1, &req,
3924 sizeof(bluetooth_mesh_provisioning_request_t));
3926 bluetooth_mesh_provisioning_request_t *param = \
3927 g_memdup2(&req, sizeof(bluetooth_mesh_provisioning_request_t));
3929 sender = (char*)g_dbus_method_invocation_get_sender(context);
3930 _bt_save_invocation_context(context, result, sender,
3931 function_name, (gpointer)param);
3935 case BT_MESH_AUTHENTICATION_REPLY: {
3936 BT_INFO("Mesh: BT_MESH_AUTHENTICATION_REPLY");
3937 const char *auth_value = NULL;
3938 gboolean authentication_reply = FALSE;
3940 auth_value = g_variant_get_data(in_param2);
3941 __bt_service_get_parameters(in_param3,
3942 &authentication_reply, sizeof(gboolean));
3943 __bt_service_get_parameters(in_param1,
3944 &auth_type, sizeof(int));
3945 BT_INFO("Mesh: Auth Reply Type [%d]", auth_type);
3946 BT_INFO("Mesh: Auth Value [%s]", auth_value);
3947 BT_INFO("Mesh: Auth Accept [%d]", authentication_reply);
3948 result = _bt_mesh_authentication_reply(auth_type,
3949 auth_value, authentication_reply);
3952 case BT_MESH_NETWORK_SET_NAME: {
3953 bluetooth_mesh_network_t network;
3954 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3956 __bt_service_get_parameters(in_param1,
3957 &network, sizeof(bluetooth_mesh_network_t));
3959 result = _bt_mesh_network_set_name(requester_unique_creds, sender, &network);
3963 case BT_MESH_NETWORK_ADD_NETKEY: {
3964 bluetooth_mesh_network_t network;
3965 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3967 __bt_service_get_parameters(in_param1,
3968 &network, sizeof(bluetooth_mesh_network_t));
3970 result = _bt_mesh_network_add_netkey(requester_unique_creds,
3973 if (result != BLUETOOTH_ERROR_NONE) {
3974 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3976 bluetooth_mesh_network_t *net = g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
3978 sender = (char*)g_dbus_method_invocation_get_sender(context);
3979 _bt_save_invocation_context(context, result, sender,
3980 function_name, (gpointer)net);
3984 case BT_MESH_NETWORK_DELETE_NETKEY: {
3985 bluetooth_mesh_network_t network;
3988 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3990 __bt_service_get_parameters(in_param1,
3991 &network, sizeof(bluetooth_mesh_network_t));
3992 __bt_service_get_parameters(in_param2,
3993 &index, sizeof(guint16));
3995 result = _bt_mesh_network_delete_netkey(requester_unique_creds,
3996 sender, &network, index);
3998 if (result != BLUETOOTH_ERROR_NONE) {
3999 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
4001 bluetooth_mesh_network_t *net = g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
4003 sender = (char*)g_dbus_method_invocation_get_sender(context);
4004 _bt_save_invocation_context(context, result, sender,
4005 function_name, (gpointer)net);
4009 case BT_MESH_NETWORK_UPDATE_NETKEY: {
4010 bluetooth_mesh_network_t network;
4013 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4015 __bt_service_get_parameters(in_param1,
4016 &network, sizeof(bluetooth_mesh_network_t));
4017 __bt_service_get_parameters(in_param2,
4018 &index, sizeof(guint16));
4020 result = _bt_mesh_network_update_netkey(requester_unique_creds,
4021 sender, &network, index);
4023 if (result != BLUETOOTH_ERROR_NONE) {
4024 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
4026 bluetooth_mesh_network_t *net = g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
4028 sender = (char*)g_dbus_method_invocation_get_sender(context);
4029 _bt_save_invocation_context(context, result, sender,
4030 function_name, (gpointer)net);
4034 case BT_MESH_NETWORK_ADD_APPKEY: {
4035 bluetooth_mesh_network_t network;
4038 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4040 __bt_service_get_parameters(in_param1,
4041 &network, sizeof(bluetooth_mesh_network_t));
4042 __bt_service_get_parameters(in_param2,
4043 &net_idx, sizeof(guint16));
4045 result = _bt_mesh_network_add_appkey(requester_unique_creds,
4046 sender, &network, net_idx);
4048 if (result != BLUETOOTH_ERROR_NONE) {
4049 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
4051 bluetooth_mesh_network_t *net = g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
4053 sender = (char*)g_dbus_method_invocation_get_sender(context);
4054 _bt_save_invocation_context(context, result, sender,
4055 function_name, (gpointer)net);
4059 case BT_MESH_NETWORK_UPDATE_APPKEY: {
4060 bluetooth_mesh_network_t network;
4064 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4066 __bt_service_get_parameters(in_param1,
4067 &network, sizeof(bluetooth_mesh_network_t));
4068 __bt_service_get_parameters(in_param2,
4069 &net_idx, sizeof(guint16));
4070 __bt_service_get_parameters(in_param3,
4071 &app_idx, sizeof(guint16));
4073 result = _bt_mesh_network_update_appkey(requester_unique_creds,
4074 sender, &network, net_idx, app_idx);
4076 if (result != BLUETOOTH_ERROR_NONE) {
4077 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
4079 bluetooth_mesh_network_t *net = g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
4081 sender = (char*)g_dbus_method_invocation_get_sender(context);
4082 _bt_save_invocation_context(context, result, sender,
4083 function_name, (gpointer)net);
4087 case BT_MESH_NETWORK_DELETE_APPKEY: {
4088 bluetooth_mesh_network_t network;
4092 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4094 __bt_service_get_parameters(in_param1,
4095 &network, sizeof(bluetooth_mesh_network_t));
4096 __bt_service_get_parameters(in_param2,
4097 &net_idx, sizeof(guint16));
4098 __bt_service_get_parameters(in_param3,
4099 &app_idx, sizeof(guint16));
4101 result = _bt_mesh_network_delete_appkey(requester_unique_creds,
4102 sender, &network, net_idx, app_idx);
4104 if (result != BLUETOOTH_ERROR_NONE) {
4105 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
4107 bluetooth_mesh_network_t *net = g_memdup2(&network, sizeof(bluetooth_mesh_network_t));
4109 sender = (char*)g_dbus_method_invocation_get_sender(context);
4110 _bt_save_invocation_context(context, result, sender,
4111 function_name, (gpointer)net);
4115 case BT_MESH_NETWORK_GET_NETKEYS: {
4116 bluetooth_mesh_network_t network;
4117 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4118 __bt_service_get_parameters(in_param1,
4119 &network, sizeof(bluetooth_mesh_network_t));
4120 result = _bt_mesh_network_get_netkeys(requester_unique_creds,
4121 sender, &network, out_param1);
4124 case BT_MESH_NETWORK_GET_APPKEYS: {
4125 bluetooth_mesh_network_t network;
4128 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4129 __bt_service_get_parameters(in_param1,
4130 &network, sizeof(bluetooth_mesh_network_t));
4131 __bt_service_get_parameters(in_param2,
4132 &net_idx, sizeof(guint16));
4133 result = _bt_mesh_network_get_appkeys(
4134 requester_unique_creds, sender,
4135 &network, net_idx, out_param1);
4138 case BT_MESH_NETWORK_GET_NODES: {
4139 bluetooth_mesh_network_t network;
4140 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4141 __bt_service_get_parameters(in_param1,
4142 &network, sizeof(bluetooth_mesh_network_t));
4143 result = _bt_mesh_network_get_nodes(
4144 requester_unique_creds, sender,
4145 &network, out_param1);
4148 case BT_MESH_ELEMENT_GET_MODELS: {
4149 bluetooth_mesh_network_t network;
4153 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4154 __bt_service_get_parameters(in_param1,
4155 &network, sizeof(bluetooth_mesh_network_t));
4156 __bt_service_get_parameters(in_param2,
4157 &node_addr, sizeof(guint16));
4158 __bt_service_get_parameters(in_param3,
4159 &elem_idx, sizeof(int));
4160 result = _bt_mesh_element_get_models(requester_unique_creds, sender,
4161 &network, node_addr, elem_idx, out_param1);
4164 case BT_MESH_NODE_BROWSE: {
4165 bluetooth_mesh_node_discover_t req;
4166 memset(&req, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4168 __bt_service_get_parameters(in_param1,
4169 &req, sizeof(bluetooth_mesh_node_discover_t));
4171 result = _bt_mesh_browse_remote_node(
4172 requester_unique_creds, sender, &req);
4174 /* Save invocation */
4175 if (result != BLUETOOTH_ERROR_NONE) {
4176 g_array_append_vals(*out_param1, &req,
4177 sizeof(bluetooth_mesh_node_discover_t));
4179 bluetooth_mesh_node_discover_t *param = \
4180 g_memdup2(&req, sizeof(bluetooth_mesh_node_discover_t));
4182 sender = (char*)g_dbus_method_invocation_get_sender(context);
4183 _bt_save_invocation_context(context, result, sender,
4184 function_name, (gpointer)param);
4188 case BT_MESH_NODE_GET_VENDOR_FEATURES: {
4189 bluetooth_mesh_node_features_t req;
4190 memset(&req, 0x00, sizeof(bluetooth_mesh_node_features_t));
4192 __bt_service_get_parameters(in_param1,
4193 &req, sizeof(bluetooth_mesh_node_features_t));
4195 result = _bt_mesh_node_discover_vendor_features(
4196 requester_unique_creds, sender, &req);
4198 /* Save invocation */
4199 if (result != BLUETOOTH_ERROR_NONE) {
4200 g_array_append_vals(*out_param1,
4201 &req, sizeof(bluetooth_mesh_node_features_t));
4203 bluetooth_mesh_node_features_t *param = \
4204 g_memdup2(&req, sizeof(bluetooth_mesh_node_features_t));
4206 sender = (char*)g_dbus_method_invocation_get_sender(context);
4207 _bt_save_invocation_context(context, result, sender,
4208 function_name, (gpointer)param);
4212 case BT_MESH_NODE_CONFIGURE_KEY: {
4213 bluetooth_mesh_key_configure_t req;
4215 memset(&req, 0x00, sizeof(bluetooth_mesh_key_configure_t));
4217 __bt_service_get_parameters(in_param1,
4218 &req, sizeof(bluetooth_mesh_key_configure_t));
4220 result = _bt_mesh_node_configure_key(
4221 requester_unique_creds, sender, &req);
4223 /* Save invocation */
4224 if (result != BLUETOOTH_ERROR_NONE) {
4225 g_array_append_vals(*out_param1,
4226 &req, sizeof(bluetooth_mesh_key_configure_t));
4228 bluetooth_mesh_key_configure_t *param = \
4229 g_memdup2(&req, sizeof(bluetooth_mesh_key_configure_t));
4231 sender = (char*)g_dbus_method_invocation_get_sender(context);
4232 _bt_save_invocation_context(context, result, sender,
4233 function_name, (gpointer)param);
4237 case BT_MESH_NODE_TTL_EXECUTE: {
4238 bluetooth_mesh_node_ttl_info_t req;
4240 memset(&req, 0x00, sizeof(bluetooth_mesh_node_ttl_info_t));
4242 __bt_service_get_parameters(in_param1,
4243 &req, sizeof(bluetooth_mesh_node_ttl_info_t));
4245 result = _bt_mesh_ttl_execute_remote_node(
4246 requester_unique_creds, sender, &req);
4248 /* Save invocation */
4249 if (result != BLUETOOTH_ERROR_NONE) {
4250 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_node_ttl_info_t));
4252 bluetooth_mesh_node_ttl_info_t *param = \
4253 g_memdup2(&req, sizeof(bluetooth_mesh_node_ttl_info_t));
4255 sender = (char*)g_dbus_method_invocation_get_sender(context);
4256 _bt_save_invocation_context(context, result, sender,
4257 function_name, (gpointer)param);
4261 case BT_MESH_MODEL_CONFIGURE_APPKEY: {
4262 bluetooth_mesh_model_configure_t req;
4264 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4266 __bt_service_get_parameters(in_param1,
4267 &req, sizeof(bluetooth_mesh_model_configure_t));
4269 result = _bt_mesh_node_model_appkey_execute(
4270 requester_unique_creds, sender, &req);
4272 /* Save invocation */
4273 if (result != BLUETOOTH_ERROR_NONE) {
4274 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4276 bluetooth_mesh_model_configure_t *param = \
4277 g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4279 sender = (char*)g_dbus_method_invocation_get_sender(context);
4280 _bt_save_invocation_context(context, result, sender,
4281 function_name, (gpointer)param);
4285 case BT_MESH_MODEL_EXECUTE_MSG: {
4286 bluetooth_mesh_model_msg_t req;
4288 memset(&req, 0x00, sizeof(bluetooth_mesh_model_msg_t));
4290 __bt_service_get_parameters(in_param1,
4291 &req, sizeof(bluetooth_mesh_model_msg_t));
4293 result = _bt_mesh_model_execute_msg(
4294 requester_unique_creds, sender, &req);
4296 /* Save invocation */
4297 if (result != BLUETOOTH_ERROR_NONE) {
4298 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_msg_t));
4300 bluetooth_mesh_model_msg_t *param = \
4301 g_memdup2(&req, sizeof(bluetooth_mesh_model_msg_t));
4303 sender = (char*)g_dbus_method_invocation_get_sender(context);
4304 _bt_save_invocation_context(context, result, sender,
4305 function_name, (gpointer)param);
4309 case BT_MESH_MODEL_RESPONSE_MSG: {
4310 bluetooth_mesh_model_msg_t req;
4311 memset(&req, 0x00, sizeof(bluetooth_mesh_model_msg_t));
4312 __bt_service_get_parameters(in_param1,
4313 &req, sizeof(bluetooth_mesh_model_msg_t));
4315 result = _bt_mesh_model_send_response(
4316 requester_unique_creds, sender, &req);
4317 if (result != BLUETOOTH_ERROR_NONE)
4318 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_msg_t));
4321 case BT_MESH_NODE_GET_NETKEYS: {
4322 bluetooth_mesh_node_discover_t node;
4323 memset(&node, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4324 __bt_service_get_parameters(in_param1,
4325 &node, sizeof(bluetooth_mesh_node_discover_t));
4326 result = _bt_mesh_network_node_get_netkeys(
4327 requester_unique_creds, &node, out_param1);
4330 case BT_MESH_NODE_GET_APPKEYS: {
4331 bluetooth_mesh_node_discover_t node;
4332 memset(&node, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4333 __bt_service_get_parameters(in_param1,
4334 &node, sizeof(bluetooth_mesh_node_discover_t));
4335 result = _bt_mesh_network_node_get_appkeys(
4336 requester_unique_creds, sender, &node, out_param1);
4339 case BT_MESH_NODE_RESET: {
4340 bluetooth_mesh_node_info_t node;
4341 memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t));
4343 __bt_service_get_parameters(in_param1,
4344 &node, sizeof(bluetooth_mesh_node_info_t));
4346 BT_INFO("Mesh: Reset the Node");
4347 result = _bt_mesh_network_reset_node(requester_unique_creds,
4352 case BT_MESH_MODEL_GET_APPKEY_LIST: {
4353 bluetooth_mesh_model_configure_t req;
4355 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4357 __bt_service_get_parameters(in_param1,
4358 &req, sizeof(bluetooth_mesh_model_configure_t));
4360 result = _bt_mesh_node_model_get_appkey_list(
4361 requester_unique_creds, sender, &req);
4363 /* Save invocation */
4364 if (result != BLUETOOTH_ERROR_NONE) {
4365 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4367 bluetooth_mesh_model_configure_t *param = \
4368 g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4370 sender = (char*)g_dbus_method_invocation_get_sender(context);
4371 _bt_save_invocation_context(context, result, sender,
4372 function_name, (gpointer)param);
4376 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST: {
4377 bluetooth_mesh_model_configure_t req;
4379 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4381 __bt_service_get_parameters(in_param1,
4382 &req, sizeof(bluetooth_mesh_model_configure_t));
4384 result = _bt_mesh_node_model_get_subscription_list(
4385 requester_unique_creds, sender, &req);
4387 /* Save invocation */
4388 if (result != BLUETOOTH_ERROR_NONE) {
4389 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4391 bluetooth_mesh_model_configure_t *param = \
4392 g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4394 sender = (char*)g_dbus_method_invocation_get_sender(context);
4395 _bt_save_invocation_context(context, result, sender,
4396 function_name, (gpointer)param);
4401 case BT_MESH_NETWORK_CREATE_GROUP: {
4402 bluetooth_mesh_network_t net;
4403 bluetooth_mesh_network_group_info_t res;
4404 gboolean is_virtual;
4407 memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
4408 memset(&res, 0x00, sizeof(bluetooth_mesh_network_group_info_t));
4410 __bt_service_get_parameters(in_param1,
4411 &net, sizeof(bluetooth_mesh_network_t));
4412 __bt_service_get_parameters(in_param2,
4413 &is_virtual, sizeof(gboolean));
4414 __bt_service_get_parameters(in_param3,
4415 &grp_addr, sizeof(guint16));
4417 result = _bt_mesh_network_create_group(
4418 requester_unique_creds, sender, &net,
4419 is_virtual, grp_addr, &res);
4421 if (result == BLUETOOTH_ERROR_NONE)
4422 g_array_append_vals(*out_param1, &res,
4423 sizeof(bluetooth_mesh_network_group_info_t));
4426 case BT_MESH_NETWORK_REMOVE_GROUP: {
4427 bluetooth_mesh_network_t net;
4428 bluetooth_mesh_network_group_info_t req;
4430 memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
4431 memset(&req, 0x00, sizeof(bluetooth_mesh_network_group_info_t));
4433 __bt_service_get_parameters(in_param1,
4434 &net, sizeof(bluetooth_mesh_network_t));
4435 __bt_service_get_parameters(in_param2,
4436 &req, sizeof(bluetooth_mesh_network_group_info_t));
4438 result = _bt_mesh_network_remove_group(
4439 requester_unique_creds, sender, &net, &req);
4443 case BT_MESH_MODEL_CONFIG_GROUP_SUB: {
4444 bluetooth_mesh_model_configure_t req;
4446 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4448 __bt_service_get_parameters(in_param1,
4449 &req, sizeof(bluetooth_mesh_model_configure_t));
4451 result = _bt_mesh_model_configure_group_subscription(
4452 requester_unique_creds, sender, &req);
4454 /* Save invocation */
4455 if (result != BLUETOOTH_ERROR_NONE) {
4456 g_array_append_vals(*out_param1,
4457 &req, sizeof(bluetooth_mesh_model_configure_t));
4459 bluetooth_mesh_model_configure_t *param = \
4460 g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4462 sender = (char*)g_dbus_method_invocation_get_sender(context);
4463 _bt_save_invocation_context(context, result, sender,
4464 function_name, (gpointer)param);
4468 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB: {
4469 bluetooth_mesh_model_configure_t req;
4471 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4473 __bt_service_get_parameters(in_param1,
4474 &req, sizeof(bluetooth_mesh_model_configure_t));
4476 result = _bt_mesh_model_configure_virtual_group_subscription(
4477 requester_unique_creds, sender, &req);
4479 /* Save invocation */
4480 if (result != BLUETOOTH_ERROR_NONE) {
4481 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4483 bluetooth_mesh_model_configure_t *param = \
4484 g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4486 sender = (char*)g_dbus_method_invocation_get_sender(context);
4487 _bt_save_invocation_context(context, result, sender,
4488 function_name, (gpointer)param);
4492 case BT_MESH_MODEL_SET_PUBLICATION: {
4493 bluetooth_mesh_model_configure_t req;
4495 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4497 __bt_service_get_parameters(in_param1,
4498 &req, sizeof(bluetooth_mesh_model_configure_t));
4500 result = _bt_mesh_model_set_publication(
4501 requester_unique_creds, sender, &req);
4503 /* Save invocation */
4504 if (result != BLUETOOTH_ERROR_NONE) {
4505 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4507 bluetooth_mesh_model_configure_t *param = g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4509 sender = (char*)g_dbus_method_invocation_get_sender(context);
4510 _bt_save_invocation_context(context, result, sender,
4511 function_name, (gpointer)param);
4515 case BT_MESH_MODEL_GET_PUBLICATION: {
4516 bluetooth_mesh_model_configure_t req;
4518 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4520 __bt_service_get_parameters(in_param1,
4521 &req, sizeof(bluetooth_mesh_model_configure_t));
4523 result = _bt_mesh_model_get_publication(
4524 requester_unique_creds, sender, &req);
4526 /* Save invocation */
4527 if (result != BLUETOOTH_ERROR_NONE) {
4528 g_array_append_vals(*out_param1,
4529 &req, sizeof(bluetooth_mesh_model_configure_t));
4531 bluetooth_mesh_model_configure_t *param = \
4532 g_memdup2(&req, sizeof(bluetooth_mesh_model_configure_t));
4534 sender = (char*)g_dbus_method_invocation_get_sender(context);
4535 _bt_save_invocation_context(context, result, sender,
4536 function_name, (gpointer)param);
4540 case BT_MESH_NETWORK_GET_GROUPS: {
4541 bluetooth_mesh_network_t network;
4542 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4543 __bt_service_get_parameters(in_param1,
4544 &network, sizeof(bluetooth_mesh_network_t));
4545 BT_INFO("Mesh: Request:: Get Groups");
4546 result = _bt_mesh_network_get_groups(
4547 requester_unique_creds, sender, &network, out_param1);
4550 case BT_L2CAP_LE_CLIENT_CONNECT: {
4551 bluetooth_device_address_t address = { {0} };
4554 __bt_service_get_parameters(in_param1,
4555 &address, sizeof(bluetooth_device_address_t));
4557 __bt_service_get_parameters(in_param2, &psm, sizeof(int));
4559 result = _bt_l2cap_le_connect_using_psm(&address, psm);
4561 if (result != BLUETOOTH_ERROR_NONE) {
4562 bluetooth_l2cap_le_connection_t conn_info;
4564 BT_ERR("BT_L2CAP_LE_CLIENT_CONNECT failed, send error errcode %d", result);
4565 memset(&conn_info, 0x00, sizeof(bluetooth_l2cap_le_connection_t));
4566 conn_info.device_role = L2CAP_LE_ROLE_CLIENT;
4567 conn_info.socket_fd = -1;
4568 conn_info.psm = psm;
4569 memcpy(&conn_info.device_addr, &address, sizeof(bluetooth_device_address_t));
4570 g_array_append_vals(*out_param1, &conn_info,
4571 sizeof(bluetooth_l2cap_le_connection_t));
4573 bluetooth_l2cap_le_connection_t *conn_info;
4575 BT_INFO("BT_L2CAP_LE_CLIENT_CONNECT success, save context");
4576 sender = (char*)g_dbus_method_invocation_get_sender(context);
4577 conn_info = g_malloc0(sizeof(bluetooth_l2cap_le_connection_t));
4578 conn_info->socket_fd = -1;
4579 conn_info->device_role = L2CAP_LE_ROLE_CLIENT;
4580 conn_info->psm = psm;
4582 memcpy(&conn_info->device_addr, &address, sizeof(bluetooth_device_address_t));
4584 _bt_save_invocation_context(context, result, sender, function_name, (gpointer)conn_info);
4588 case BT_L2CAP_LE_SOCKET_DISCONNECT: {
4590 * Bluetooth L2CAP_LE socket disconnection will be done from bt-api, call to bt-service
4591 * is only used for privilege check, so return BLUETOOTH_ERROR_NONE from here.
4593 result = BLUETOOTH_ERROR_NONE;
4596 case BT_L2CAP_LE_SOCKET_WRITE: {
4598 * This call to bt-service is only used for privilege check, so return
4599 * BLUETOOTH_ERROR_NONE from here.
4601 result = BLUETOOTH_ERROR_NONE;
4604 case BT_L2CAP_LE_CREATE_SOCKET: {
4606 * This call to bt-service is only used for privilege check, so return
4607 * BLUETOOTH_ERROR_NONE from here.
4609 result = BLUETOOTH_ERROR_NONE;
4612 case BT_L2CAP_LE_LISTEN_AND_ACCEPT: {
4616 __bt_service_get_parameters(in_param1, &psm, sizeof(int));
4618 socket_fd = _bt_l2cap_le_socket_listen(psm, true);
4619 if (socket_fd > 0) {
4620 result = BLUETOOTH_ERROR_NONE;
4621 sender = (char *)g_dbus_method_invocation_get_sender(context);
4622 _bt_save_invocation_context(context,
4623 result, sender, function_name, NULL);
4625 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
4629 case BT_L2CAP_LE_LISTEN: {
4633 __bt_service_get_parameters(in_param1, &psm, sizeof(int));
4635 socket_fd = _bt_l2cap_le_socket_listen(psm, false);
4636 if (socket_fd > 0) {
4637 result = BLUETOOTH_ERROR_NONE;
4638 sender = (char *)g_dbus_method_invocation_get_sender(context);
4639 _bt_save_invocation_context(context, result,
4640 sender, function_name, NULL);
4642 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
4646 case BT_L2CAP_LE_ACCEPT_CONNECTION: {
4649 address = (char *)g_variant_get_data(in_param1);
4650 result = _bt_socket_reply_conn_authorization(address, TRUE);
4653 case BT_L2CAP_LE_REJECT_CONNECTION: {
4656 address = (char *)g_variant_get_data(in_param1);
4657 result = _bt_socket_reply_conn_authorization(address, FALSE);
4660 case BT_L2CAP_LE_REMOVE_SOCKET: {
4662 * This call to bt-service is only used for privilege check, so return
4663 * BLUETOOTH_ERROR_NONE from here.
4665 result = BLUETOOTH_ERROR_NONE;
4669 BT_INFO("UnSupported function [%d]", function_name);
4670 result = BLUETOOTH_ERROR_NOT_SUPPORT;
4676 #ifdef TIZEN_FEATURE_BT_OBEX
4677 /* Function definitions*/
4678 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
4683 size = g_variant_get_size(var);
4685 data = (char *)g_variant_get_data(var);
4687 param = g_array_append_vals(param, data, size);
4693 int __bt_obexd_request(int function_name,
4696 GDBusMethodInvocation *context,
4697 GVariant *in_param1,
4698 GVariant *in_param2,
4699 GVariant *in_param3,
4700 GVariant *in_param4,
4701 GArray **out_param1)
4705 int result = BLUETOOTH_ERROR_NONE;
4707 BT_DBG("function_name : %x", function_name);
4709 switch (function_name) {
4710 case BT_OPP_PUSH_FILES: {
4711 BT_DBG("BT_OPP_PUSH_FILES");
4713 bluetooth_device_address_t address = { {0} };
4714 bt_file_path_t *path;
4719 __bt_service_get_parameters(in_param1, &address,
4720 sizeof(bluetooth_device_address_t));
4721 __bt_service_get_parameters(in_param3, &file_count,
4724 file_path = g_new0(char *, file_count + 1);
4726 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
4727 __bt_fill_garray_from_variant(in_param2, param2);
4729 for (i = 0; i < file_count; i++) {
4730 path = &g_array_index(param2, bt_file_path_t, i);
4731 file_path[i] = g_strdup(path->path);
4733 BT_DBG("_bt_opp_client_push_files");
4734 result = _bt_opp_client_push_files(request_id, context,
4735 &address, file_path,
4738 for (i = 0; i < file_count; i++)
4739 g_free(file_path[i]);
4742 g_array_free(param2, TRUE);
4746 case BT_OPP_CANCEL_PUSH: {
4747 result = _bt_opp_client_cancel_push();
4751 case BT_OPP_IS_PUSHING_FILES: {
4752 gboolean is_sending = FALSE;
4754 result = _bt_opp_client_is_sending(&is_sending);
4756 g_array_append_vals(*out_param1, &is_sending,
4760 case BT_OPP_GET_TRANSFER_PROGRESS: {
4763 guint8 progress = 0;
4765 __bt_service_get_parameters(in_param1, &direction,
4767 __bt_service_get_parameters(in_param2, &transfer_id,
4770 result = _bt_opp_get_client_progress(&progress);
4772 result = _bt_opp_get_server_progress(transfer_id, &progress);
4774 g_array_append_vals(*out_param1, &progress,
4780 case BT_MAP_CREATE_SESSION: {
4781 BT_DBG("BT_MAP_CREATE_SESSION");
4782 char *address = (char *)g_variant_get_data(in_param1);
4783 char *session_id = NULL;
4784 result = _bt_create_session_sync(address, &session_id);
4785 if (result == BLUETOOTH_ERROR_NONE)
4786 g_array_append_vals(*out_param1, session_id, strlen(session_id)+1);
4790 case BT_MAP_DESTROY_SESSION: {
4791 BT_DBG("BT_MAP_DESTROY_SESSION");
4792 char* session_id = (char *)g_variant_get_data(in_param1);
4793 result = _bt_destroy_session_sync(session_id);
4794 if (result == BLUETOOTH_ERROR_NONE)
4795 BT_DBG("successfully destroyed session");
4799 case BT_MAP_SET_FOLDER: {
4800 BT_DBG("BT_MAP_SET_FOLDER");
4801 char *session_id = (char *)g_variant_get_data(in_param1);
4802 char *name = (char *)g_variant_get_data(in_param2);
4803 result = _bt_map_client_set_folder(session_id, name);
4807 case BT_MAP_LIST_FOLDERS: {
4808 BT_DBG("BT_MAP_LIST_FOLDERS");
4810 char* session_id = (char *)g_variant_get_data(in_param1);
4811 char* filter_serialized = (char*)g_variant_get_data(in_param2);
4813 result = _bt_map_client_list_folders(request_id, context, session_id, filter_serialized);
4814 if (result == BLUETOOTH_ERROR_NONE)
4815 BT_DBG("_bt_map_client_list_folders succeed");
4820 case BT_MAP_LIST_FILTER_FIELDS: {
4821 BT_DBG("BT_MAP_LIST_FILTER_FIELDS");
4823 char* session_id = (char *)g_variant_get_data(in_param1);
4825 result = _bt_map_client_list_filter_fields(request_id, context, session_id);
4826 if (result == BLUETOOTH_ERROR_NONE)
4827 BT_DBG("_bt_map_client_list_filter_fields succeed");
4832 case BT_MAP_LIST_MESSAGES: {
4833 BT_DBG("BT_MAP_LIST_MESSAGES");
4835 char* session_id = (char*)g_variant_get_data(in_param1);
4836 char* folder = (char*)g_variant_get_data(in_param2);
4837 char* filter_serialized = (char*)g_variant_get_data(in_param3);
4839 result = _bt_map_client_list_messages(request_id, context, session_id, folder, filter_serialized);
4840 if (result == BLUETOOTH_ERROR_NONE)
4841 BT_DBG("_bt_map_client_list_messages succeed");
4843 BT_DBG("_bt_map_client_list_messages failed");
4848 case BT_MAP_UPDATE_INBOX: {
4849 BT_DBG("BT_MAP_UPDATE_INBOX");
4850 char* session_id = (char *)g_variant_get_data(in_param1);
4851 result = _bt_map_client_update_inbox(session_id);
4855 case BT_MAP_PUSH_MESSAGE: {
4856 BT_DBG("BT_MAP_PUSH_MESSAGE");
4858 char* session_id = (char *)g_variant_get_data(in_param1);
4859 char* source_file = (char *)g_variant_get_data(in_param2);
4860 char* folder = (char *)g_variant_get_data(in_param3);
4861 char* args_serialized = (char *)g_variant_get_data(in_param4);
4863 result = _bt_map_client_push_message(
4864 request_id, context, session_id, source_file, folder, args_serialized);
4865 if (result == BLUETOOTH_ERROR_NONE)
4866 BT_DBG("_bt_map_client_push_message succeed");
4868 BT_ERR("_bt_map_client_push_message failed");
4873 case BT_MAP_GET_MESSAGE: {
4874 BT_DBG("BT_MAP_GET_MESSAGE");
4875 // TODO session currently is not used, but should be valid
4876 //char* session_id = (char *)g_variant_get_data(in_param1);
4877 char* message_object = (char *)g_variant_get_data(in_param2);
4878 char* target_file = (char *)g_variant_get_data(in_param3);
4879 bool attachment = false;
4880 __bt_service_get_parameters(in_param4, &attachment, sizeof(bool));
4882 result = _bt_map_client_get_message(request_id, context, message_object,
4883 target_file, attachment);
4884 if (result == BLUETOOTH_ERROR_NONE)
4885 BT_DBG("_bt_map_client_get_message succeed");
4890 case BT_OBEX_SERVER_ALLOCATE: {
4896 sender = (char *)g_dbus_method_invocation_get_sender(context);
4898 path = (char *)g_variant_get_data(in_param1);
4899 __bt_service_get_parameters(in_param2, &is_native,
4901 __bt_service_get_parameters(in_param3, &app_pid,
4904 result = _bt_obex_server_allocate(sender,
4905 path, app_pid, is_native);
4909 case BT_OBEX_SERVER_DEALLOCATE: {
4913 __bt_service_get_parameters(in_param1, &is_native,
4915 __bt_service_get_parameters(in_param2, &app_pid,
4918 result = _bt_obex_server_deallocate(app_pid, is_native);
4921 case BT_OBEX_SERVER_IS_ACTIVATED: {
4922 gboolean is_activated = FALSE;
4924 result = _bt_obex_server_is_activated(&is_activated);
4926 g_array_append_vals(*out_param1, &is_activated,
4931 case BT_OBEX_SERVER_ACCEPT_CONNECTION: {
4932 result = _bt_obex_server_accept_connection(request_id);
4936 case BT_OBEX_SERVER_REJECT_CONNECTION: {
4937 result = _bt_obex_server_reject_connection();
4941 case BT_OBEX_SERVER_ACCEPT_FILE: {
4944 file_name = (char *)g_variant_get_data(in_param1);
4946 result = _bt_obex_server_accept_authorize(file_name, TRUE);
4950 case BT_OBEX_SERVER_REJECT_FILE: {
4951 result = _bt_obex_server_reject_authorize();
4955 case BT_OBEX_SERVER_SET_PATH: {
4957 char *destination_path;
4959 destination_path = (char *)g_variant_get_data(in_param1);
4960 __bt_service_get_parameters(in_param2, &is_native,
4963 result = _bt_obex_server_set_destination_path(destination_path,
4968 case BT_OBEX_SERVER_SET_ROOT: {
4971 root = (char *)g_variant_get_data(in_param1);
4973 result = _bt_obex_server_set_root(root);
4977 case BT_OBEX_SERVER_CANCEL_TRANSFER: {
4980 __bt_service_get_parameters(in_param1, &transfer_id,
4983 result = _bt_obex_server_cancel_transfer(transfer_id);
4987 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS: {
4988 result = _bt_obex_server_cancel_all_transfers();
4992 case BT_OBEX_SERVER_IS_RECEIVING: {
4993 gboolean is_receiving = FALSE;
4995 result = _bt_obex_server_is_receiving(&is_receiving);
4997 g_array_append_vals(*out_param1, &is_receiving,
5001 case BT_PBAP_CONNECT: {
5002 bluetooth_device_address_t address = { {0} };
5004 __bt_service_get_parameters(in_param1, &address,
5005 sizeof(bluetooth_device_address_t));
5007 result = _bt_pbap_connect(&address);
5010 case BT_PBAP_DISCONNECT: {
5011 bluetooth_device_address_t address = { {0} };
5013 __bt_service_get_parameters(in_param1, &address,
5014 sizeof(bluetooth_device_address_t));
5016 result = _bt_pbap_disconnect(&address);
5019 case BT_PBAP_GET_PHONEBOOK_SIZE: {
5020 bluetooth_device_address_t address = { {0} };
5021 bt_pbap_folder_t folder = { 0, };
5023 __bt_service_get_parameters(in_param1, &address,
5024 sizeof(bluetooth_device_address_t));
5025 __bt_service_get_parameters(in_param2, &folder,
5026 sizeof(bt_pbap_folder_t));
5028 result = _bt_pbap_get_phonebook_size(&address,
5029 folder.addressbook, folder.folder_type);
5032 case BT_PBAP_GET_PHONEBOOK: {
5033 bluetooth_device_address_t address = { {0} };
5034 bt_pbap_folder_t folder = { 0, };
5035 bt_pbap_pull_parameters_t app_param = { 0, };
5037 __bt_service_get_parameters(in_param1, &address,
5038 sizeof(bluetooth_device_address_t));
5039 __bt_service_get_parameters(in_param2, &folder,
5040 sizeof(bt_pbap_folder_t));
5041 __bt_service_get_parameters(in_param3, &app_param,
5042 sizeof(bt_pbap_pull_parameters_t));
5044 result = _bt_pbap_get_phonebook(&address, folder.addressbook,
5045 folder.folder_type, &app_param);
5048 case BT_PBAP_GET_LIST: {
5049 bluetooth_device_address_t address = { {0} };
5050 bt_pbap_folder_t folder = { 0, };
5051 bt_pbap_list_parameters_t app_param = { 0, };
5053 __bt_service_get_parameters(in_param1, &address,
5054 sizeof(bluetooth_device_address_t));
5055 __bt_service_get_parameters(in_param2, &folder,
5056 sizeof(bt_pbap_folder_t));
5057 __bt_service_get_parameters(in_param3, &app_param,
5058 sizeof(bt_pbap_list_parameters_t));
5060 result = _bt_pbap_get_list(&address, folder.addressbook,
5061 folder.folder_type, &app_param);
5064 case BT_PBAP_PULL_VCARD: {
5065 bluetooth_device_address_t address = { {0} };
5066 bt_pbap_folder_t folder = { 0, };
5067 bt_pbap_pull_vcard_parameters_t app_param = { 0, };
5069 __bt_service_get_parameters(in_param1, &address,
5070 sizeof(bluetooth_device_address_t));
5071 __bt_service_get_parameters(in_param2, &folder,
5072 sizeof(bt_pbap_folder_t));
5073 __bt_service_get_parameters(in_param3, &app_param,
5074 sizeof(bt_pbap_pull_vcard_parameters_t));
5076 result = _bt_pbap_pull_vcard(&address, folder.addressbook,
5077 folder.folder_type, &app_param);
5080 case BT_PBAP_PHONEBOOK_SEARCH: {
5081 bluetooth_device_address_t address = { {0} };
5082 bt_pbap_folder_t folder = { 0, };
5083 bt_pbap_search_parameters_t app_param = { 0, };
5085 __bt_service_get_parameters(in_param1, &address,
5086 sizeof(bluetooth_device_address_t));
5087 __bt_service_get_parameters(in_param2, &folder,
5088 sizeof(bt_pbap_folder_t));
5089 __bt_service_get_parameters(in_param3, &app_param,
5090 sizeof(bt_pbap_search_parameters_t));
5092 result = _bt_pbap_phonebook_search(&address, folder.addressbook,
5093 folder.folder_type, &app_param);
5098 BT_ERR("Unknown function!");
5099 result = BLUETOOTH_ERROR_INTERNAL;
5108 int __bt_agent_request(int function_name,
5111 GDBusMethodInvocation *context,
5112 GVariant *in_param1,
5113 GVariant *in_param2,
5114 GVariant *in_param3,
5115 GVariant *in_param4,
5116 GArray **out_param1)
5119 switch (function_name) {
5120 case BT_SET_AUTHORIZATION: {
5127 sender = (char *)g_dbus_method_invocation_get_sender(context);
5128 __bt_service_get_parameters(in_param1, &type, sizeof(int));
5129 uuid = (char *)g_variant_get_data(in_param2);
5130 path = (char *)g_variant_get_data(in_param3);
5131 __bt_service_get_parameters(in_param4, &fd, sizeof(int));
5133 result = _bt_register_osp_server_in_agent(sender, type, uuid, path, fd);
5136 case BT_UNSET_AUTHORIZATION: {
5140 __bt_service_get_parameters(in_param1, &type, sizeof(int));
5141 uuid = (char *)g_variant_get_data(in_param2);
5143 result = _bt_unregister_osp_server_in_agent(type, uuid);
5147 BT_ERR("Unknown function!");
5148 result = BLUETOOTH_ERROR_INTERNAL;
5155 int __bt_core_request(int function_name,
5158 GDBusMethodInvocation *context,
5159 GVariant *in_param1)
5163 switch (function_name) {
5164 case BT_ENABLE_ADAPTER:
5167 _bt_set_adapter_request_state(TRUE);
5168 status = _bt_adapter_get_status();
5170 if (status == BT_ACTIVATING) {
5171 BT_DBG("Enabling in progress");
5172 result = BLUETOOTH_ERROR_IN_PROGRESS;
5173 } else if (status == BT_ACTIVATED) {
5174 BT_DBG("Already enabled");
5175 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
5177 _bt_adapter_set_status(BT_ACTIVATING);
5178 result = BLUETOOTH_ERROR_NONE;
5183 case BT_DISABLE_ADAPTER:
5187 status = _bt_adapter_get_status();
5188 if (status == BT_DEACTIVATING) {
5189 BT_DBG("Disabling in progress");
5190 result = BLUETOOTH_ERROR_IN_PROGRESS;
5191 } else if (status == BT_DEACTIVATED) {
5192 BT_DBG("Already disabled");
5193 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
5195 _bt_adapter_set_status(BT_DEACTIVATING);
5196 result = BLUETOOTH_ERROR_NONE;
5201 case BT_ENABLE_ADAPTER_LE:
5203 bt_le_status_t le_status;
5204 _bt_set_le_request_state(TRUE);
5205 le_status = _bt_adapter_get_le_status();
5206 if (le_status == BT_LE_ACTIVATING) {
5207 BT_DBG("Enabling in progress");
5208 result = BLUETOOTH_ERROR_IN_PROGRESS;
5209 } else if (le_status == BT_LE_ACTIVATED) {
5210 BT_DBG("Already enabled");
5211 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
5213 _bt_adapter_set_le_status(BT_LE_ACTIVATING);
5214 result = BLUETOOTH_ERROR_NONE;
5219 case BT_DISABLE_ADAPTER_LE:
5221 bt_le_status_t le_status;
5223 le_status = _bt_adapter_get_le_status();
5224 if (le_status == BT_LE_DEACTIVATING) {
5225 BT_DBG("Disabling in progress");
5226 result = BLUETOOTH_ERROR_IN_PROGRESS;
5227 } else if (le_status == BT_LE_DEACTIVATED) {
5228 BT_DBG("Already disabled");
5229 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
5231 _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
5232 result = BLUETOOTH_ERROR_NONE;
5238 BT_ERR("Unknown function!");
5239 result = BLUETOOTH_ERROR_INTERNAL;
5246 static int __bt_service_get_requester_app_id(const char *unique_name, char *app_id, int len)
5251 retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
5252 retv_if(unique_name == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
5254 ret = __bt_service_get_sender_pid(unique_name, &pid);
5255 if (ret != BLUETOOTH_ERROR_NONE) {
5256 BT_ERR("Fail to get the sender pid");
5260 ret = aul_app_get_appid_bypid(pid, app_id, len);
5261 if (ret != AUL_R_OK) {
5262 BT_ERR("app_id not found");
5263 return BLUETOOTH_ERROR_NOT_SUPPORT;
5265 BT_DBG("Sender app_id: %s", app_id);
5267 return BLUETOOTH_ERROR_NONE;
5270 #ifdef TIZEN_FEATURE_BT_CONTAINER
5271 static void __bt_service_free_nspid(struct nspid_t *nspid)
5273 g_free(nspid->unique_name);
5277 static void __bt_service_cleanup_nspid_list(const char *unique_name)
5280 struct nspid_t *nspid;
5282 ret_if(unique_name == NULL);
5284 for (l = nspid_list; l; l = g_slist_next(l)) {
5288 if (!g_strcmp0(nspid->unique_name, unique_name)) {
5289 nspid_list = g_slist_remove(nspid_list, nspid);
5290 __bt_service_free_nspid(nspid);
5296 static gboolean __bt_service_is_container_request(const char *unique_name)
5300 char path[1024], buf[1024];
5302 gboolean is_container = FALSE;
5304 struct nspid_t *nspid;
5306 for (l = nspid_list; l; l = g_slist_next(l)) {
5310 if (!g_strcmp0(nspid->unique_name, unique_name))
5311 return nspid->is_container;
5314 ret = __bt_service_get_sender_pid(unique_name, &pid);
5315 if (ret != BLUETOOTH_ERROR_NONE)
5318 sprintf(path, "/proc/%d/status", pid);
5319 fp = fopen(path, "r");
5321 BT_ERR("fopen() failed. %d(%s)", errno, strerror(errno));
5325 while (fgets(buf, sizeof(buf), fp)) {
5326 if (strstr(buf, "NSpid:")) {
5327 char *p = strchr(buf + 7, '\t'); /* find 2nd '\t' */
5329 BT_DBG("caller is container process");
5330 is_container = TRUE;
5338 nspid = g_malloc0(sizeof(struct nspid_t));
5339 nspid->unique_name = g_strdup(unique_name);
5340 nspid->is_container = is_container;
5341 nspid_list = g_slist_append(nspid_list, nspid);
5343 return is_container;
5347 #ifdef TIZEN_FEATURE_BT_CONTAINER
5348 static gboolean __bt_service_check_privilege_in_container(int function_name,
5349 const char *unique_name)
5351 int result = BLUETOOTH_ERROR_NONE;
5352 GError *error = NULL;
5354 GArray *in_param1, *in_param2, *in_param3, *in_param4, *in_param5;
5355 GVariant *param1, *param2, *param3, *param4, *param5, *out_param;
5357 proxy = _bt_get_container_proxy();
5358 if (proxy == NULL) {
5359 BT_ERR("container proxy is NULL");
5363 in_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
5364 in_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
5365 in_param3 = g_array_new(TRUE, TRUE, sizeof(gchar));
5366 in_param4 = g_array_new(TRUE, TRUE, sizeof(gchar));
5367 in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
5369 /* The sender's privilege should be checked not bt-service in container */
5370 g_array_append_vals(in_param1, unique_name, strlen(unique_name));
5372 param1 = g_variant_new_from_data((const GVariantType *)"ay",
5373 in_param1->data, in_param1->len, TRUE, NULL, NULL);
5374 param2 = g_variant_new_from_data((const GVariantType *)"ay",
5375 in_param2->data, in_param2->len, TRUE, NULL, NULL);
5376 param3 = g_variant_new_from_data((const GVariantType *)"ay",
5377 in_param3->data, in_param3->len, TRUE, NULL, NULL);
5378 param4 = g_variant_new_from_data((const GVariantType *)"ay",
5379 in_param4->data, in_param4->len, TRUE, NULL, NULL);
5380 param5 = g_variant_new_from_data((const GVariantType *)"ay",
5381 in_param5->data, in_param5->len, TRUE, NULL, NULL);
5383 BT_DBG("This request is from container. Privilege will be checked in container. unique_name: %s", unique_name);
5385 GVariant *ret = g_dbus_proxy_call_sync(proxy, "service_request",
5386 g_variant_new("(iii@ay@ay@ay@ay@ay)",
5387 BT_CHECK_PRIVILEGE, function_name,
5388 BT_SYNC_REQ, param1, param2,
5389 param3, param4, param5),
5390 G_DBUS_CALL_FLAGS_NONE, -1,
5393 BT_ERR("dBUS-RPC is failed");
5395 if (error != NULL) {
5396 BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
5397 error->code, error->message);
5398 g_clear_error(&error);
5400 BT_ERR("error returned was NULL");
5403 result = BLUETOOTH_ERROR_INTERNAL;
5405 g_variant_get(ret, "(iv)", &result, &out_param);
5406 g_variant_unref(out_param);
5407 g_variant_unref(ret);
5410 g_array_free(in_param1, TRUE);
5411 g_array_free(in_param2, TRUE);
5412 g_array_free(in_param3, TRUE);
5413 g_array_free(in_param4, TRUE);
5414 g_array_free(in_param5, TRUE);
5416 return (result == BLUETOOTH_ERROR_NONE) ? TRUE : FALSE;
5420 gboolean __bt_service_check_privilege(int function_name,
5422 const char *unique_name)
5425 gboolean result = TRUE;
5426 char *client_creds = NULL;
5427 char *user_creds = NULL;
5428 char *client_session = "";
5429 enum cynara_client_creds client_creds_method = CLIENT_METHOD_SMACK;
5430 enum cynara_user_creds user_creds_method = USER_METHOD_UID;
5431 char err_msg[256] = {0, };
5433 retv_if(unique_name == NULL, FALSE);
5434 retv_if(bt_service_conn == NULL, FALSE);
5436 #ifdef TIZEN_FEATURE_BT_CONTAINER
5437 if (_bt_service_is_container() == FALSE)
5438 if (__bt_service_is_container_request(unique_name) == TRUE)
5439 return __bt_service_check_privilege_in_container(function_name, unique_name);
5442 ret_val = cynara_creds_get_default_client_method(&client_creds_method);
5443 if (ret_val != CYNARA_API_SUCCESS) {
5444 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5445 BT_ERR("Fail to get default client method: %s", err_msg);
5449 ret_val = cynara_creds_get_default_user_method(&user_creds_method);
5450 if (ret_val != CYNARA_API_SUCCESS) {
5451 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5452 BT_ERR("Fail to get default user method: %s", err_msg);
5456 ret_val = cynara_creds_gdbus_get_client(bt_service_conn, unique_name, client_creds_method, &client_creds);
5457 if (ret_val != CYNARA_API_SUCCESS) {
5458 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5459 BT_ERR("Fail to get client credential: %s", err_msg);
5463 ret_val = cynara_creds_gdbus_get_user(bt_service_conn, unique_name, user_creds_method, &user_creds);
5464 if (ret_val != CYNARA_API_SUCCESS) {
5465 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5466 BT_ERR("Fail to get user credential: %s", err_msg);
5472 BT_DBG("%s, %s, %s", unique_name, client_creds, user_creds);
5474 switch (function_name) {
5475 case BT_SET_LOCAL_NAME:
5476 case BT_START_DISCOVERY:
5477 case BT_START_CUSTOM_DISCOVERY:
5478 case BT_CANCEL_DISCOVERY:
5479 case BT_OOB_ADD_REMOTE_DATA:
5480 case BT_OOB_REMOVE_REMOTE_DATA:
5481 case BT_OOB_READ_LOCAL_DATA:
5482 case BT_SET_ADVERTISING:
5483 case BT_SET_CUSTOM_ADVERTISING:
5484 case BT_SET_ADVERTISING_PARAMETERS:
5485 case BT_START_LE_DISCOVERY:
5486 case BT_STOP_LE_DISCOVERY:
5487 case BT_SET_SCAN_PARAMETERS:
5488 case BT_SET_SCAN_TYPE:
5489 case BT_UPDATE_LE_CONNECTION_MODE:
5491 case BT_BOND_DEVICE:
5492 case BT_CANCEL_BONDING:
5493 case BT_UNBOND_DEVICE:
5495 case BT_SET_AUTHORIZATION:
5496 case BT_UNSET_AUTHORIZATION:
5497 case BT_SEARCH_SERVICE:
5499 case BT_RFCOMM_CLIENT_CONNECT:
5500 if (function_name == BT_RFCOMM_CLIENT_CONNECT)
5501 BT_PERMANENT_LOG("Connect socket");
5502 case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
5503 case BT_RFCOMM_SOCKET_DISCONNECT:
5504 if (function_name == BT_RFCOMM_SOCKET_DISCONNECT)
5505 BT_PERMANENT_LOG("Disconnect socket");
5506 case BT_RFCOMM_SOCKET_WRITE:
5507 case BT_RFCOMM_CREATE_SOCKET:
5508 case BT_RFCOMM_REMOVE_SOCKET:
5509 case BT_RFCOMM_SEND_RX_DETAILS:
5510 case BT_RFCOMM_SEND_TX_DETAILS:
5511 case BT_RFCOMM_UPDATE_CONNECTION_INFO:
5513 case BT_OPP_PUSH_FILES:
5514 case BT_OPP_CANCEL_PUSH:
5515 /* TODO: MAP? MAP functions, see above */
5517 case BT_OBEX_SERVER_ACCEPT_CONNECTION:
5518 case BT_OBEX_SERVER_REJECT_CONNECTION:
5519 case BT_OBEX_SERVER_ACCEPT_FILE:
5520 case BT_OBEX_SERVER_REJECT_FILE:
5521 case BT_OBEX_SERVER_SET_PATH:
5522 case BT_OBEX_SERVER_SET_ROOT:
5523 case BT_OBEX_SERVER_CANCEL_TRANSFER:
5524 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS:
5526 case BT_AUDIO_SELECT_ROLE:
5527 case BT_AUDIO_CONNECT:
5528 case BT_AUDIO_DISCONNECT:
5530 case BT_AG_DISCONNECT:
5532 case BT_AV_DISCONNECT:
5533 case BT_AV_SOURCE_CONNECT:
5534 case BT_AV_SOURCE_DISCONNECT:
5535 case BT_AVRCP_TARGET_CONNECT:
5536 case BT_AVRCP_TARGET_DISCONNECT:
5537 case BT_AVRCP_CONTROL_CONNECT:
5538 case BT_AVRCP_CONTROL_DISCONNECT:
5539 case BT_AVRCP_HANDLE_CONTROL:
5540 case BT_AVRCP_SET_TRACK_INFO:
5541 case BT_AVRCP_SET_PROPERTY:
5542 case BT_AVRCP_SET_PROPERTIES:
5543 case BT_AVRCP_CONTROL_SET_PROPERTY:
5545 case BT_AUDIO_SET_ABSOLUTE_VOLUME:
5546 case BT_AUDIO_GET_ABSOLUTE_VOLUME:
5547 case BT_AUDIO_IS_AVC_ACTIVATED:
5550 case BT_HF_DISCONNECT:
5552 case BT_HID_CONNECT:
5553 case BT_HID_DISCONNECT:
5555 case BT_HID_DEVICE_ACTIVATE:
5556 case BT_HID_DEVICE_DEACTIVATE:
5557 case BT_HID_DEVICE_CONNECT:
5558 case BT_HID_DEVICE_DISCONNECT:
5559 case BT_HID_DEVICE_SEND_MOUSE_EVENT:
5560 case BT_HID_DEVICE_SEND_KEY_EVENT:
5561 case BT_HID_DEVICE_SEND_REPLY_TO_REPORT:
5562 case BT_HID_DEVICE_SEND_CUSTOM_EVENT:
5565 case BT_DISCONNECT_LE:
5567 case BT_SET_ADVERTISING_DATA:
5568 case BT_SET_SCAN_RESPONSE_DATA:
5570 case BT_HDP_CONNECT:
5571 case BT_HDP_DISCONNECT:
5572 case BT_HDP_SEND_DATA:
5573 case BT_HDP_REGISTER_SINK_APP:
5574 case BT_HDP_UNREGISTER_SINK_APP:
5577 case BT_DPM_SET_ALLOW_BT_MODE:
5578 case BT_DPM_GET_ALLOW_BT_MODE:
5579 case BT_DPM_SET_DEVICE_RESTRITION:
5580 case BT_DPM_GET_DEVICE_RESTRITION:
5581 case BT_DPM_SET_UUID_RESTRITION:
5582 case BT_DPM_GET_UUID_RESTRITION:
5583 case BT_DPM_ADD_DEVICES_BLOCKLIST:
5584 case BT_DPM_ADD_DEVICES_ALLOWLIST:
5585 case BT_DPM_ADD_UUIDS_BLOCKLIST:
5586 case BT_DPM_ADD_UUIDS_ALLOWLIST:
5587 case BT_DPM_CLEAR_DEVICES_BLOCKLIST:
5588 case BT_DPM_CLEAR_DEVICES_ALLOWLIST:
5589 case BT_DPM_CLEAR_UUIDS_BLOCKLIST:
5590 case BT_DPM_CLEAR_UUIDS_ALLOWLIST:
5591 case BT_DPM_REMOVE_DEVICE_BLOCKLIST:
5592 case BT_DPM_REMOVE_DEVICE_ALLOWLIST:
5593 case BT_DPM_REMOVE_UUID_BLOCKLIST:
5594 case BT_DPM_REMOVE_UUID_ALLOWLIST:
5595 case BT_DPM_GET_DEVICES_BLOCKLIST:
5596 case BT_DPM_GET_DEVICES_ALLOWLIST:
5597 case BT_DPM_GET_UUIDS_BLOCKLIST:
5598 case BT_DPM_GET_UUIDS_ALLOWLIST:
5599 case BT_DPM_SET_ALLOW_OUTGOING_CALL:
5600 case BT_DPM_GET_ALLOW_OUTGOING_CALL:
5601 case BT_DPM_SET_PAIRING_STATE:
5602 case BT_DPM_GET_PAIRING_STATE:
5603 case BT_DPM_SET_PROFILE_STATE:
5604 case BT_DPM_GET_PROFILE_STATE:
5605 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE:
5606 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE:
5607 case BT_DPM_SET_DISCOVERABLE_STATE:
5608 case BT_DPM_GET_DISCOVERABLE_STATE:
5609 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE:
5610 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE:
5611 case BT_DPM_SET_DATA_TRANSFER_STATE:
5612 case BT_DPM_GET_DATA_TRANSFER_STATE:
5614 case BT_NETWORK_ACTIVATE:
5615 case BT_NETWORK_DEACTIVATE:
5616 case BT_NETWORK_CONNECT:
5617 case BT_NETWORK_DISCONNECT:
5618 case BT_NETWORK_SERVER_DISCONNECT:
5620 case BT_GATT_GET_PRIMARY_SERVICES:
5621 case BT_GATT_GET_SERVICE_PROPERTIES: /* GATT Client */
5622 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: /* GATT Client */
5623 case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: /* GATT Client */
5624 case BT_GATT_DISCOVER_CHARACTERISTICS:
5625 case BT_GATT_SET_PROPERTY_REQUEST:
5626 case BT_GATT_READ_CHARACTERISTIC:
5627 case BT_GATT_READ_DESCRIPTOR_VALUE: /* GATT Client */
5628 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: /* GATT Client */
5629 case BT_GATT_ACQUIRE_WRITE:
5630 case BT_GATT_WRITE_DESCRIPTOR_VALUE: /* GATT Client */
5631 case BT_GATT_WATCH_CHARACTERISTIC: /* GATT Client */
5632 case BT_GATT_CLIENT_REGISTER: /* GATT Client */
5633 case BT_GATT_CLIENT_UNREGISTER: /* GATT Client */
5634 case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
5635 case BT_GATT_REGISTER_APPLICATION:
5636 case BT_GATT_REGISTER_SERVICE:
5637 case BT_GATT_SEND_RESPONSE:
5639 case BT_GATT_SERVER_REGISTER:
5640 case BT_GATT_SERVER_ADD_SERVICE:
5641 case BT_GATT_SERVER_ADD_CHARACTERISTIC:
5642 case BT_GATT_SERVER_ADD_DESCRIPTOR:
5643 case BT_GATT_SERVER_START_SERVICE:
5644 case BT_GATT_SERVER_STOP_SERVICE:
5645 case BT_GATT_SERVER_DELETE_SERVICE:
5646 case BT_GATT_SERVER_SET_SERVICE_PERSISTENCE:
5647 case BT_GATT_SERVER_UNSET_SERVICE_PERSISTENCE:
5648 case BT_GATT_SERVER_SEND_RESPONSE:
5649 case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE:
5650 case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE:
5651 case BT_GATT_SERVER_SEND_INDICATION:
5652 case BT_GATT_SERVER_UPDATE_VALUE:
5653 case BT_GATT_SERVER_DEREGISTER:
5655 case BT_GATT_SERVER_READ_PHY:
5656 case BT_GATT_SERVER_SET_PHY:
5657 case BT_GATT_CLIENT_READ_PHY:
5658 case BT_GATT_CLIENT_SET_PHY:
5659 case BT_REQ_ATT_MTU:
5660 case BT_PBAP_CONNECT:
5661 case BT_PBAP_DISCONNECT:
5662 case BT_PBAP_GET_PHONEBOOK_SIZE:
5663 case BT_PBAP_GET_PHONEBOOK:
5664 case BT_PBAP_GET_LIST:
5665 case BT_PBAP_PULL_VCARD:
5666 case BT_PBAP_PHONEBOOK_SEARCH:
5668 case BT_RFCOMM_LISTEN_AND_ACCEPT:
5670 case BT_L2CAP_LE_CLIENT_CONNECT:
5671 case BT_L2CAP_LE_CLIENT_CANCEL_CONNECT:
5672 case BT_L2CAP_LE_SOCKET_DISCONNECT:
5673 case BT_L2CAP_LE_SOCKET_WRITE:
5674 case BT_L2CAP_LE_CREATE_SOCKET:
5675 case BT_L2CAP_LE_REMOVE_SOCKET:
5676 case BT_L2CAP_LE_LISTEN_AND_ACCEPT:
5677 case BT_L2CAP_LE_ACCEPT_CONNECTION:
5678 case BT_L2CAP_LE_REJECT_CONNECTION:
5679 case BT_L2CAP_LE_LISTEN:
5681 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5682 BT_PRIVILEGE_PUBLIC);
5684 BT_INFO("Client Credentials [%s]", client_creds);
5685 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5686 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PUBLIC);
5690 /* Need to check mediastorage privilege */
5691 if (function_name == BT_PBAP_GET_PHONEBOOK ||
5692 function_name == BT_PBAP_PULL_VCARD) {
5693 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5694 MEDIASTORAGE_PRIVILEGE);
5696 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5697 BT_ERR("Fail to access: %s", MEDIASTORAGE_PRIVILEGE);
5703 case BT_ENABLE_ADAPTER:
5704 case BT_DISABLE_ADAPTER:
5705 case BT_RESET_ADAPTER:
5706 case BT_RECOVER_ADAPTER:
5707 case BT_BATTERY_READ_DATA:
5708 case BT_ENABLE_ADAPTER_LE:
5709 case BT_DISABLE_ADAPTER_LE:
5710 case BT_SET_CONNECTABLE:
5711 case BT_SET_DISCOVERABLE_MODE:
5712 case BT_ADD_ALLOW_LIST:
5713 case BT_REMOVE_ALLOW_LIST:
5714 case BT_CLEAR_ALLOW_LIST:
5715 case BT_SET_MANUFACTURER_DATA:
5717 case BT_CANCEL_SEARCH_SERVICE:
5718 case BT_ENABLE_RSSI:
5719 case BT_DISCONNECT_DEVICE:
5721 case BT_RFCOMM_ACCEPT_CONNECTION:
5722 case BT_RFCOMM_REJECT_CONNECTION:
5723 case BT_RFCOMM_LISTEN:
5725 case BT_HID_ENABLE_BARCODE_FEATURE:
5727 case BT_AVRCP_TRANSPORT_SET_PROPERTY:
5728 case BT_AVRCP_HANDLE_CONTROL_TO_DEST:
5730 case BT_SET_CONTENT_PROTECT:
5731 case BT_BOND_DEVICE_BY_TYPE:
5732 case BT_SET_LE_PRIVACY:
5733 case BT_SET_LE_STATIC_RANDOM_ADDRESS:
5734 case BT_LE_CONN_UPDATE:
5735 case BT_GET_DEVICE_IDA:
5736 case BT_LE_READ_MAXIMUM_DATA_LENGTH:
5737 case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH:
5738 case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH:
5739 case BT_LE_SET_DATA_LENGTH:
5740 case BT_LE_OOB_READ_LOCAL_DATA:
5741 case BT_LE_OOB_ADD_REMOTE_DATA:
5743 case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS:
5744 case BT_ENABLE_GATT_DATA_BATCHING:
5745 case BT_DISABLE_GATT_DATA_BATCHING:
5747 case BT_LE_IPSP_INIT:
5748 case BT_LE_IPSP_DEINIT:
5749 case BT_LE_IPSP_CONNECT:
5750 case BT_LE_IPSP_DISCONNECT:
5751 case BT_PXP_MONITOR_SET_PROPERTY:
5752 case BT_PXP_MONITOR_GET_PROPERTY:
5753 case BT_PXP_MONITOR_GET_SUPPORTED_SERIVCES:
5754 case BT_PXP_REPORTER_REGISTER:
5755 case BT_PXP_REPORTER_UNREGISTER:
5756 case BT_PXP_REPORTER_GET_PROPERTY:
5759 case BT_TDS_PROVIDER_REGISTER:
5760 case BT_TDS_PROVIDER_UNREGISTER:
5761 case BT_TDS_PROVIDER_SET_MANUF_DATA:
5762 case BT_TDS_PROVIDER_CREATE:
5763 case BT_TDS_PROVIDER_DESTROY:
5764 case BT_TDS_PROVIDER_SET_TRANSPORT_DATA:
5765 case BT_TDS_SEND_ACTIVATION_RESPONSE:
5766 case BT_TDS_READ_TRANSPORT_DATA:
5767 case BT_TDS_ENABLE_CONTROL_POINT:
5768 case BT_TDS_ACTIVATE_CONTROL_POINT:
5771 case BT_OTP_SERVER_INIT:
5772 case BT_OTP_SERVER_DEINIT:
5773 case BT_OTP_READ_VALUE:
5774 case BT_OTP_ENABLE_NOTIFICATION:
5775 case BT_OTP_WRITE_VALUE:
5776 case BT_LE_OTC_CONNECT:
5777 case BT_LE_OTC_DISCONNECT:
5779 case BT_MAP_CREATE_SESSION:
5780 case BT_MAP_DESTROY_SESSION:
5781 case BT_MAP_SET_FOLDER:
5782 case BT_MAP_LIST_FOLDERS:
5783 case BT_MAP_LIST_FILTER_FIELDS:
5784 case BT_MAP_LIST_MESSAGES:
5785 case BT_MAP_UPDATE_INBOX:
5786 case BT_MAP_PUSH_MESSAGE:
5787 case BT_MAP_GET_MESSAGE:
5790 case BT_MESH_DEINIT:
5791 case BT_MESH_NETWORK_CREATE:
5792 case BT_MESH_NETWORK_DESTROY:
5793 case BT_MESH_NETWORK_LOAD:
5794 case BT_MESH_NETWORK_UNLOAD:
5795 case BT_MESH_NETWORK_JOIN:
5796 case BT_MESH_CANCEL_JOIN:
5797 case BT_MESH_NETWORK_SCAN:
5798 case BT_MESH_NETWORK_CANCEL_SCAN:
5799 case BT_MESH_NETWORK_SET_CAPABILITIES:
5800 case BT_MESH_NETWORK_PROVISION_DEVICE:
5801 case BT_MESH_AUTHENTICATION_REPLY:
5802 case BT_MESH_NETWORK_SET_NAME:
5803 case BT_MESH_NETWORK_ADD_NETKEY:
5804 case BT_MESH_NETWORK_DELETE_NETKEY:
5805 case BT_MESH_NETWORK_UPDATE_NETKEY:
5806 case BT_MESH_NETWORK_ADD_APPKEY:
5807 case BT_MESH_NETWORK_DELETE_APPKEY:
5808 case BT_MESH_NETWORK_UPDATE_APPKEY:
5809 case BT_MESH_NETWORK_GET_NETKEYS:
5810 case BT_MESH_NETWORK_GET_APPKEYS:
5811 case BT_MESH_NETWORK_GET_NODES:
5812 case BT_MESH_ELEMENT_GET_MODELS:
5813 case BT_MESH_NODE_BROWSE:
5814 case BT_MESH_NODE_GET_VENDOR_FEATURES:
5815 case BT_MESH_NODE_CONFIGURE_KEY:
5816 case BT_MESH_NODE_TTL_EXECUTE:
5817 case BT_MESH_NODE_GET_NETKEYS:
5818 case BT_MESH_NODE_GET_APPKEYS:
5819 case BT_MESH_NODE_RESET:
5820 case BT_MESH_MODEL_CONFIGURE_APPKEY:
5821 case BT_MESH_MODEL_GET_APPKEY_LIST:
5822 case BT_MESH_MODEL_EXECUTE_MSG:
5823 case BT_MESH_MODEL_RESPONSE_MSG:
5824 case BT_MESH_NETWORK_CREATE_GROUP:
5825 case BT_MESH_NETWORK_REMOVE_GROUP:
5826 case BT_MESH_MODEL_CONFIG_GROUP_SUB:
5827 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB:
5828 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST:
5829 case BT_MESH_MODEL_SET_PUBLICATION:
5830 case BT_MESH_MODEL_GET_PUBLICATION:
5831 case BT_MESH_NETWORK_GET_GROUPS:
5833 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5834 BT_PRIVILEGE_PLATFORM);
5836 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5837 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PLATFORM);
5842 case BT_CHECK_ADAPTER:
5845 case BT_GET_LOCAL_NAME:
5846 case BT_GET_LOCAL_ADDRESS:
5847 case BT_GET_LOCAL_VERSION:
5848 case BT_IS_SERVICE_USED:
5849 case BT_GET_DISCOVERABLE_MODE:
5850 case BT_GET_DISCOVERABLE_TIME:
5851 case BT_IS_DISCOVERYING:
5852 case BT_IS_LE_DISCOVERYING:
5853 case BT_IS_CONNECTABLE:
5854 case BT_GET_CONNECTABLE:
5855 case BT_GET_BONDED_DEVICES:
5856 case BT_GET_PROFILE_CONNECTED_DEVICES:
5857 case BT_GET_BONDED_DEVICE:
5858 case BT_PASSKEY_REPLY:
5859 case BT_PASSKEY_CONFIRMATION_REPLY:
5860 case BT_GET_IS_ALIAS_SET:
5861 case BT_IS_DEVICE_CONNECTED:
5862 case BT_GET_CONNECTED_LINK_TYPE:
5863 case BT_SET_PROFILE_TRUSTED:
5864 case BT_GET_PROFILE_TRUSTED:
5865 case BT_GET_SPEAKER_GAIN:
5866 case BT_SET_SPEAKER_GAIN:
5867 case BT_RFCOMM_CLIENT_IS_CONNECTED:
5868 case BT_RFCOMM_IS_UUID_AVAILABLE:
5869 case BT_GET_ADVERTISING_DATA:
5870 case BT_GET_SCAN_RESPONSE_DATA:
5871 case BT_IS_ADVERTISING:
5872 case BT_IS_LE_2M_PHY_SUPPORTED:
5873 case BT_IS_LE_CODED_PHY_SUPPORTED:
5874 case BT_SET_SCANNING_ROLE:
5875 case BT_SET_SCANNING_PHY:
5876 case BT_IS_LE_EXTENDED_ADVERTISING_SUPPORTED:
5877 case BT_IS_LE_EXTENDED_SCAN_SUPPORTED:
5878 case BT_LE_MAX_ADVERTISING_DATA_LEN:
5879 case BT_REGISTER_SCAN_FILTER:
5880 case BT_IS_SCAN_FILTER_SUPPORTED:
5881 case BT_GET_ATT_MTU:
5883 case BT_OBEX_SERVER_ALLOCATE:
5884 case BT_OBEX_SERVER_DEALLOCATE:
5885 case BT_OBEX_SERVER_IS_ACTIVATED:
5886 case BT_OPP_GET_TRANSFER_PROGRESS:
5887 case BT_AVRCP_CONTROL_GET_PROPERTY:
5888 case BT_AVRCP_GET_TRACK_INFO:
5890 case BT_L2CAP_LE_IS_PSM_AVAILABLE:
5891 /* Non-privilege control */
5894 BT_ERR("Unknown function!");
5899 if (function_name >= BT_FUNC_MESH_BASE) {
5900 BT_INFO("MESH Function called");
5901 char app_id[256] = { 0, };
5903 if (BLUETOOTH_ERROR_NONE == __bt_service_get_requester_app_id(unique_name,
5904 app_id, sizeof(app_id))) {
5905 requester_unique_creds = g_strdup(app_id);
5907 BT_DBG("Requester app_id not found, use client creds");
5908 requester_unique_creds = g_strdup(client_creds);
5910 BT_DBG("Requester unique_creds: %s", requester_unique_creds);
5912 BT_INFO("Non MESH Function called client creds [%s]", client_creds);
5924 GDBusNodeInfo *__bt_service_create_method_node_info
5925 (const gchar *introspection_data)
5928 GDBusNodeInfo *node_info = NULL;
5930 if (introspection_data == NULL) {
5931 BT_ERR("Introspection XML not present");
5935 node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
5938 BT_ERR("Unable to create node: %s", err->message);
5939 g_clear_error(&err);
5944 int __bt_service_register_object(GDBusConnection *conn,
5945 GDBusNodeInfo *node_info, gboolean reg)
5947 static guint service_id = 0;
5948 GError *error = NULL;
5951 if (node_info == NULL)
5954 service_id = g_dbus_connection_register_object(conn,
5956 node_info->interfaces[0],
5958 NULL, NULL, &error);
5959 if (service_id == 0)
5962 if (service_id > 0) {
5963 g_dbus_connection_unregister_object(conn,
5972 static void __name_owner_changed(GDBusConnection *connection,
5973 const gchar *sender_name,
5974 const gchar *object_path,
5975 const gchar *interface_name,
5976 const gchar *signal_name,
5977 GVariant *parameters,
5980 const char *name = NULL;
5981 const char *old_owner = NULL;
5982 const char *new_owner = NULL;
5984 g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
5985 if (new_owner && *new_owner != '\0')
5988 _bt_check_hdp_app_termination(name);
5990 /* Advertising App Termination */
5991 _bt_check_adv_app_termination(name);
5993 /* Check if le_scanning app is terminated */
5994 _bt_check_le_scanner_app_termination(name);
5996 /* Check if RFCOMM app is terminated */
5997 _bt_rfcomm_check_termination(name);
5999 /* Mesh App Termination */
6000 _bt_check_mesh_app_termination(name);
6002 /* Stop the Transport Discovery service */
6003 _bt_tds_stop_by_terminated_process(name);
6005 #ifdef TIZEN_FEATURE_BT_CONTAINER
6006 /* Cleanup the NSpid list */
6007 __bt_service_cleanup_nspid_list(name);
6011 static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
6012 const gchar *name, gpointer user_data)
6014 GDBusNodeInfo *node_info = NULL;
6016 BT_INFO("bus acquired");
6018 ret_if(connection == NULL);
6020 node_info = __bt_service_create_method_node_info(
6021 bt_service_introspection_xml);
6022 ret_if(node_info == NULL);
6024 __bt_service_register_object(connection, node_info, TRUE);
6025 g_dbus_node_info_unref(node_info);
6027 bt_service_conn = connection;
6030 static void __bt_service_name_acquired_handler(GDBusConnection *connection,
6031 const gchar *name, gpointer user_data)
6033 BT_INFO("name acquired");
6034 name_acquired = TRUE;
6036 #ifdef TIZEN_FEATURE_BT_CONTAINER
6037 if (_bt_service_is_container() == TRUE)
6038 __bt_service_bus_acquired_handler(connection, name, user_data);
6042 static void __bt_service_name_lost_handler(GDBusConnection *connection,
6043 const gchar *name, gpointer user_data)
6045 BT_INFO("name lost");
6046 name_acquired = FALSE;
6049 gboolean _is_name_acquired(void)
6051 return name_acquired;
6054 void _bt_service_unref_connection(void)
6058 if (bt_service_conn) {
6059 g_dbus_connection_flush_sync(bt_service_conn, NULL, NULL);
6060 g_object_unref(bt_service_conn);
6061 bt_service_conn = NULL;
6067 int _bt_service_register(void)
6069 GDBusConnection *conn;
6072 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
6073 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
6074 bt_service_conn = conn;
6076 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
6078 G_BUS_NAME_OWNER_FLAGS_NONE,
6079 __bt_service_bus_acquired_handler,
6080 __bt_service_name_acquired_handler,
6081 __bt_service_name_lost_handler,
6083 BT_DBG("owner_id is [%d]", owner_id);
6087 /* Subscribe for name owner changed signal */
6088 owner_sig_id = g_dbus_connection_signal_subscribe(conn,
6089 BT_FREEDESKTOP_SERVICE, BT_FREEDESKTOP_INTERFACE,
6090 BT_NAME_OWNER_CHANGED, NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
6091 __name_owner_changed, NULL, NULL);
6092 BT_INFO("owner_sig_id: %d", owner_sig_id);
6094 return BLUETOOTH_ERROR_NONE;
6097 if (bt_service_conn) {
6098 g_object_unref(bt_service_conn);
6099 bt_service_conn = NULL;
6102 return BLUETOOTH_ERROR_INTERNAL;
6105 #ifdef TIZEN_FEATURE_BT_CONTAINER
6106 int _bt_service_register_in_container(void)
6108 GDBusConnection *conn;
6111 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
6112 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
6114 /* Register dbus name because systemd will down bt-service
6115 * if we don't reigster the dbus name in container */
6116 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
6118 G_BUS_NAME_OWNER_FLAGS_NONE,
6119 NULL, NULL, NULL, NULL, NULL);
6120 BT_DBG("owner_id is [%d]", owner_id);
6124 conn = g_dbus_connection_new_for_address_sync(
6125 DBUS_HOST_SYSTEM_BUS_ADDRESS,
6126 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
6128 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
6129 bt_service_conn = conn;
6131 /* Register to host dbus connection to call
6132 * the method toward container in host bt-service */
6133 owner_id = g_bus_own_name_on_connection(conn,
6134 BT_SERVICE_CONTAINER_NAME,
6135 G_BUS_NAME_OWNER_FLAGS_NONE,
6136 __bt_service_name_acquired_handler,
6137 __bt_service_name_lost_handler,
6139 BT_DBG("owner_id is [%d]", owner_id);
6143 return BLUETOOTH_ERROR_NONE;
6146 if (bt_service_conn) {
6147 g_object_unref(bt_service_conn);
6148 bt_service_conn = NULL;
6151 return BLUETOOTH_ERROR_INTERNAL;
6155 void _bt_service_unregister(void)
6157 if (bt_service_conn) {
6158 sd_notify(0, "STOPPING=1");
6160 if (owner_sig_id > 0) {
6161 g_dbus_connection_signal_unsubscribe(
6162 bt_service_conn, owner_sig_id);
6167 g_bus_unown_name(owner_id);
6171 __bt_service_register_object(bt_service_conn, NULL, FALSE);
6174 #ifdef TIZEN_FEATURE_BT_CONTAINER
6176 g_slist_free_full(nspid_list, (GDestroyNotify)__bt_service_free_nspid);
6182 int _bt_service_cynara_init(void)
6185 char err_msg[256] = {0, };
6187 retv_if(p_cynara != NULL, BLUETOOTH_ERROR_ALREADY_INITIALIZED);
6189 result = cynara_initialize(&p_cynara, conf);
6191 if (result != CYNARA_API_SUCCESS) {
6192 cynara_strerror(result, err_msg, sizeof(err_msg));
6193 BT_ERR("Fail to initialize cynara: [%s]", err_msg);
6194 return BLUETOOTH_ERROR_INTERNAL;
6197 return BLUETOOTH_ERROR_NONE;
6200 void _bt_service_cynara_deinit(void)
6203 char err_msg[256] = {0, };
6205 ret_if(p_cynara == NULL);
6207 result = cynara_finish(p_cynara);
6209 if (result != CYNARA_API_SUCCESS) {
6210 cynara_strerror(result, err_msg, sizeof(err_msg));
6211 BT_ERR("Fail to finish cynara: [%s]", err_msg);
6219 void _bt_service_method_return(GDBusMethodInvocation *invocation,
6220 GArray *out_param, int result)
6224 out_var = g_variant_new_from_data((const GVariantType *)"ay",
6225 out_param->data, out_param->len, TRUE, NULL, NULL);
6227 g_dbus_method_invocation_return_value(invocation,
6228 g_variant_new("(iv)", result, out_var));
6231 void _bt_service_method_return_with_unix_fd_list(GDBusMethodInvocation *invocation,
6232 GArray *out_param, int result, GUnixFDList *fd_list)
6236 out_var = g_variant_new_from_data((const GVariantType *)"ay",
6237 out_param->data, out_param->len, TRUE, NULL, NULL);
6239 g_dbus_method_invocation_return_value_with_unix_fd_list(invocation,
6240 g_variant_new("(iv)", result, out_var), fd_list);