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 #ifdef TIZEN_FEATURE_BT_PAN_NAP
66 #include "bt-service-network.h"
69 #ifdef TIZEN_FEATURE_BT_IPSP
70 #include "bt-service-ipsp.h"
72 /* For maintaining Application Sync API call requests */
73 static GSList *invocation_list = NULL;
75 #ifdef TIZEN_FEATURE_BT_CONTAINER
78 gboolean is_container;
80 static GSList *nspid_list = NULL;
83 static GDBusConnection *bt_service_conn;
84 static guint owner_id = 0;
85 static guint owner_sig_id = 0;
86 static gboolean is_le_intended = FALSE;
88 static cynara *p_cynara;
89 static cynara_configuration *conf;
90 static const char *requester_unique_creds = NULL;
92 static const gchar bt_service_introspection_xml[] =
93 "<node name='/org/projectx/bt_service'>"
94 " <interface name='org.projectx.bt'>"
95 " <method name='service_request'>"
96 /* Input Parameters */
97 " <arg type='i' name='service_type' direction='in' />"
98 " <arg type='i' name='service_function' direction='in' />"
99 " <arg type='i' name='request_type' direction='in' />"
100 " <arg type='ay' name='input_param1' direction='in' />"
101 " <arg type='ay' name='input_param2' direction='in' />"
102 " <arg type='ay' name='input_param3' direction='in' />"
103 " <arg type='ay' name='input_param4' direction='in' />"
104 " <arg type='ay' name='input_param5' direction='in' />"
105 /* Return Parameters */
106 " <arg type='i' name='output_param1' direction='out' />"
107 " <arg type='v' name='output_param2' direction='out' />"
109 " <method name='get_avc_mode'>"
111 " <arg type='u' name='avc_mode' direction='out' />"
116 static gboolean name_acquired = FALSE;
118 static char *current_sender_playing = NULL;
120 GDBusNodeInfo *node_info_g = NULL;
122 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param);
124 static void __bt_service_method(GDBusConnection *connection,
126 const gchar *object_path,
127 const gchar *interface_name,
128 const gchar *method_name,
129 GVariant *parameters,
130 GDBusMethodInvocation *invocation,
133 int __bt_bluez_request(int function_name,
136 GDBusMethodInvocation *context,
141 GArray **out_param1);
142 int __bt_obexd_request(int function_name,
145 GDBusMethodInvocation *context,
150 GArray **out_param1);
151 int __bt_agent_request(int function_name,
154 GDBusMethodInvocation *context,
159 GArray **out_param1);
160 int __bt_core_request(int function_name,
163 GDBusMethodInvocation *context,
164 GVariant *in_param1);
166 gboolean __bt_service_check_privilege(int function_name,
168 const char *unique_name);
170 /* Function definitions*/
171 GSList *_bt_get_invocation_list(void)
173 return invocation_list;
176 void _bt_free_info_from_invocation_list(invocation_info_t *req_info)
178 ret_if(NULL == req_info);
179 invocation_list = g_slist_remove(invocation_list, req_info);
180 g_free(req_info->sender);
181 g_free(req_info->user_data);
185 void _bt_set_le_intended_status(gboolean value)
187 is_le_intended = value;
190 static void __bt_service_get_parameters(GVariant *in_param,
191 void *value, int size)
194 buf = (void *)g_variant_get_data(in_param);
195 memcpy(value, buf, size);
198 static gboolean __bt_is_sync_function(int service_function)
200 /*TODO: Keep adding sync methods with expect replies from bluetooth service */
201 if (service_function == BT_GET_LOCAL_ADDRESS
202 || service_function == BT_GET_LOCAL_NAME
203 || service_function == BT_GET_LOCAL_VERSION
204 || service_function == BT_GET_BONDED_DEVICES
205 || service_function == BT_GET_BONDED_DEVICE
206 || service_function == BT_GET_PROFILE_CONNECTED_DEVICES
207 || service_function == BT_GET_IS_ALIAS_SET
208 || service_function == BT_GET_CONNECTED_LINK_TYPE
209 || service_function == BT_IS_SERVICE_USED
210 || service_function == BT_RFCOMM_LISTEN_AND_ACCEPT
211 || service_function == BT_RFCOMM_LISTEN
212 || service_function == BT_HDP_REGISTER_SINK_APP
213 || service_function == BT_HDP_UNREGISTER_SINK_APP
214 || service_function == BT_HDP_GET_FD
215 || service_function == BT_AVRCP_GET_TRACK_INFO
216 || service_function == BT_AVRCP_CONTROL_GET_PROPERTY
217 || service_function == BT_SET_ADVERTISING_DATA
218 || service_function == BT_SET_SCAN_RESPONSE_DATA
219 || service_function == BT_SET_ADVERTISING
220 || service_function == BT_SET_CUSTOM_ADVERTISING
221 || service_function == BT_GATT_SERVER_REGISTER
222 || service_function == BT_GATT_SERVER_ADD_SERVICE
223 || service_function == BT_GATT_SERVER_ADD_CHARACTERISTIC
224 || service_function == BT_GATT_SERVER_ADD_DESCRIPTOR
225 || service_function == BT_GATT_SERVER_START_SERVICE
226 || service_function == BT_GATT_SERVER_STOP_SERVICE
227 || service_function == BT_GATT_SERVER_DELETE_SERVICE
228 || service_function == BT_START_LE_DISCOVERY
229 || service_function == BT_STOP_LE_DISCOVERY
230 || service_function == BT_GET_CONNECTABLE
231 || service_function == BT_GATT_CLIENT_REGISTER
232 || service_function == BT_GATT_GET_PRIMARY_SERVICES
233 || service_function == BT_GATT_GET_SERVICE_PROPERTIES
234 || service_function == BT_GATT_GET_INCLUDED_SERVICES
235 || service_function == BT_GATT_GET_CHARACTERISTIC_PROPERTIES
236 || service_function == BT_GATT_WATCH_CHARACTERISTIC
237 || service_function == BT_GATT_ACQUIRE_WRITE
238 || service_function == BT_AUDIO_SELECT_ROLE
240 || service_function == BT_MESH_INIT
241 || service_function == BT_MESH_NETWORK_CREATE
242 || service_function == BT_MESH_NETWORK_DESTROY
243 || service_function == BT_MESH_NETWORK_LOAD
244 || service_function == BT_MESH_NETWORK_SCAN
245 || service_function == BT_MESH_NETWORK_ADD_NETKEY
246 || service_function == BT_MESH_NETWORK_DELETE_NETKEY
247 || service_function == BT_MESH_NETWORK_UPDATE_NETKEY
248 || service_function == BT_MESH_NETWORK_ADD_APPKEY
249 || service_function == BT_MESH_NETWORK_DELETE_APPKEY
250 || service_function == BT_MESH_NETWORK_UPDATE_APPKEY)
256 void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
257 char *sender, int service_function,
258 gpointer invocation_data)
260 invocation_info_t *info;
261 info = g_malloc0(sizeof(invocation_info_t));
262 info->context = invocation;
263 info->result = result;
264 info->sender = g_strdup(sender);
265 info->service_function = service_function;
266 info->user_data = invocation_data;
267 invocation_list = g_slist_append(invocation_list, info);
271 static int __bt_service_get_sender_pid(const char *unique_name, pid_t *pid)
274 char err_msg[256] = {0, };
276 retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
278 ret = cynara_creds_gdbus_get_pid(bt_service_conn, unique_name, pid);
279 if (ret != CYNARA_API_SUCCESS) {
280 cynara_strerror(ret, err_msg, sizeof(err_msg));
281 BT_ERR("Fail to get user credential: %s", err_msg);
283 return BLUETOOTH_ERROR_INTERNAL;
286 return BLUETOOTH_ERROR_NONE;
289 static int __bt_bm_request_data(_bt_battery_data_t *latest)
291 int ret = _bt_bm_read_data(latest);
292 if (ret == BLUETOOTH_ERROR_NONE) {
293 BT_DBG("Received data from bluetooth battery monitor: %ld %ld %d %d",
294 latest->session_start_time, latest->session_end_time,
295 latest->session_scan_time, latest->session_connected_time);
297 if (latest->atm_list == NULL) {
298 BT_DBG("No app data transaction for this session");
302 for (GSList *l = latest->atm_list; l != NULL; l = g_slist_next(l)) {
303 _bt_battery_app_data_t *t = (_bt_battery_app_data_t *)(l->data);
304 BT_DBG("%ld %ld %d %d", (long int)(t->uid), (long int)(t->pid), t->rx_bytes, t->tx_bytes);
308 BT_ERR("Error encountered");
312 static void __bt_service_method(GDBusConnection *connection,
314 const gchar *object_path,
315 const gchar *interface_name,
316 const gchar *method_name,
317 GVariant *parameters,
318 GDBusMethodInvocation *invocation,
323 BT_DBG("Method[%s] Object Path[%s] Interface Name[%s]",
324 method_name, object_path, interface_name);
326 if (g_strcmp0(method_name, "service_request") == 0) {
328 int service_function;
330 GVariant *param1 = NULL;
331 GVariant *param2 = NULL;
332 GVariant *param3 = NULL;
333 GVariant *param4 = NULL;
334 GVariant *param5 = NULL;
335 GArray *out_param1 = NULL;
336 GVariant *out_var = NULL;
337 GVariant *temp = NULL;
341 g_variant_get(parameters, "(iii@ay@ay@ay@ay@ay)", &service_type,
342 &service_function, &request_type,
343 ¶m1, ¶m2, ¶m3, ¶m4, ¶m5);
345 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
347 if (service_type == BT_CORE_SERVICE) {
348 BT_DBG("No need to check privilege from bt-core");
349 } else if (__bt_service_check_privilege(service_function,
350 service_type, (const char *)sender) == FALSE) {
351 BT_ERR("Client don't have the privilege to excute this function");
352 result = BLUETOOTH_ERROR_PERMISSION_DEINED;
356 BT_DBG("SERVICE TYPE [%d] SERVICE FUNC [%d]",
357 service_type, service_function);
358 switch (service_type) {
359 case BT_BLUEZ_SERVICE:
360 result = __bt_bluez_request(service_function,
361 request_type, request_id,
362 invocation, param1, param2,
363 param3, param4, &out_param1);
365 case BT_OBEX_SERVICE:
366 result = __bt_obexd_request(service_function,
367 request_type, request_id,
370 param4, &out_param1);
372 case BT_AGENT_SERVICE:
373 result = __bt_agent_request(service_function,
374 request_type, request_id,
377 param4, &out_param1);
379 case BT_CORE_SERVICE:
380 result = __bt_core_request(service_function,
381 request_type, request_id,
384 case BT_CHECK_PRIVILEGE:
385 result = BLUETOOTH_ERROR_NONE;
388 BT_ERR("Unknown service type");
389 result = BLUETOOTH_ERROR_INTERNAL;
393 if (result != BLUETOOTH_ERROR_NONE)
396 if (service_type == BT_CHECK_PRIVILEGE)
399 if (service_function == BT_OPP_PUSH_FILES)
402 if (request_type == BT_ASYNC_REQ ||
403 __bt_is_sync_function(service_function)) {
404 /* Do not send reply to bt-api over dbus,
405 Invocation context is already saved in service_function */
410 out_var = g_variant_new_from_data((const GVariantType *)"ay",
411 out_param1->data, out_param1->len,
414 temp = g_variant_new("(iv)", result, out_var);
415 g_dbus_method_invocation_return_value(invocation, temp);
416 g_array_free(out_param1, TRUE);
420 g_variant_unref(param1);
421 g_variant_unref(param2);
422 g_variant_unref(param3);
423 g_variant_unref(param4);
424 g_variant_unref(param5);
428 BT_ERR_C("Request is failed [%s] [0x%x]",
429 _bt_convert_error_to_string(result), result);
431 out_var = g_variant_new_from_data((const GVariantType *)"ay",
432 out_param1->data, out_param1->len,
435 temp = g_variant_new("(iv)", result, out_var);
436 g_dbus_method_invocation_return_value(invocation, temp);
438 g_array_free(out_param1, TRUE);
441 g_variant_unref(param1);
442 g_variant_unref(param2);
443 g_variant_unref(param3);
444 g_variant_unref(param4);
445 g_variant_unref(param5);
447 else if (g_strcmp0(method_name, "get_avc_mode") == 0) {
448 unsigned int mode = 0;
450 if (_bt_audio_get_avc_mode(&mode) != BLUETOOTH_ERROR_NONE)
451 BT_ERR("Fail to get the avc mode");
453 BT_DBG("Absolute Volume Control mode: %d", mode);
455 g_dbus_method_invocation_return_value(invocation,
456 g_variant_new("(u)", mode));
464 static const GDBusInterfaceVTable method_table = {
471 int __bt_bluez_request(int function_name,
474 GDBusMethodInvocation *context,
481 int result = BLUETOOTH_ERROR_NONE;
484 switch (function_name) {
485 case BT_ENABLE_ADAPTER: {
486 result = _bt_enable_adapter();
487 _bt_adapter_start_enable_timer();
490 case BT_DISABLE_ADAPTER: {
491 result = _bt_disable_adapter();
494 case BT_RECOVER_ADAPTER:
495 result = _bt_recover_adapter();
497 case BT_RESET_ADAPTER:
498 result = _bt_reset_adapter();
500 case BT_BATTERY_READ_DATA: {
501 _bt_battery_data_t *data = NULL;
502 data = g_malloc0(sizeof(_bt_battery_data_t));
503 result = __bt_bm_request_data(data);
505 bt_battery_dbus_data_t dbus_data;
506 memset(&dbus_data, 0, sizeof(bt_battery_dbus_data_t));
507 dbus_data.session_start_time = data->session_start_time;
508 dbus_data.session_end_time = data->session_end_time;
509 dbus_data.session_scan_time = data->session_scan_time;
510 dbus_data.session_connected_time = data->session_connected_time;
511 dbus_data.tx_time = data->tx_time;
512 dbus_data.rx_time = data->rx_time;
513 dbus_data.idle_time = data->idle_time;
515 /*Populating app data*/
517 for (GSList *l = data->atm_list; l != NULL; l = g_slist_next(l)) {
518 bt_battery_app_data *t = (bt_battery_app_data *)(l->data);
519 memcpy(&dbus_data.app_data[n], t, sizeof(bt_battery_app_data));
522 dbus_data.num_app = n;
523 g_array_append_vals(*out_param1, &dbus_data, sizeof(bt_battery_dbus_data_t));
524 g_slist_free_full(data->atm_list, g_free);
529 case BT_CHECK_ADAPTER: {
530 int enabled = BT_ADAPTER_DISABLED;
531 result = _bt_check_adapter(&enabled);
533 g_array_append_vals(*out_param1, &enabled,
537 case BT_ENABLE_ADAPTER_LE:
538 _bt_set_le_intended_status(TRUE);
539 result = _bt_enable_adapter_le();
541 case BT_DISABLE_ADAPTER_LE:
542 _bt_set_le_intended_status(FALSE);
543 result = _bt_disable_adapter_le();
545 case BT_START_DISCOVERY: {
546 unsigned short max_response;
547 unsigned short discovery_duration;
548 unsigned int classOfDeviceMask;
551 __bt_service_get_parameters(in_param1,
552 &max_response, sizeof(unsigned short));
553 __bt_service_get_parameters(in_param2,
554 &discovery_duration, sizeof(unsigned short));
555 __bt_service_get_parameters(in_param3,
556 &classOfDeviceMask, sizeof(unsigned int));
557 __bt_service_get_parameters(in_param4, &uid, sizeof(uid_t));
559 result = _bt_start_discovery(max_response, discovery_duration, classOfDeviceMask);
561 if (result == BLUETOOTH_ERROR_NONE) {
564 sender = (char*)g_dbus_method_invocation_get_sender(context);
566 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
567 BT_ERR("Fail to get the sender pid");
569 BT_DBG("Remeber pid / uid for the scan operation");
570 _bt_bm_add_scan_app(SCAN_REGACY, uid, pid);
575 case BT_START_CUSTOM_DISCOVERY: {
576 bt_discovery_role_type_t role;
578 __bt_service_get_parameters(in_param1,
579 &role, sizeof(bt_discovery_role_type_t));
580 result = _bt_start_custom_discovery(role);
584 case BT_CANCEL_DISCOVERY:
585 result = _bt_cancel_discovery();
587 case BT_IS_DISCOVERYING: {
588 gboolean discovering = FALSE;
589 discovering = _bt_is_discovering();
590 g_array_append_vals(*out_param1,
591 &discovering, sizeof(gboolean));
594 case BT_GET_LOCAL_ADDRESS: {
595 result = _bt_get_local_address();
597 /* Save invocation */
598 if (result == BLUETOOTH_ERROR_NONE) {
599 sender = (char*)g_dbus_method_invocation_get_sender(context);
600 _bt_save_invocation_context(context, result, sender,
601 function_name, NULL);
605 case BT_GET_LOCAL_VERSION: {
606 result = _bt_get_local_version();
608 /* Save invocation */
609 if (result == BLUETOOTH_ERROR_NONE) {
610 sender = (char*)g_dbus_method_invocation_get_sender(context);
611 _bt_save_invocation_context(context, result, sender,
612 function_name, NULL);
616 case BT_GET_LOCAL_NAME: {
617 result = _bt_get_local_name();
619 /* Save invocation */
620 if (result == BLUETOOTH_ERROR_NONE) {
621 sender = (char*)g_dbus_method_invocation_get_sender(context);
622 _bt_save_invocation_context(context, result, sender,
623 function_name, NULL);
627 case BT_SET_LOCAL_NAME: {
628 bluetooth_device_name_t local_name = { {0} };
629 __bt_service_get_parameters(in_param1,
630 &local_name, sizeof(bluetooth_device_name_t));
631 result = _bt_set_local_name(local_name.name);
634 case BT_GET_DISCOVERABLE_MODE: {
635 int discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
636 result = _bt_get_discoverable_mode(&discoverable_mode);
637 g_array_append_vals(*out_param1, &discoverable_mode, sizeof(int));
640 case BT_GET_DISCOVERABLE_TIME: {
643 result = _bt_get_timeout_value(&timeout);
644 g_array_append_vals(*out_param1, &timeout, sizeof(int));
647 case BT_SET_DISCOVERABLE_MODE: {
648 int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
651 __bt_service_get_parameters(in_param1, &mode, sizeof(int));
652 __bt_service_get_parameters(in_param2, &time, sizeof(int));
654 result = _bt_set_discoverable_mode(mode, time);
657 case BT_IS_CONNECTABLE: {
658 gboolean is_connectable = FALSE;
660 is_connectable = _bt_is_connectable();
661 g_array_append_vals(*out_param1, &is_connectable, sizeof(gboolean));
664 case BT_GET_CONNECTABLE: {
665 result = _bt_get_connectable();
667 /* Save invocation */
668 if (result == BLUETOOTH_ERROR_NONE) {
669 sender = (char*)g_dbus_method_invocation_get_sender(context);
670 _bt_save_invocation_context(context, result, sender,
671 function_name, NULL);
675 case BT_SET_CONNECTABLE: {
676 gboolean is_connectable;
678 __bt_service_get_parameters(in_param1,
679 &is_connectable, sizeof(gboolean));
680 result = _bt_set_connectable(is_connectable);
683 case BT_IS_SERVICE_USED: {
686 uuid = (char *)g_variant_get_data(in_param1);
687 BT_INFO("UUID to be searched [%s]", uuid);
688 result = _bt_is_service_used();
690 /* Save invocation */
691 if (result == BLUETOOTH_ERROR_NONE) {
692 sender = (char*)g_dbus_method_invocation_get_sender(context);
693 _bt_save_invocation_context(context, result, sender,
694 function_name, g_strdup(uuid));
698 case BT_GET_BONDED_DEVICES: {
699 result = _bt_get_bonded_devices();
700 /* Save invocation */
701 if (result == BLUETOOTH_ERROR_NONE) {
702 sender = (char*)g_dbus_method_invocation_get_sender(context);
703 _bt_save_invocation_context(context, result, sender,
704 function_name, NULL);
708 case BT_GET_BONDED_DEVICE: {
709 bluetooth_device_address_t address = { {0} };
711 __bt_service_get_parameters(in_param1,
712 &address, sizeof(bluetooth_device_address_t));
714 result = _bt_get_bonded_device_info(&address);
715 /* Save invocation */
716 if (result == BLUETOOTH_ERROR_NONE) {
717 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
719 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
723 _bt_convert_addr_type_to_string(addr, address.addr);
724 sender = (char*)g_dbus_method_invocation_get_sender(context);
725 _bt_save_invocation_context(context, result, sender,
726 function_name, addr);
730 case BT_GET_PROFILE_CONNECTED_DEVICES: {
732 uuid = (char *)g_variant_get_data(in_param1);
733 result = _bt_get_profile_connected_devices(uuid);
735 /* Save invocation */
736 if (result == BLUETOOTH_ERROR_NONE) {
737 sender = (char *)g_dbus_method_invocation_get_sender(context);
738 _bt_save_invocation_context(context, result, sender,
739 function_name, NULL);
744 bluetooth_device_address_t address = { {0} };
745 const char *local_name;
747 __bt_service_get_parameters(in_param1,
748 &address, sizeof(bluetooth_device_address_t));
749 local_name = (const char *)g_variant_get_data(in_param2);
751 result = _bt_set_alias(&address, local_name);
754 case BT_BOND_DEVICE: {
755 bluetooth_device_address_t address = { {0} };
757 __bt_service_get_parameters(in_param1,
758 &address, sizeof(bluetooth_device_address_t));
759 result = _bt_bond_device(&address, BLUETOOTH_DEV_CONN_DEFAULT, out_param1);
761 /* Save invocation */
762 if (result == BLUETOOTH_ERROR_NONE) {
763 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
764 _bt_convert_addr_type_to_string(addr, address.addr);
765 sender = (char*)g_dbus_method_invocation_get_sender(context);
766 _bt_save_invocation_context(context, result, sender,
767 function_name, (gpointer)addr);
769 bluetooth_device_info_t dev_info;
771 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
772 memcpy(&dev_info.device_address, &address,
773 sizeof(bluetooth_device_address_t));
774 g_array_append_vals(*out_param1, &dev_info,
775 sizeof(bluetooth_device_info_t));
779 case BT_BOND_DEVICE_BY_TYPE: {
780 bluetooth_device_address_t address = { {0} };
781 unsigned short conn_type = 0;
783 __bt_service_get_parameters(in_param1,
784 &address, sizeof(bluetooth_device_address_t));
785 __bt_service_get_parameters(in_param2,
786 &conn_type, sizeof(unsigned short));
788 result = _bt_bond_device(&address, conn_type, out_param1);
789 /* Save invocation */
790 if (result == BLUETOOTH_ERROR_NONE) {
791 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
792 _bt_convert_addr_type_to_string(addr, address.addr);
793 sender = (char*)g_dbus_method_invocation_get_sender(context);
794 _bt_save_invocation_context(context, result, sender,
795 function_name, (gpointer)addr);
797 bluetooth_device_info_t dev_info;
799 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
800 memcpy(&dev_info.device_address, &address,
801 sizeof(bluetooth_device_address_t));
802 g_array_append_vals(*out_param1, &dev_info,
803 sizeof(bluetooth_device_info_t));
807 case BT_UNBOND_DEVICE: {
808 bluetooth_device_address_t address = { {0} };
810 __bt_service_get_parameters(in_param1,
811 &address, sizeof(bluetooth_device_address_t));
812 result = _bt_unbond_device(&address, out_param1);
814 /* Save invocation */
815 if (result == BLUETOOTH_ERROR_NONE) {
816 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
817 _bt_convert_addr_type_to_string(addr, address.addr);
818 sender = (char*)g_dbus_method_invocation_get_sender(context);
819 _bt_save_invocation_context(context, result, sender,
820 function_name, (gpointer)addr);
822 g_array_append_vals(*out_param1, &address,
823 sizeof(bluetooth_device_address_t));
827 case BT_CANCEL_BONDING:{
828 result = _bt_cancel_bonding();
831 case BT_SEARCH_SERVICE: {
832 bluetooth_device_address_t address = { {0} };
833 __bt_service_get_parameters(in_param1,
834 &address, sizeof(bluetooth_device_address_t));
835 result = _bt_search_device(&address);
836 /* Save invocation */
837 if (result == BLUETOOTH_ERROR_NONE) {
838 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
839 _bt_convert_addr_type_to_string(addr, address.addr);
840 sender = (char*)g_dbus_method_invocation_get_sender(context);
841 _bt_save_invocation_context(context, result, sender,
842 function_name, (gpointer)addr);
844 bt_sdp_info_t sdp_info;
846 memset(&sdp_info, 0x00, sizeof(bt_sdp_info_t));
847 memcpy(&sdp_info.device_addr, &address,
848 sizeof(bluetooth_device_address_t));
849 g_array_append_vals(*out_param1, &sdp_info, sizeof(bt_sdp_info_t));
853 case BT_CANCEL_SEARCH_SERVICE: {
854 result = _bt_cancel_search_device();
857 case BT_SET_PASSKEY_NOTIFICATION: {
861 sender = (char *)g_dbus_method_invocation_get_sender(context);
862 __bt_service_get_parameters(in_param1,
863 &enable, sizeof(gboolean));
865 result = _bt_set_passkey_notification(sender, enable);
868 case BT_SET_PIN_CODE: {
869 bluetooth_device_address_t address = { {0} };
870 bluetooth_device_pin_code_t pin_code = { {0} };
872 __bt_service_get_parameters(in_param1,
873 &address, sizeof(bluetooth_device_address_t));
874 __bt_service_get_parameters(in_param2,
875 &pin_code, sizeof(bluetooth_device_pin_code_t));
877 result = _bt_set_pin_code(&address, &pin_code);
880 case BT_UNSET_PIN_CODE: {
881 bluetooth_device_address_t address = { {0} };
883 __bt_service_get_parameters(in_param1,
884 &address, sizeof(bluetooth_device_address_t));
886 result = _bt_unset_pin_code(&address);
889 case BT_PASSKEY_REPLY: {
890 const char *passkey = NULL;
891 gboolean authentication_reply = FALSE;
892 passkey = g_variant_get_data(in_param1);
893 __bt_service_get_parameters(in_param2,
894 &authentication_reply, sizeof(gboolean));
895 result = _bt_passkey_reply(passkey, authentication_reply);
898 case BT_PASSKEY_CONFIRMATION_REPLY: {
899 gboolean confirmation_reply = FALSE;
900 __bt_service_get_parameters(in_param1,
901 &confirmation_reply, sizeof(gboolean));
902 result = _bt_passkey_confirmation_reply(confirmation_reply);
905 case BT_GET_IS_ALIAS_SET: {
906 bluetooth_device_address_t address = { {0} };
908 __bt_service_get_parameters(in_param1,
909 &address, sizeof(bluetooth_device_address_t));
911 result = _bt_is_alias_set(&address);
912 if (result == BLUETOOTH_ERROR_NONE) {
913 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
915 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
919 _bt_convert_addr_type_to_string(addr, address.addr);
920 sender = (char*)g_dbus_method_invocation_get_sender(context);
921 _bt_save_invocation_context(context, result, sender,
922 function_name, addr);
926 case BT_SET_AUTHORIZATION: {
927 bluetooth_device_address_t address = { {0} };
929 __bt_service_get_parameters(in_param1,
930 &address, sizeof(bluetooth_device_address_t));
931 __bt_service_get_parameters(in_param2,
932 &authorize, sizeof(gboolean));
933 result = _bt_set_authorization(&address, authorize);
936 case BT_SET_LE_PRIVACY: {
937 gboolean set_privacy;
938 __bt_service_get_parameters(in_param1, &set_privacy,
940 result = _bt_set_le_privacy(set_privacy);
943 case BT_ADD_WHITE_LIST: {
944 bluetooth_device_address_t address = { {0} };
945 int address_type = 0;
947 __bt_service_get_parameters(in_param1,
948 &address, sizeof(bluetooth_device_address_t));
949 __bt_service_get_parameters(in_param2,
950 &address_type, sizeof(int));
951 result = _bt_set_white_list(&address, address_type, is_add);
954 case BT_REMOVE_WHITE_LIST: {
955 bluetooth_device_address_t address = { {0} };
956 int address_type = 0;
958 __bt_service_get_parameters(in_param1,
959 &address, sizeof(bluetooth_device_address_t));
960 __bt_service_get_parameters(in_param2,
961 &address_type, sizeof(int));
962 result = _bt_set_white_list(&address, address_type, is_add);
965 case BT_UPDATE_LE_CONNECTION_MODE: {
967 bluetooth_device_address_t remote_address = { { 0 } };
968 bluetooth_le_connection_param_t parameters = { 0 };
969 bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED;
971 __bt_service_get_parameters(in_param1, &remote_address,
972 sizeof(bluetooth_device_address_t));
973 __bt_service_get_parameters(in_param2, &mode,
974 sizeof(bluetooth_le_connection_mode_t));
976 result = _bt_get_le_connection_parameter(mode, ¶meters);
977 if (result != BLUETOOTH_ERROR_NONE)
980 sender = (char *)g_dbus_method_invocation_get_sender(context);
982 result = _bt_le_connection_update(sender,
984 parameters.interval_min,
985 parameters.interval_max,
990 case BT_SET_MANUFACTURER_DATA: {
991 bluetooth_manufacturer_data_t m_data = { 0 };
992 __bt_service_get_parameters(in_param1,
993 &m_data, sizeof(bluetooth_manufacturer_data_t));
994 result = _bt_set_manufacturer_data(&m_data);
998 case BT_IS_DEVICE_CONNECTED: {
999 bluetooth_device_address_t address = { {0} };
1000 gboolean connected = FALSE;
1003 __bt_service_get_parameters(in_param1,
1004 &address, sizeof(bluetooth_device_address_t));
1005 __bt_service_get_parameters(in_param2,
1006 &service_type, sizeof(int));
1008 #if defined(TIZEN_FEATURE_BT_PAN_NAP)
1009 if ((service_type == BLUETOOTH_NAP_SERVICE) || (service_type == BLUETOOTH_NAP_SERVER_SERVICE))
1010 connected = _bt_is_nap_panu_device_connected(&address, service_type);
1012 connected = _bt_is_device_connected(&address, service_type);
1014 connected = _bt_is_device_connected(&address, service_type);
1016 BT_INFO("is_connected: %d", connected);
1017 g_array_append_vals(*out_param1, &connected, sizeof(gboolean));
1020 case BT_GET_CONNECTED_LINK_TYPE: {
1021 bluetooth_device_address_t address = { {0} };
1023 __bt_service_get_parameters(in_param1,
1024 &address, sizeof(bluetooth_device_address_t));
1026 result = _bt_get_connected_link(&address);
1027 if (result == BLUETOOTH_ERROR_NONE) {
1028 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
1030 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
1034 _bt_convert_addr_type_to_string(addr, address.addr);
1035 sender = (char*)g_dbus_method_invocation_get_sender(context);
1036 _bt_save_invocation_context(context, result, sender,
1037 function_name, addr);
1041 case BT_IS_SCAN_FILTER_SUPPORTED:{
1042 int is_supported = 0;
1044 if (_bt_is_scan_filter_supported() == TRUE)
1047 g_array_append_vals(*out_param1,
1048 &is_supported, sizeof(int));
1052 case BT_ENABLE_RSSI: {
1053 bluetooth_device_address_t bd_addr;
1055 bt_rssi_threshold_t rssi_threshold;
1057 int in_range_threshold;
1060 BT_DBG("Enable RSSI");
1062 __bt_service_get_parameters(in_param1,
1063 &bd_addr, sizeof(bluetooth_device_address_t));
1064 __bt_service_get_parameters(in_param2,
1065 &link_type, sizeof(int));
1066 __bt_service_get_parameters(in_param3,
1067 &rssi_threshold, sizeof(bt_rssi_threshold_t));
1069 low_threshold = rssi_threshold.low_threshold;
1070 in_range_threshold = rssi_threshold.in_range_threshold;
1071 high_threshold = rssi_threshold.high_threshold;
1073 result = _bt_enable_rssi(&bd_addr, link_type, low_threshold,
1074 in_range_threshold, high_threshold);
1079 bluetooth_device_address_t bd_addr;
1081 BT_DBG("Get RSSI Strength");
1083 __bt_service_get_parameters(in_param1,
1084 &bd_addr, sizeof(bluetooth_device_address_t));
1085 __bt_service_get_parameters(in_param2,
1086 &link_type, sizeof(int));
1088 result = _bt_get_rssi_strength(&bd_addr, link_type);
1091 case BT_SET_PROFILE_TRUSTED: {
1092 bluetooth_device_address_t bd_addr = { {0} };
1096 __bt_service_get_parameters(in_param1, &bd_addr,
1097 sizeof(bluetooth_device_address_t));
1098 __bt_service_get_parameters(in_param2, &profile, sizeof(int));
1099 __bt_service_get_parameters(in_param3, &trust, sizeof(int));
1101 result = _bt_set_trust_profile(&bd_addr, profile, trust);
1104 case BT_GET_PROFILE_TRUSTED: {
1105 bluetooth_device_address_t bd_addr = { {0} };
1107 guint trusted_profile = 0;
1109 __bt_service_get_parameters(in_param1, &bd_addr,
1110 sizeof(bluetooth_device_address_t));
1111 __bt_service_get_parameters(in_param2, &profile, sizeof(int));
1113 result = _bt_get_trust_profile(&bd_addr, profile, &trusted_profile);
1114 BT_DBG("TRUST %d", trusted_profile);
1115 if (result == BLUETOOTH_ERROR_NONE) {
1116 g_array_append_vals(*out_param1, &trusted_profile,
1122 case BT_HID_CONNECT: {
1123 bluetooth_device_address_t address = { {0} };
1125 __bt_service_get_parameters(in_param1,
1126 &address, sizeof(bluetooth_device_address_t));
1128 result = _bt_hid_connect(&address);
1129 if (result != BLUETOOTH_ERROR_NONE) {
1130 g_array_append_vals(*out_param1, &address,
1131 sizeof(bluetooth_device_address_t));
1133 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1134 _bt_convert_addr_type_to_string(addr, address.addr);
1135 sender = (char*)g_dbus_method_invocation_get_sender(context);
1136 _bt_save_invocation_context(context, result, sender,
1137 function_name, (gpointer)addr);
1141 case BT_HID_DISCONNECT: {
1142 bluetooth_device_address_t address = { {0} };
1144 __bt_service_get_parameters(in_param1,
1145 &address, sizeof(bluetooth_device_address_t));
1147 result = _bt_hid_disconnect(&address);
1148 if (result != BLUETOOTH_ERROR_NONE) {
1149 g_array_append_vals(*out_param1, &address,
1150 sizeof(bluetooth_device_address_t));
1152 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1153 _bt_convert_addr_type_to_string(addr, address.addr);
1154 sender = (char*)g_dbus_method_invocation_get_sender(context);
1155 _bt_save_invocation_context(context, result, sender,
1156 function_name, (gpointer)addr);
1160 case BT_DPM_SET_ALLOW_BT_MODE: {
1161 dpm_bt_allow_t value = DPM_BT_ERROR;
1163 __bt_service_get_parameters(in_param1, &value,
1166 result = _bt_dpm_set_allow_bluetooth_mode(value);
1169 case BT_DPM_GET_ALLOW_BT_MODE: {
1170 int value = DPM_BT_ERROR;
1172 result = _bt_dpm_get_allow_bluetooth_mode(&value);
1173 g_array_append_vals(*out_param1, &value, sizeof(int));
1176 case BT_DPM_SET_DEVICE_RESTRITION: {
1177 dpm_status_t value = DPM_STATUS_ERROR;
1179 __bt_service_get_parameters(in_param1, &value,
1182 result = _bt_dpm_activate_bluetooth_device_restriction(value);
1185 case BT_DPM_GET_DEVICE_RESTRITION: {
1186 int value = DPM_STATUS_ERROR;
1188 result = _bt_dpm_is_bluetooth_device_restriction_active(&value);
1189 g_array_append_vals(*out_param1, &value, sizeof(int));
1192 case BT_DPM_SET_UUID_RESTRITION: {
1193 dpm_status_t value = DPM_STATUS_ERROR;
1195 __bt_service_get_parameters(in_param1, &value,
1198 result = _bt_dpm_activate_bluetoooth_uuid_restriction(value);
1201 case BT_DPM_GET_UUID_RESTRITION: {
1202 int value = DPM_STATUS_ERROR;
1204 result = _bt_dpm_is_bluetooth_uuid_restriction_active(&value);
1205 g_array_append_vals(*out_param1, &value, sizeof(int));
1208 case BT_DPM_ADD_DEVICES_BLACKLIST: {
1209 bluetooth_device_address_t address = { {0} };
1211 __bt_service_get_parameters(in_param1, &address,
1212 sizeof(bluetooth_device_address_t));
1214 result = _bt_dpm_add_bluetooth_devices_to_blacklist(&address);
1217 case BT_DPM_ADD_DEVICES_WHITELIST: {
1218 bluetooth_device_address_t address = { {0} };
1220 __bt_service_get_parameters(in_param1, &address,
1221 sizeof(bluetooth_device_address_t));
1223 result = _bt_dpm_add_bluetooth_devices_to_whitelist(&address);
1226 case BT_DPM_ADD_UUIDS_BLACKLIST: {
1227 const char *uuid = NULL;
1229 uuid = g_variant_get_data(in_param1);
1231 result = _bt_dpm_add_bluetooth_uuids_to_blacklist(uuid);
1234 case BT_DPM_ADD_UUIDS_WHITELIST: {
1235 const char *uuid = NULL;
1237 uuid = g_variant_get_data(in_param1);
1239 result = _bt_dpm_add_bluetooth_uuids_to_whitelist(uuid);
1242 case BT_DPM_CLEAR_DEVICES_BLACKLIST: {
1243 result = _bt_dpm_clear_bluetooth_devices_from_blacklist();
1246 case BT_DPM_CLEAR_DEVICES_WHITELIST: {
1247 result = _bt_dpm_clear_bluetooth_devices_from_whitelist();
1250 case BT_DPM_CLEAR_UUIDS_BLACKLIST: {
1251 result = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
1254 case BT_DPM_CLEAR_UUIDS_WHITELIST: {
1255 result = _bt_dpm_clear_bluetooth_uuids_from_whitelist();
1258 case BT_DPM_REMOVE_DEVICE_BLACKLIST: {
1259 bluetooth_device_address_t address = { {0} };
1261 __bt_service_get_parameters(in_param1, &address,
1262 sizeof(bluetooth_device_address_t));
1264 result = _bt_dpm_remove_bluetooth_devices_from_blacklist(&address);
1267 case BT_DPM_REMOVE_DEVICE_WHITELIST: {
1268 bluetooth_device_address_t address = { {0} };
1270 __bt_service_get_parameters(in_param1, &address,
1271 sizeof(bluetooth_device_address_t));
1273 result = _bt_dpm_remove_bluetooth_devices_from_whitelist(&address);
1276 case BT_DPM_REMOVE_UUID_BLACKLIST: {
1277 const char *uuid = NULL;
1279 uuid = g_variant_get_data(in_param1);
1281 result = _bt_dpm_remove_bluetooth_uuids_from_blacklist(uuid);
1284 case BT_DPM_REMOVE_UUID_WHITELIST: {
1285 const char *uuid = NULL;
1287 uuid = g_variant_get_data(in_param1);
1289 result = _bt_dpm_remove_bluetooth_uuids_from_whitelist(uuid);
1293 case BT_DPM_GET_DEVICES_BLACKLIST: {
1294 result = _bt_dpm_get_bluetooth_devices_from_blacklist(out_param1);
1297 case BT_DPM_GET_DEVICES_WHITELIST: {
1298 result = _bt_dpm_get_bluetooth_devices_from_whitelist(out_param1);
1301 case BT_DPM_GET_UUIDS_BLACKLIST: {
1302 result = _bt_dpm_get_bluetooth_uuids_from_blacklist(out_param1);
1305 case BT_DPM_GET_UUIDS_WHITELIST: {
1306 result = _bt_dpm_get_bluetooth_uuids_from_whitelist(out_param1);
1309 case BT_DPM_SET_ALLOW_OUTGOING_CALL: {
1310 dpm_status_t value = DPM_STATUS_ERROR;
1312 __bt_service_get_parameters(in_param1, &value,
1315 result = _bt_dpm_set_allow_bluetooth_outgoing_call(value);
1319 case BT_DPM_GET_ALLOW_OUTGOING_CALL: {
1320 int value = DPM_STATUS_ERROR;
1322 result = _bt_dpm_get_allow_bluetooth_outgoing_call(&value);
1323 g_array_append_vals(*out_param1, &value, sizeof(int));
1326 case BT_DPM_SET_PAIRING_STATE: {
1327 dpm_status_t value = DPM_STATUS_ERROR;
1329 __bt_service_get_parameters(in_param1, &value,
1332 result = _bt_dpm_set_bluetooth_pairing_state(value);
1336 case BT_DPM_GET_PAIRING_STATE: {
1337 int value = DPM_STATUS_ERROR;
1339 result = _bt_dpm_get_bluetooth_pairing_state(&value);
1340 g_array_append_vals(*out_param1, &value, sizeof(int));
1343 case BT_DPM_SET_PROFILE_STATE: {
1344 int value = DPM_STATUS_ERROR;
1345 int profile = DPM_PROFILE_NONE;
1347 __bt_service_get_parameters(in_param1, &profile,
1349 __bt_service_get_parameters(in_param2, &value,
1352 result = _bt_dpm_set_bluetooth_profile_state(profile, value);
1356 case BT_DPM_GET_PROFILE_STATE: {
1357 int value = DPM_STATUS_ERROR;
1358 int profile = DPM_PROFILE_NONE;
1360 __bt_service_get_parameters(in_param1, &profile,
1363 result = _bt_dpm_get_bluetooth_profile_state(profile, &value);
1364 g_array_append_vals(*out_param1, &value, sizeof(int));
1367 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE: {
1368 int value = DPM_BT_ERROR;
1370 __bt_service_get_parameters(in_param1, &value,
1373 result = _bt_dpm_set_bluetooth_desktop_connectivity_state(value);
1377 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE: {
1378 int value = DPM_STATUS_ERROR;
1380 result = _bt_dpm_get_bluetooth_desktop_connectivity_state(&value);
1381 g_array_append_vals(*out_param1, &value, sizeof(int));
1384 case BT_DPM_SET_DISCOVERABLE_STATE: {
1385 int value = DPM_STATUS_ERROR;
1387 __bt_service_get_parameters(in_param1, &value,
1390 result = _bt_dpm_set_bluetooth_discoverable_state(value);
1394 case BT_DPM_GET_DISCOVERABLE_STATE: {
1395 int value = DPM_STATUS_ERROR;
1397 result = _bt_dpm_get_bluetooth_discoverable_state(&value);
1398 g_array_append_vals(*out_param1, &value, sizeof(int));
1401 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE: {
1402 int value = DPM_STATUS_ERROR;
1404 __bt_service_get_parameters(in_param1, &value,
1407 result = _bt_dpm_set_bluetooth_limited_discoverable_state(value);
1411 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE: {
1412 int value = DPM_STATUS_ERROR;
1414 result = _bt_dpm_get_bluetooth_limited_discoverable_state(&value);
1415 g_array_append_vals(*out_param1, &value, sizeof(int));
1418 case BT_DPM_SET_DATA_TRANSFER_STATE: {
1419 int value = DPM_STATUS_ERROR;
1421 __bt_service_get_parameters(in_param1, &value,
1424 result = _bt_dpm_set_bluetooth_data_transfer_state(value);
1428 case BT_DPM_GET_DATA_TRANSFER_STATE: {
1429 int value = DPM_STATUS_ERROR;
1431 result = _bt_dpm_get_allow_bluetooth_data_transfer_state(&value);
1432 g_array_append_vals(*out_param1, &value, sizeof(int));
1435 case BT_RFCOMM_CLIENT_CONNECT: {
1436 bluetooth_device_address_t address = { {0} };
1440 __bt_service_get_parameters(in_param1,
1441 &address, sizeof(bluetooth_device_address_t));
1442 input_string = (char *)g_variant_get_data(in_param2);
1443 __bt_service_get_parameters(in_param3, &connect_type, sizeof(int));
1445 if (connect_type == BT_RFCOMM_UUID)
1446 result = _bt_rfcomm_connect_using_uuid(&address, input_string);
1448 result = _bt_rfcomm_connect_using_channel(&address, input_string);
1450 if (result != BLUETOOTH_ERROR_NONE) {
1451 bluetooth_rfcomm_connection_t conn_info;
1453 BT_ERR("BT_RFCOMM_CLIENT_CONNECT failed, send error");
1454 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
1455 if (connect_type == BT_RFCOMM_UUID)
1456 g_strlcpy(conn_info.uuid, input_string, BLUETOOTH_UUID_STRING_MAX);
1458 g_strlcpy(conn_info.uuid, "not_used", BLUETOOTH_UUID_STRING_MAX);
1460 conn_info.device_role = RFCOMM_ROLE_CLIENT;
1461 conn_info.socket_fd = -1;
1462 g_array_append_vals(*out_param1, &conn_info,
1463 sizeof(bluetooth_rfcomm_connection_t));
1465 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1466 _bt_convert_addr_type_to_string(addr, address.addr);
1467 sender = (char*)g_dbus_method_invocation_get_sender(context);
1468 _bt_save_invocation_context(context, result, sender, function_name, addr);
1472 case BT_RFCOMM_SOCKET_DISCONNECT: {
1474 * Bluetooth RFCOMM socket disconnection will be done from bt-api, call to bt-service
1475 * is only used for privilege check, so return BLUETOOTH_ERROR_NONE from here.
1477 result = BLUETOOTH_ERROR_NONE;
1480 case BT_RFCOMM_SOCKET_WRITE: {
1482 * This call to bt-service is only used for privilege check, so return
1483 * BLUETOOTH_ERROR_NONE from here.
1485 result = BLUETOOTH_ERROR_NONE;
1488 case BT_RFCOMM_CREATE_SOCKET: {
1490 * This call to bt-service is only used for privilege check, so return
1491 * BLUETOOTH_ERROR_NONE from here.
1493 result = BLUETOOTH_ERROR_NONE;
1496 case BT_RFCOMM_LISTEN_AND_ACCEPT: {
1500 sender = (char *)g_dbus_method_invocation_get_sender(context);
1501 uuid = (char *)g_variant_get_data(in_param1);
1503 result = _bt_rfcomm_socket_listen(sender, uuid, true);
1505 result = BLUETOOTH_ERROR_NONE;
1506 _bt_save_invocation_context(context,
1507 result, sender, function_name, NULL);
1509 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1513 case BT_RFCOMM_LISTEN: {
1517 sender = (char *)g_dbus_method_invocation_get_sender(context);
1518 uuid = (char *)g_variant_get_data(in_param1);
1520 result = _bt_rfcomm_socket_listen(sender, uuid, false);
1522 result = BLUETOOTH_ERROR_NONE;
1523 _bt_save_invocation_context(context,
1524 result, sender, function_name, NULL);
1526 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1530 case BT_RFCOMM_ACCEPT_CONNECTION: {
1533 address = (char *)g_variant_get_data(in_param1);
1534 result = _bt_rfcomm_reply_conn_authorization(address, TRUE);
1537 case BT_RFCOMM_REJECT_CONNECTION: {
1540 address = (char *)g_variant_get_data(in_param1);
1541 result = _bt_rfcomm_reply_conn_authorization(address, FALSE);
1544 case BT_RFCOMM_REMOVE_SOCKET: {
1546 * This call to bt-service is only used for privilege check, so return
1547 * BLUETOOTH_ERROR_NONE from here.
1549 result = BLUETOOTH_ERROR_NONE;
1552 case BT_RFCOMM_SEND_RX_DETAILS: {
1556 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
1557 __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t));
1558 __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int));
1559 _bt_bm_add_transaction_details(uid, pid, size, RX_DATA);
1562 case BT_RFCOMM_SEND_TX_DETAILS: {
1566 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
1567 __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t));
1568 __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int));
1569 _bt_bm_add_transaction_details(uid, pid, size, TX_DATA);
1572 case BT_RFCOMM_UPDATE_CONNECTION_INFO: {
1573 gboolean connected = FALSE;
1575 int role = RFCOMM_ROLE_SERVER;
1577 sender = (char *)g_dbus_method_invocation_get_sender(context);
1579 __bt_service_get_parameters(in_param1, &role, sizeof(int));
1580 __bt_service_get_parameters(in_param2, &connected, sizeof(gboolean));
1581 __bt_service_get_parameters(in_param3, &socket_fd, sizeof(int));
1583 if (connected == TRUE)
1584 result = _bt_rfcomm_conn_added(sender, role, socket_fd);
1586 result = _bt_rfcomm_conn_removed(sender, role, socket_fd);
1590 case BT_AUDIO_SELECT_ROLE: {
1591 bluetooth_audio_role_t role;
1593 __bt_service_get_parameters(in_param1,
1594 &role, sizeof(bluetooth_audio_role_t));
1596 result = _bt_audio_select_role(role);
1597 if (result == BLUETOOTH_ERROR_NONE) {
1598 sender = (char*)g_dbus_method_invocation_get_sender(context);
1599 _bt_save_invocation_context(context, result, sender,
1600 function_name, NULL);
1604 case BT_AUDIO_SET_ABSOLUTE_VOLUME: {
1605 unsigned int volume = 0;
1607 __bt_service_get_parameters(in_param1,
1608 &volume, sizeof(unsigned int));
1610 result = _bt_audio_set_absolute_volume(volume);
1613 case BT_AUDIO_GET_ABSOLUTE_VOLUME: {
1614 unsigned int volume = 0;
1616 result = _bt_audio_get_absolute_volume(&volume);
1617 g_array_append_vals(*out_param1, &volume, sizeof(unsigned int));
1620 case BT_AUDIO_IS_AVC_ACTIVATED: {
1623 result = _bt_audio_is_avc_activated(&activated);
1624 g_array_append_vals(*out_param1, &activated, sizeof(bool));
1627 case BT_AV_CONNECT: {
1628 bluetooth_device_address_t address = { {0} };
1629 __bt_service_get_parameters(in_param1,
1630 &address, sizeof(bluetooth_device_address_t));
1632 result = _bt_audio_is_profile_connection_in_progress(BT_AV_CONNECT, &address);
1634 if (result == BLUETOOTH_ERROR_NONE)
1635 result = _bt_audio_connect(BT_AUDIO_A2DP, &address);
1637 if (result != BLUETOOTH_ERROR_NONE) {
1638 BT_ERR("AV Connect Request has failed to execute");
1639 char addr[BT_ADDRESS_STRING_SIZE];
1640 _bt_convert_addr_type_to_string(addr, address.addr);
1641 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1643 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1644 _bt_convert_addr_type_to_string(addr, address.addr);
1645 sender = (char*)g_dbus_method_invocation_get_sender(context);
1646 _bt_save_invocation_context(context, result, sender,
1647 function_name, (gpointer)addr);
1651 case BT_AUDIO_CONNECT: {
1652 bluetooth_device_address_t address = { {0} };
1653 __bt_service_get_parameters(in_param1,
1654 &address, sizeof(bluetooth_device_address_t));
1656 result = _bt_audio_is_profile_connection_in_progress(BT_AUDIO_CONNECT, &address);
1658 if (result == BLUETOOTH_ERROR_NONE)
1659 result = _bt_audio_connect(BT_AUDIO_ALL, &address);
1661 if (result != BLUETOOTH_ERROR_NONE) {
1662 BT_ERR("Audio All Connect Request has failed to execute");
1663 char addr[BT_ADDRESS_STRING_SIZE];
1664 _bt_convert_addr_type_to_string(addr, address.addr);
1665 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1667 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1668 _bt_convert_addr_type_to_string(addr, address.addr);
1669 sender = (char*)g_dbus_method_invocation_get_sender(context);
1670 _bt_save_invocation_context(context, result, sender,
1671 function_name, (gpointer)addr);
1675 case BT_AUDIO_DISCONNECT: {
1676 bluetooth_device_address_t address = { {0} };
1677 __bt_service_get_parameters(in_param1,
1678 &address, sizeof(bluetooth_device_address_t));
1680 result = _bt_audio_disconnect(BT_AUDIO_ALL, &address);
1682 if (result != BLUETOOTH_ERROR_NONE) {
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_AV_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_A2DP, &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_AG_CONNECT: {
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_is_profile_connection_in_progress(BT_AG_CONNECT, &address);
1722 if (result == BLUETOOTH_ERROR_NONE)
1723 result = _bt_audio_connect(BT_AUDIO_HSP, &address);
1725 if (result != BLUETOOTH_ERROR_NONE) {
1726 BT_ERR("AG Connect Request has failed to execute");
1727 char addr[BT_ADDRESS_STRING_SIZE];
1728 _bt_convert_addr_type_to_string(addr, address.addr);
1729 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1731 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1732 _bt_convert_addr_type_to_string(addr, address.addr);
1733 sender = (char*)g_dbus_method_invocation_get_sender(context);
1734 _bt_save_invocation_context(context, result, sender,
1735 function_name, (gpointer)addr);
1739 case BT_AG_DISCONNECT: {
1740 bluetooth_device_address_t address = { {0} };
1742 __bt_service_get_parameters(in_param1,
1743 &address, sizeof(bluetooth_device_address_t));
1745 result = _bt_audio_disconnect(BT_AUDIO_HSP, &address);
1747 if (result != BLUETOOTH_ERROR_NONE) {
1748 char addr[BT_ADDRESS_STRING_SIZE];
1749 _bt_convert_addr_type_to_string(addr, address.addr);
1750 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1752 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1753 _bt_convert_addr_type_to_string(addr, address.addr);
1754 sender = (char*)g_dbus_method_invocation_get_sender(context);
1755 _bt_save_invocation_context(context, result, sender,
1756 function_name, (gpointer)addr);
1760 case BT_AV_SOURCE_CONNECT: {
1761 bluetooth_device_address_t address = { {0} };
1763 __bt_service_get_parameters(in_param1,
1764 &address, sizeof(bluetooth_device_address_t));
1766 result = _bt_audio_is_profile_connection_in_progress(BT_AV_SOURCE_CONNECT,
1769 if (result == BLUETOOTH_ERROR_NONE)
1770 result = _bt_audio_connect(BT_AUDIO_A2DP_SOURCE, &address);
1772 if (result != BLUETOOTH_ERROR_NONE) {
1773 BT_ERR("A2DP Source Connect Request has failed to execute");
1774 char addr[BT_ADDRESS_STRING_SIZE];
1775 _bt_convert_addr_type_to_string(addr, address.addr);
1776 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1778 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1779 _bt_convert_addr_type_to_string(addr, address.addr);
1780 sender = (char*)g_dbus_method_invocation_get_sender(context);
1781 _bt_save_invocation_context(context, result, sender,
1782 function_name, (gpointer)addr);
1786 case BT_AV_SOURCE_DISCONNECT: {
1787 bluetooth_device_address_t address = { {0} };
1789 __bt_service_get_parameters(in_param1,
1790 &address, sizeof(bluetooth_device_address_t));
1792 result = _bt_audio_disconnect(BT_AUDIO_A2DP_SOURCE, &address);
1793 if (result != BLUETOOTH_ERROR_NONE) {
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_HF_CONNECT: {
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_is_profile_connection_in_progress(BT_HF_CONNECT,
1815 if (result == BLUETOOTH_ERROR_NONE)
1816 result = _bt_hf_connect(&address);
1818 if (result != BLUETOOTH_ERROR_NONE) {
1819 BT_ERR("HF Connect Request has failed to execute");
1820 char addr[BT_ADDRESS_STRING_SIZE];
1821 _bt_convert_addr_type_to_string(addr, address.addr);
1822 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1824 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1825 _bt_convert_addr_type_to_string(addr, address.addr);
1826 sender = (char*)g_dbus_method_invocation_get_sender(context);
1827 _bt_save_invocation_context(context, result, sender,
1828 function_name, (gpointer)addr);
1832 case BT_HF_DISCONNECT: {
1833 bluetooth_device_address_t address = { {0} };
1835 __bt_service_get_parameters(in_param1,
1836 &address, sizeof(bluetooth_device_address_t));
1838 result = _bt_hf_disconnect(&address);
1839 if (result != BLUETOOTH_ERROR_NONE) {
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_AVRCP_TARGET_CONNECT: {
1853 bluetooth_device_address_t address = { {0} };
1855 __bt_service_get_parameters(in_param1,
1856 &address, sizeof(bluetooth_device_address_t));
1858 result = _bt_audio_is_profile_connection_in_progress(BT_AVRCP_TARGET_CONNECT,
1861 if (result == BLUETOOTH_ERROR_NONE)
1862 result = _bt_audio_connect(BT_AVRCP_TARGET, &address);
1864 if (result != BLUETOOTH_ERROR_NONE) {
1865 BT_ERR("AVRCP Target Connect Request has failed to execute");
1866 char addr[BT_ADDRESS_STRING_SIZE];
1867 _bt_convert_addr_type_to_string(addr, address.addr);
1868 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1870 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1871 _bt_convert_addr_type_to_string(addr, address.addr);
1872 sender = (char*)g_dbus_method_invocation_get_sender(context);
1873 _bt_save_invocation_context(context, result, sender,
1874 function_name, (gpointer)addr);
1878 case BT_AVRCP_TARGET_DISCONNECT: {
1879 bluetooth_device_address_t address = { {0} };
1881 __bt_service_get_parameters(in_param1,
1882 &address, sizeof(bluetooth_device_address_t));
1884 result = _bt_audio_disconnect(BT_AVRCP_TARGET, &address);
1885 if (result != BLUETOOTH_ERROR_NONE) {
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_CONTROL_CONNECT: {
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_is_profile_connection_in_progress(BT_AVRCP_CONTROL_CONNECT,
1907 if (result == BLUETOOTH_ERROR_NONE)
1908 result = _bt_audio_connect(BT_AVRCP, &address);
1910 if (result != BLUETOOTH_ERROR_NONE) {
1911 BT_ERR("AVRCP Control Connect Request has failed to execute");
1912 char addr[BT_ADDRESS_STRING_SIZE];
1913 _bt_convert_addr_type_to_string(addr, address.addr);
1914 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1916 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1917 _bt_convert_addr_type_to_string(addr, address.addr);
1918 sender = (char*)g_dbus_method_invocation_get_sender(context);
1919 _bt_save_invocation_context(context, result, sender,
1920 function_name, (gpointer)addr);
1924 case BT_AVRCP_CONTROL_DISCONNECT: {
1925 bluetooth_device_address_t address = { {0} };
1927 __bt_service_get_parameters(in_param1,
1928 &address, sizeof(bluetooth_device_address_t));
1930 result = _bt_audio_disconnect(BT_AVRCP, &address);
1931 if (result != BLUETOOTH_ERROR_NONE) {
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_HANDLE_CONTROL: {
1946 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1947 result = _bt_avrcp_control_cmd(key_code);
1950 case BT_AVRCP_HANDLE_CONTROL_TO_DEST: {
1952 bluetooth_device_address_t address = { { 0 } };
1954 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1955 __bt_service_get_parameters(in_param2,
1956 &address, sizeof(bluetooth_device_address_t));
1958 result = _bt_avrcp_control_cmd_to_dest(key_code, &address);
1961 case BT_AVRCP_CONTROL_SET_PROPERTY: {
1965 __bt_service_get_parameters(in_param1,
1966 &type, sizeof(int));
1967 __bt_service_get_parameters(in_param2,
1968 &value, sizeof(unsigned int));
1970 result = _bt_avrcp_control_set_property(type, value);
1973 case BT_AVRCP_TRANSPORT_SET_PROPERTY: {
1978 __bt_service_get_parameters(in_param1,
1979 &type, sizeof(int));
1980 __bt_service_get_parameters(in_param2,
1981 &value, sizeof(unsigned int));
1983 result = _bt_avrcp_transport_set_property(type, value);
1987 case BT_AVRCP_CONTROL_GET_PROPERTY: {
1990 __bt_service_get_parameters(in_param1, &type, sizeof(int));
1992 result = _bt_avrcp_control_get_property(type);
1993 /* Save invocation */
1994 if (result == BLUETOOTH_ERROR_NONE) {
1995 sender = (char*)g_dbus_method_invocation_get_sender(context);
1996 _bt_save_invocation_context(context, result, sender,
1997 function_name, g_memdup(&type, sizeof(int)));
2001 case BT_AVRCP_GET_TRACK_INFO: {
2002 result = _bt_avrcp_control_get_track_info();
2003 /* Save invocation */
2004 if (result == BLUETOOTH_ERROR_NONE) {
2005 sender = (char*)g_dbus_method_invocation_get_sender(context);
2006 _bt_save_invocation_context(context, result, sender,
2007 function_name, NULL);
2011 case BT_HDP_REGISTER_SINK_APP: {
2012 unsigned short data_type;
2013 bt_hdp_role_type_t role;
2014 bt_hdp_qos_type_t channel_type;
2015 int *app_id = g_new0(int, 1);
2017 __bt_service_get_parameters(in_param1,
2018 &data_type, sizeof(short));
2019 __bt_service_get_parameters(in_param2,
2020 &role, sizeof(bt_hdp_role_type_t));
2021 __bt_service_get_parameters(in_param3,
2022 &channel_type, sizeof(bt_hdp_qos_type_t));
2023 sender = (char*)g_dbus_method_invocation_get_sender(context);
2025 result = _bt_hdp_app_register(role,
2026 channel_type, data_type, sender, app_id);
2027 if (result != BLUETOOTH_ERROR_NONE) {
2028 g_array_append_vals(*out_param1, &app_id, sizeof(app_id));
2031 _bt_save_invocation_context(context, result, sender,
2032 function_name, (gpointer)app_id);
2036 case BT_HDP_UNREGISTER_SINK_APP: {
2038 int *app_id = g_new0(int, 1);
2040 app_handle = (char *)g_variant_get_data(in_param1);
2041 sscanf(app_handle, "health_app_%d", app_id);
2042 result = _bt_hdp_app_unregister(*app_id);
2043 if (result != BLUETOOTH_ERROR_NONE) {
2046 sender = (char*)g_dbus_method_invocation_get_sender(context);
2047 _bt_save_invocation_context(context, result, sender,
2048 function_name, (gpointer)app_id);
2052 case BT_HDP_CONNECT: {
2056 bt_hdp_connected_t *conn_info = NULL;
2058 conn_info = g_malloc0(sizeof(bt_hdp_connected_t));
2060 app_handle = (char *)g_variant_get_data(in_param1);
2061 conn_info->app_handle = app_handle;
2062 sscanf(app_handle, "health_app_%d", &app_id);
2064 __bt_service_get_parameters(in_param2,
2065 &(conn_info->type), sizeof(bt_hdp_qos_type_t));
2066 __bt_service_get_parameters(in_param3,
2067 &(conn_info->device_address),
2068 sizeof(bluetooth_device_address_t));
2070 result = _bt_hdp_connect(app_id, &(conn_info->device_address),
2071 conn_info->type, (int *)(&(conn_info->channel_id)));
2072 if (result != BLUETOOTH_ERROR_NONE) {
2073 g_array_append_vals(*out_param1, conn_info,
2074 sizeof(bt_hdp_connected_t));
2077 sender = (char*)g_dbus_method_invocation_get_sender(context);
2078 _bt_save_invocation_context(context, result, sender,
2079 function_name, (gpointer)conn_info);
2083 case BT_HDP_DISCONNECT: {
2084 bt_hdp_disconnected_t *hdp_disconn_info = NULL;
2086 hdp_disconn_info = g_malloc0(sizeof(bt_hdp_disconnected_t));
2088 __bt_service_get_parameters(in_param1,
2089 &(hdp_disconn_info->channel_id), sizeof(int));
2090 __bt_service_get_parameters(in_param2,
2091 &(hdp_disconn_info->device_address),
2092 sizeof(bluetooth_device_address_t));
2094 result = _bt_hdp_disconnect(hdp_disconn_info->channel_id);
2095 if (result != BLUETOOTH_ERROR_NONE) {
2096 g_array_append_vals(*out_param1, hdp_disconn_info,
2097 sizeof(bt_hdp_disconnected_t));
2098 g_free(hdp_disconn_info);
2100 sender = (char*)g_dbus_method_invocation_get_sender(context);
2101 _bt_save_invocation_context(context, result, sender,
2102 function_name, (gpointer)hdp_disconn_info);
2106 case BT_HDP_GET_FD: {
2107 int *channel_id = g_new0(int, 1);
2109 __bt_service_get_parameters(in_param1, channel_id, sizeof(int));
2111 result = _bt_hdp_get_fd(*channel_id);
2112 if (result != BLUETOOTH_ERROR_NONE) {
2115 sender = (char*)g_dbus_method_invocation_get_sender(context);
2116 _bt_save_invocation_context(context, result, sender,
2117 function_name, (gpointer)channel_id);
2121 case BT_HDP_SEND_DATA: {
2123 * This call to bt-service is only used for privilege check, so return
2124 * BLUETOOTH_ERROR_NONE from here.
2126 result = BLUETOOTH_ERROR_NONE;
2129 case BT_OOB_READ_LOCAL_DATA: { //208
2130 bt_oob_data_t local_oob_data;
2132 memset(&local_oob_data, 0x00, sizeof(bt_oob_data_t));
2133 result = _bt_oob_read_local_data(&local_oob_data);
2135 g_array_append_vals(*out_param1, &local_oob_data,
2136 sizeof(bt_oob_data_t));
2140 case BT_OOB_ADD_REMOTE_DATA: { //209
2141 bluetooth_device_address_t address = { {0} };
2142 unsigned short address_type;
2143 bt_oob_data_t remote_oob_data;
2145 __bt_service_get_parameters(in_param1,
2146 &address, sizeof(bluetooth_device_address_t));
2147 __bt_service_get_parameters(in_param2,
2148 &address_type, sizeof(unsigned short));
2149 __bt_service_get_parameters(in_param3,
2150 &remote_oob_data, sizeof(bt_oob_data_t));
2152 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2156 case BT_OOB_REMOVE_REMOTE_DATA: { //210
2157 bluetooth_device_address_t address = { {0} };
2159 __bt_service_get_parameters(in_param1,
2160 &address, sizeof(bluetooth_device_address_t));
2162 result = _bt_oob_remove_remote_data(&address);
2166 case BT_LE_OOB_READ_LOCAL_DATA: {
2167 bt_oob_data_t local_oob_data;
2168 bt_oob_data_t *local_oob_cache_data;
2170 local_oob_cache_data = _bt_le_oob_get_local_cache_data();
2171 if (local_oob_cache_data && local_oob_cache_data->eir_len) {
2172 g_array_append_vals(*out_param1, local_oob_cache_data,
2173 sizeof(bt_oob_data_t));
2174 return BLUETOOTH_ERROR_NONE;
2177 /* We should modify this logic in later */
2178 if (_bt_is_le_static_random_address_enabled() == false) {
2179 /* Seperate BT & LE address */
2180 _bt_set_le_static_random_address(TRUE);
2183 result = _bt_le_oob_read_local_data(&local_oob_data);
2184 _bt_le_oob_set_local_cache_data(&local_oob_data);
2186 g_array_append_vals(*out_param1, &local_oob_data,
2187 sizeof(bt_oob_data_t));
2191 case BT_LE_OOB_ADD_REMOTE_DATA: {
2192 bluetooth_device_address_t address = { {0} };
2193 unsigned short address_type;
2194 bt_oob_data_t remote_oob_data;
2196 __bt_service_get_parameters(in_param1,
2197 &address, sizeof(bluetooth_device_address_t));
2198 __bt_service_get_parameters(in_param2,
2199 &address_type, sizeof(unsigned short));
2200 __bt_service_get_parameters(in_param3,
2201 &remote_oob_data, sizeof(bt_oob_data_t));
2203 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2207 case BT_AVRCP_SET_TRACK_INFO: {
2208 media_metadata_t data;
2209 media_metadata_attributes_t meta_data;
2211 memset(&data, 0x00, sizeof(media_metadata_t));
2212 memset(&meta_data, 0x00, sizeof(media_metadata_attributes_t));
2214 __bt_service_get_parameters(in_param1,
2215 &data, sizeof(media_metadata_t));
2217 meta_data.title = g_strdup(data.title);
2218 meta_data.artist = g_strdup(data.artist);
2219 meta_data.album = g_strdup(data.album);
2220 meta_data.genre = g_strdup(data.genre);
2221 meta_data.total_tracks = data.total_tracks;
2222 meta_data.number = data.number;
2223 meta_data.duration = (int64_t) data.duration;
2225 result = _bt_avrcp_set_track_info(&meta_data);
2227 g_free((gpointer)meta_data.title);
2228 g_free((gpointer)meta_data.artist);
2229 g_free((gpointer)meta_data.album);
2230 g_free((gpointer)meta_data.genre);
2234 case BT_AVRCP_SET_PROPERTY: {
2238 sender = (char *)g_dbus_method_invocation_get_sender(context);
2240 __bt_service_get_parameters(in_param1,
2241 &type, sizeof(int));
2242 __bt_service_get_parameters(in_param2,
2243 &value, sizeof(unsigned int));
2245 if (value == STATUS_PLAYING) {
2246 if (current_sender_playing)
2247 g_free(current_sender_playing);
2248 current_sender_playing = g_strdup(sender);
2250 if (g_strcmp0(sender, current_sender_playing) == 0 ||
2251 current_sender_playing == NULL) {
2252 BT_INFO("Current Player Status %d type %d Sender %s", value, type, sender);
2254 BT_INFO("Current Player and this sender (%s) are different", sender);
2255 result = BLUETOOTH_ERROR_NONE;
2258 result = _bt_avrcp_set_property(type, value);
2262 case BT_AVRCP_SET_PROPERTIES: {
2263 media_player_settings_t properties;
2265 memset(&properties, 0x00, sizeof(media_player_settings_t));
2266 __bt_service_get_parameters(in_param1,
2267 &properties, sizeof(media_player_settings_t));
2269 result = _bt_avrcp_set_properties(&properties);
2273 case BT_SET_ADVERTISING_DATA: {
2276 bluetooth_advertising_data_t adv = { {0} };
2278 gboolean use_reserved_slot = FALSE;
2280 app = (char *)g_dbus_method_invocation_get_sender(context);
2281 adv_handle = g_malloc0(sizeof(int));
2283 __bt_service_get_parameters(in_param1,
2284 adv_handle, sizeof(int));
2285 __bt_service_get_parameters(in_param3,
2286 &length, sizeof(int));
2287 __bt_service_get_parameters(in_param2,
2289 __bt_service_get_parameters(in_param4,
2290 &use_reserved_slot, sizeof(gboolean));
2291 result = _bt_set_advertising_data(app, *adv_handle,
2292 &adv, length, use_reserved_slot);
2293 if (result != BLUETOOTH_ERROR_NONE) {
2294 BT_ERR("Set Advertising data failed!!");
2297 _bt_save_invocation_context(context, result, app,
2298 function_name, (gpointer)adv_handle);
2302 case BT_SET_SCAN_RESPONSE_DATA: {
2305 bluetooth_scan_resp_data_t rsp = { {0} };
2307 gboolean use_reserved_slot = FALSE;
2309 app = (char *)g_dbus_method_invocation_get_sender(context);
2310 adv_handle = g_malloc0(sizeof(int));
2312 __bt_service_get_parameters(in_param1,
2313 adv_handle, sizeof(int));
2314 __bt_service_get_parameters(in_param3,
2315 &length, sizeof(int));
2316 __bt_service_get_parameters(in_param2,
2318 __bt_service_get_parameters(in_param4,
2319 &use_reserved_slot, sizeof(gboolean));
2321 result = _bt_set_scan_response_data(app, *adv_handle,
2322 &rsp, length, use_reserved_slot);
2324 if (result != BLUETOOTH_ERROR_NONE) {
2325 BT_ERR("Set Scan Response Data failed!!");
2328 _bt_save_invocation_context(context, result, app,
2329 function_name, (gpointer)adv_handle);
2333 case BT_SET_ADVERTISING: {
2336 gboolean enable = FALSE;
2337 gboolean use_reserved_slot = FALSE;
2339 adv_handle = g_malloc0(sizeof(int));
2340 __bt_service_get_parameters(in_param1,
2341 adv_handle, sizeof(int));
2342 __bt_service_get_parameters(in_param2,
2343 &enable, sizeof(gboolean));
2344 __bt_service_get_parameters(in_param3,
2345 &use_reserved_slot, sizeof(gboolean));
2347 app = (char *)g_dbus_method_invocation_get_sender(context);
2349 result = _bt_set_advertising(app, *adv_handle,
2350 enable, use_reserved_slot);
2351 if (result != BLUETOOTH_ERROR_NONE) {
2352 BT_ERR("Start Advertising failed!!");
2355 _bt_save_invocation_context(context, result, app,
2356 function_name, (gpointer)adv_handle);
2360 case BT_SET_CUSTOM_ADVERTISING: {
2363 gboolean enable = FALSE;
2364 bluetooth_advertising_params_t adv_params;
2365 gboolean use_reserved_slot = FALSE;
2367 app = (char *)g_dbus_method_invocation_get_sender(context);
2368 adv_handle = g_malloc0(sizeof(int));
2370 __bt_service_get_parameters(in_param1, adv_handle,
2372 __bt_service_get_parameters(in_param2, &enable,
2374 __bt_service_get_parameters(in_param3, &adv_params,
2375 sizeof(bluetooth_advertising_params_t));
2376 __bt_service_get_parameters(in_param4, &use_reserved_slot,
2379 BT_DBG("bluetooth_advertising_params_t [%d %d %d %d %d]",
2380 adv_params.interval_min, adv_params.interval_max,
2381 adv_params.filter_policy, adv_params.type, adv_params.tx_power_level);
2382 result = _bt_set_custom_advertising(app, *adv_handle,
2383 enable, &adv_params, use_reserved_slot);
2384 if (result != BLUETOOTH_ERROR_NONE) {
2385 BT_ERR("Start Custom Advertising failed!!");
2388 _bt_save_invocation_context(context, result, app,
2389 function_name, (gpointer)adv_handle);
2393 case BT_GET_SCAN_RESPONSE_DATA: {
2394 bluetooth_scan_resp_data_t rsp = { {0} };
2398 app = (char *)g_dbus_method_invocation_get_sender(context);
2400 __bt_service_get_parameters(in_param1, &adv_handle,
2403 result = _bt_get_scan_response_data(app, adv_handle, &rsp, &length);
2404 if (result == BLUETOOTH_ERROR_NONE)
2405 g_array_append_vals(*out_param1, rsp.data, length);
2409 case BT_GET_ADVERTISING_DATA: {
2410 bluetooth_advertising_data_t adv = { {0} };
2414 app = (char *)g_dbus_method_invocation_get_sender(context);
2416 __bt_service_get_parameters(in_param1, &adv_handle,
2419 result = _bt_get_advertising_data(app, adv_handle, &adv, &length);
2420 if (result == BLUETOOTH_ERROR_NONE)
2421 g_array_append_vals(*out_param1, adv.data, length);
2425 case BT_GATT_REGISTER_APPLICATION: {
2426 BT_DBG("Register GATT application:Unhandled!!");
2429 case BT_GATT_SERVER_REGISTER: {
2430 BT_DBG("GATT Server instance initialization");
2433 app = (char *)g_dbus_method_invocation_get_sender(context);
2434 BT_DBG("GATT Server Unique Name [%s]", app);
2436 /* No ADV handle: Set 0 */
2437 result = _bt_register_server_instance(app, 0);
2439 if (result != BLUETOOTH_ERROR_NONE) {
2440 BT_ERR("GATT Server registration failed. result %d", result);
2442 _bt_save_invocation_context(context, result, app,
2443 function_name, NULL);
2447 case BT_GATT_SERVER_DEREGISTER: {
2449 app = (char*)g_dbus_method_invocation_get_sender(context);
2451 result = _bt_unregister_server_instance(app, 0/* Adv Handle*/);
2454 case BT_GATT_SERVER_ADD_SERVICE: {
2455 BT_DBG("GATT Server Add Service");
2461 int *tmp_inst_id = NULL;
2463 app = (char *)g_dbus_method_invocation_get_sender(context);
2465 __bt_service_get_parameters(in_param1, &service_type,
2467 __bt_service_get_parameters(in_param2, &num_handles,
2469 svc_uuid = (char *)g_variant_get_data(in_param3);
2470 __bt_service_get_parameters(in_param4, &instance_id,
2473 result = _bt_gatt_server_add_service(app, service_type, num_handles, svc_uuid, instance_id);
2474 if (result != BLUETOOTH_ERROR_NONE) {
2475 BT_ERR("GATT Server Add Service failed!!");
2477 tmp_inst_id = g_malloc0(sizeof(int));
2478 *tmp_inst_id = instance_id;
2479 _bt_save_invocation_context(context, result, app,
2480 function_name, (gpointer)tmp_inst_id);
2484 case BT_GATT_SERVER_ADD_CHARACTERISTIC: {
2485 BT_DBG("GATT Server Add Characteristic");
2488 int *tmp_inst_id = NULL;
2489 bluetooth_gatt_server_attribute_params_t param;
2490 memset(¶m, 0, sizeof(bluetooth_gatt_server_attribute_params_t));
2492 app = (char*)g_dbus_method_invocation_get_sender(context);
2494 __bt_service_get_parameters(in_param1, ¶m,
2495 sizeof(bluetooth_gatt_server_attribute_params_t));
2496 char_uuid = (char *)g_variant_get_data(in_param2);
2498 result = _bt_gatt_server_add_characteristic(app, char_uuid, ¶m);
2499 if (result != BLUETOOTH_ERROR_NONE) {
2500 BT_ERR("GATT Server Add Service failed!!");
2502 tmp_inst_id = g_malloc0(sizeof(int));
2503 *tmp_inst_id = param.instance_id;
2505 _bt_save_invocation_context(context, result, app,
2506 function_name, (gpointer)tmp_inst_id);
2510 case BT_GATT_SERVER_ADD_DESCRIPTOR: {
2511 BT_DBG("GATT Server Add Descriptor");
2515 bt_gatt_permission_t perm;
2517 int *tmp_inst_id = NULL;
2518 memset(&perm, 0, sizeof(bt_gatt_permission_t));
2520 app = (char *)g_dbus_method_invocation_get_sender(context);
2522 __bt_service_get_parameters(in_param1, &service_handle,
2524 __bt_service_get_parameters(in_param2, &instance_id,
2526 desc_uuid = (char *)g_variant_get_data(in_param4);
2527 __bt_service_get_parameters(in_param3, &perm,
2528 sizeof(bt_gatt_permission_t));
2530 result = _bt_gatt_server_add_descriptor(app, desc_uuid, &perm, service_handle, instance_id);
2531 if (result != BLUETOOTH_ERROR_NONE) {
2532 BT_ERR("GATT Server Add Service failed!!");
2534 tmp_inst_id = g_malloc0(sizeof(int));
2535 *tmp_inst_id = instance_id;
2536 _bt_save_invocation_context(context, result, app,
2537 function_name, (gpointer)tmp_inst_id);
2541 case BT_GATT_SERVER_START_SERVICE: {
2546 int *tmp_inst_id = NULL;
2547 app = (char*)g_dbus_method_invocation_get_sender(context);
2549 __bt_service_get_parameters(in_param1, &service_handle,
2551 __bt_service_get_parameters(in_param2, &instance_id,
2554 result = _bt_gatt_server_start_service(app, service_handle, instance_id);
2556 if (BLUETOOTH_ERROR_NONE == result) {
2557 tmp_inst_id = g_malloc0(sizeof(int));
2558 *tmp_inst_id = instance_id;
2559 _bt_save_invocation_context(context, result, app,
2560 function_name, (gpointer)tmp_inst_id);
2564 case BT_GATT_SERVER_STOP_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_stop_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_DELETE_SERVICE: {
2589 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_delete_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_SEND_RESPONSE: {
2609 bluetooth_gatt_server_response_params_t param;
2610 bluetooth_gatt_att_data_t data;
2613 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_response_params_t));
2614 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2616 app = (char*)g_dbus_method_invocation_get_sender(context);
2618 __bt_service_get_parameters(in_param1, &data,
2619 sizeof(bluetooth_gatt_att_data_t));
2620 __bt_service_get_parameters(in_param2, ¶m,
2621 sizeof(bluetooth_gatt_server_response_params_t));
2623 result = _bt_gatt_server_send_response(app, &data, ¶m);
2627 case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE: {
2629 bluetooth_gatt_server_acquire_response_params_t param;
2632 msg = g_dbus_method_invocation_get_message(context);
2633 GUnixFDList *fd_list;
2638 fd_list = g_dbus_message_get_unix_fd_list(msg);
2640 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2642 app = (char*)g_dbus_method_invocation_get_sender(context);
2644 __bt_service_get_parameters(in_param1, ¶m,
2645 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2647 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2648 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2649 fd = fd_list_array[0];
2652 result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
2656 case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE: {
2658 bluetooth_gatt_server_acquire_response_params_t param;
2661 msg = g_dbus_method_invocation_get_message(context);
2662 GUnixFDList *fd_list;
2667 fd_list = g_dbus_message_get_unix_fd_list(msg);
2669 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2671 app = (char*)g_dbus_method_invocation_get_sender(context);
2673 __bt_service_get_parameters(in_param1, ¶m,
2674 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2676 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2677 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2678 fd = fd_list_array[0];
2681 result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
2685 case BT_GATT_SERVER_SEND_INDICATION: {
2686 bluetooth_gatt_server_indication_params_t param;
2687 bluetooth_gatt_att_data_t data;
2688 bluetooth_device_address_t address;
2691 app = (char*)g_dbus_method_invocation_get_sender(context);
2693 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_indication_params_t));
2694 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2695 memset(&address, 0x00, sizeof(bluetooth_device_address_t));
2697 __bt_service_get_parameters(in_param1, &data,
2698 sizeof(bluetooth_gatt_att_data_t));
2699 __bt_service_get_parameters(in_param2, ¶m,
2700 sizeof(bluetooth_gatt_server_indication_params_t));
2701 __bt_service_get_parameters(in_param3, &address,
2702 sizeof(bluetooth_device_address_t));
2704 result = _bt_gatt_server_send_indication(app, &address, &data, ¶m);
2708 case BT_GATT_SERVER_UPDATE_VALUE: {
2709 bluetooth_gatt_server_update_value_t param;
2713 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_update_value_t));
2715 app = (char*)g_dbus_method_invocation_get_sender(context);
2717 __bt_service_get_parameters(in_param1, &instance_id,
2719 __bt_service_get_parameters(in_param2, ¶m,
2720 sizeof(bluetooth_gatt_server_update_value_t));
2722 result = _bt_gatt_server_update_attribute_value(app, instance_id, ¶m);
2725 case BT_GET_ATT_MTU: {
2726 bluetooth_device_address_t address = { {0} };
2727 unsigned int mtu = 0;
2729 __bt_service_get_parameters(in_param1,
2730 &address, sizeof(bluetooth_device_address_t));
2731 result = _bt_get_att_mtu(&address, &mtu);
2732 BT_DBG("MTU: %d", mtu);
2734 if (result == BLUETOOTH_ERROR_NONE) {
2735 g_array_append_vals(*out_param1, &mtu,
2736 sizeof(unsigned int));
2740 case BT_REQ_ATT_MTU: {
2741 bluetooth_device_address_t address = { {0} };
2745 sender = (char*)g_dbus_method_invocation_get_sender(context);
2747 __bt_service_get_parameters(in_param1,
2748 &address, sizeof(bluetooth_device_address_t));
2749 __bt_service_get_parameters(in_param2,
2750 &mtu, sizeof(unsigned int));
2751 BT_DBG("BT_REQ_ATT_MTU: %d", mtu);
2752 result = _bt_request_att_mtu(&address, mtu);
2753 if (BLUETOOTH_ERROR_NONE == result) {
2754 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2756 _bt_convert_addr_type_to_string(addr, address.addr);
2758 /* Save the informations to invocation */
2759 _bt_save_invocation_context(context, result, sender,
2760 function_name, (gpointer)addr);
2762 g_array_append_vals(*out_param1, &address,
2763 sizeof(bluetooth_device_address_t));
2767 case BT_GET_DEVICE_IDA: {
2768 bluetooth_device_address_t address = { {0} };
2769 bluetooth_device_address_t id_addr = { {0} };
2771 __bt_service_get_parameters(in_param1,
2772 &address, sizeof(bluetooth_device_address_t));
2774 result = _bt_device_get_ida(&address, &id_addr);
2776 if (result == BLUETOOTH_ERROR_NONE) {
2777 g_array_append_vals(*out_param1, &id_addr,
2778 sizeof(bluetooth_device_address_t));
2782 case BT_SET_LE_STATIC_RANDOM_ADDRESS: {
2785 __bt_service_get_parameters(in_param1, &is_enable,
2788 result = _bt_set_le_static_random_address(is_enable);
2793 case BT_GATT_CLIENT_REGISTER: {
2794 bluetooth_device_address_t address = { {0} };
2797 sender = (char*)g_dbus_method_invocation_get_sender(context);
2799 __bt_service_get_parameters(in_param1,
2800 &address, sizeof(bluetooth_device_address_t));
2802 result = _bt_register_gatt_client_instance(sender, &address);
2803 if (BLUETOOTH_ERROR_NONE == result) {
2804 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2806 _bt_convert_addr_type_to_string(addr, address.addr);
2808 /* Save the informations to invocation */
2809 _bt_save_invocation_context(context, result, sender,
2810 function_name, (gpointer)addr);
2815 case BT_GATT_CLIENT_UNREGISTER: {
2818 sender = (char*)g_dbus_method_invocation_get_sender(context);
2819 __bt_service_get_parameters(in_param1,
2820 &client_id, sizeof(int));
2822 result = _bt_unregister_gatt_client_instance(sender, client_id);
2826 /* Async: Remote Interaction */
2827 case BT_GATT_ACQUIRE_WRITE: {
2831 bluetooth_gatt_client_char_prop_info_t param;
2833 sender = (char*)g_dbus_method_invocation_get_sender(context);
2835 __bt_service_get_parameters(in_param1, ¶m,
2836 sizeof(bluetooth_gatt_client_char_prop_info_t));
2839 result = _bt_gatt_acquire_write(¶m , &fd, &mtu);
2841 g_array_append_vals(*out_param1, &mtu, sizeof(int));
2843 if (BLUETOOTH_ERROR_NONE == result)
2844 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
2846 BT_ERR("GATT Client: gatt acquire write failed");
2850 GUnixFDList *fd_list = NULL;
2851 GError *error = NULL;
2853 /* Add socket fd to unix_fd_list */
2854 fd_list = g_unix_fd_list_new();
2855 g_unix_fd_list_append(fd_list, fd, &error);
2856 g_assert_no_error(error);
2858 _bt_service_method_return_with_unix_fd_list(
2859 context, *out_param1, result, fd_list);
2862 g_object_unref(fd_list);
2866 /* Async: Remote Interaction */
2867 case BT_CONNECT_LE: {
2868 bluetooth_device_address_t address = { {0} };
2869 gboolean auto_connect;
2873 sender = (char*)g_dbus_method_invocation_get_sender(context);
2875 __bt_service_get_parameters(in_param1,
2876 &address, sizeof(bluetooth_device_address_t));
2877 __bt_service_get_parameters(in_param2,
2878 &auto_connect, sizeof(gboolean));
2879 __bt_service_get_parameters(in_param3,
2880 &client_id, sizeof(int));
2882 BT_DBG("GATT Client: client_id[%d]", client_id);
2883 result = _bt_connect_le_device(&address, auto_connect, client_id);
2884 if (BLUETOOTH_ERROR_NONE == result) {
2885 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2886 _bt_convert_addr_type_to_string(addr, address.addr);
2888 /* Save the informations to invocation */
2889 _bt_save_invocation_context(context, result, sender,
2890 function_name, (gpointer)addr);
2893 _bt_handle_invocation_context(function_name, (void *)addr);
2895 BT_ERR("GATT Client: gatt connect failed. client_id[%d]", client_id);
2896 g_array_append_vals(*out_param1, &address,
2897 sizeof(bluetooth_device_address_t));
2901 /* Async: Remote Interaction */
2902 case BT_DISCONNECT_LE: {
2903 bluetooth_device_address_t address = { {0} };
2907 sender = (char*)g_dbus_method_invocation_get_sender(context);
2909 __bt_service_get_parameters(in_param1,
2910 &address, sizeof(bluetooth_device_address_t));
2911 __bt_service_get_parameters(in_param2,
2912 &client_id, sizeof(int));
2914 BT_INFO("GATT Disconnect using client Interface [%d]", client_id);
2915 result = _bt_disconnect_le_device(&address, client_id);
2916 if (BLUETOOTH_ERROR_NONE == result) {
2917 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2919 _bt_convert_addr_type_to_string(addr, address.addr);
2921 /* Save the informations to invocation */
2922 _bt_save_invocation_context(context, result, sender,
2923 function_name, (gpointer)addr);
2925 g_array_append_vals(*out_param1, &address,
2926 sizeof(bluetooth_device_address_t));
2931 case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS: {
2932 guint available_packets = 0;
2934 result = _bt_gatt_get_data_batching_available_packets(&available_packets);
2935 BT_DBG("LE batching available packets %u", available_packets);
2936 if (result == BLUETOOTH_ERROR_NONE) {
2937 g_array_append_vals(*out_param1, &available_packets,
2944 case BT_ENABLE_GATT_DATA_BATCHING: {
2945 bluetooth_device_address_t address = { {0} };
2946 int packet_threshold;
2949 __bt_service_get_parameters(in_param1,
2950 &address, sizeof(bluetooth_device_address_t));
2951 __bt_service_get_parameters(in_param2,
2952 &packet_threshold, sizeof(int));
2953 __bt_service_get_parameters(in_param3,
2954 &timeout, sizeof(int));
2955 result = _bt_gatt_enable_data_batching(&address, packet_threshold, timeout);
2960 case BT_DISABLE_GATT_DATA_BATCHING: {
2961 bluetooth_device_address_t address = { {0} };
2963 __bt_service_get_parameters(in_param1,
2964 &address, sizeof(bluetooth_device_address_t));
2965 result = _bt_gatt_disable_data_batching(&address);
2970 case BT_GATT_GET_PRIMARY_SERVICES: {
2973 sender = (char*)g_dbus_method_invocation_get_sender(context);
2974 bluetooth_device_address_t address = { {0} };
2976 __bt_service_get_parameters(in_param1, &address,
2977 sizeof(bluetooth_device_address_t));
2979 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
2980 _bt_convert_addr_type_to_string(addr, address.addr);
2982 result = _bt_gatt_get_primary_services(addr);
2983 if (BLUETOOTH_ERROR_NONE == result) {
2984 _bt_save_invocation_context(context, result, sender,
2985 function_name, (gpointer)addr);
2991 case BT_GATT_GET_SERVICE_PROPERTIES: {
2992 bluetooth_gatt_client_svc_prop_info_t param;
2994 sender = (char*)g_dbus_method_invocation_get_sender(context);
2995 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_svc_prop_info_t));
2997 __bt_service_get_parameters(in_param1, ¶m,
2998 sizeof(bluetooth_gatt_client_svc_prop_info_t));
3000 result = _bt_gatt_get_all_characteristic(¶m);
3001 if (BLUETOOTH_ERROR_NONE == result) {
3002 /* Save the informations to invocation */
3003 _bt_save_invocation_context(context, result, sender,
3005 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_svc_prop_info_t)));
3009 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: {
3010 bluetooth_gatt_client_char_prop_info_t param;
3012 sender = (char*)g_dbus_method_invocation_get_sender(context);
3013 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3015 __bt_service_get_parameters(in_param1, ¶m,
3016 sizeof(bluetooth_gatt_client_char_prop_info_t));
3018 result = _bt_gatt_get_all_characteristic_properties(¶m);
3019 if (BLUETOOTH_ERROR_NONE == result) {
3020 /* Save the informations to invocation */
3021 _bt_save_invocation_context(context, result, sender,
3023 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3027 /* Async: Remote Interaction */
3028 case BT_GATT_READ_CHARACTERISTIC: {
3029 bluetooth_gatt_client_char_prop_info_t param;
3031 sender = (char*)g_dbus_method_invocation_get_sender(context);
3032 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3034 __bt_service_get_parameters(in_param1, ¶m,
3035 sizeof(bluetooth_gatt_client_char_prop_info_t));
3037 result = _bt_gatt_read_characteristic_value(¶m);
3038 if (BLUETOOTH_ERROR_NONE == result) {
3039 /* Save the informations to invocation */
3040 _bt_save_invocation_context(context, result, sender,
3042 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3046 /* Async: Remote Interaction */
3047 case BT_GATT_READ_DESCRIPTOR_VALUE: {
3048 bluetooth_gatt_client_desc_prop_info_t param;
3050 sender = (char*)g_dbus_method_invocation_get_sender(context);
3051 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3053 __bt_service_get_parameters(in_param1, ¶m,
3054 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3056 result = _bt_gatt_read_descriptor_value(¶m);
3057 if (BLUETOOTH_ERROR_NONE == result) {
3058 /* Save the informations to invocation */
3059 _bt_save_invocation_context(context, result, sender,
3061 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3065 /* Async: Remote Interaction */
3066 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: {
3067 bluetooth_gatt_client_char_prop_info_t param;
3068 bluetooth_gatt_att_data_t data;
3069 bluetooth_gatt_write_type_e write_type;
3071 sender = (char*)g_dbus_method_invocation_get_sender(context);
3073 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3074 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3076 __bt_service_get_parameters(in_param1, ¶m,
3077 sizeof(bluetooth_gatt_client_char_prop_info_t));
3078 __bt_service_get_parameters(in_param2, &data,
3079 sizeof(bluetooth_gatt_att_data_t));
3080 __bt_service_get_parameters(in_param3, &write_type,
3081 sizeof(bluetooth_gatt_write_type_e));
3083 result = _bt_gatt_write_characteristic_value_by_type(¶m , &data, write_type);
3084 if (BLUETOOTH_ERROR_NONE == result) {
3085 /* Save the informations to invocation */
3086 _bt_save_invocation_context(context, result, sender,
3088 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3092 /* Async: Remote Interaction */
3093 case BT_GATT_WRITE_DESCRIPTOR_VALUE: {
3094 bluetooth_gatt_client_desc_prop_info_t param;
3095 bluetooth_gatt_att_data_t data;
3096 bluetooth_gatt_write_type_e write_type;
3098 sender = (char*)g_dbus_method_invocation_get_sender(context);
3099 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3100 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3102 __bt_service_get_parameters(in_param1, ¶m,
3103 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3104 __bt_service_get_parameters(in_param2, &data,
3105 sizeof(bluetooth_gatt_att_data_t));
3106 __bt_service_get_parameters(in_param3, &write_type,
3107 sizeof(bluetooth_gatt_write_type_e));
3109 result = _bt_gatt_write_descriptor_value_by_type(¶m, &data, write_type);
3110 if (BLUETOOTH_ERROR_NONE == result) {
3111 /* Save the informations to invocation */
3112 _bt_save_invocation_context(context, result, sender,
3114 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3119 case BT_GATT_WATCH_CHARACTERISTIC: {
3120 bluetooth_gatt_client_char_prop_info_t param;
3125 gboolean is_indicate;
3128 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3130 sender = (char*)g_dbus_method_invocation_get_sender(context);
3132 __bt_service_get_parameters(in_param1, ¶m,
3133 sizeof(bluetooth_gatt_client_char_prop_info_t));
3134 __bt_service_get_parameters(in_param2, &client_id,
3136 __bt_service_get_parameters(in_param3, &is_notify,
3138 __bt_service_get_parameters(in_param4, &is_indicate,
3141 #ifdef TIZEN_FEATURE_BT_GATT_CLIENT_FD_DISABLE
3145 if (is_indicate == false) {
3146 result = _bt_gatt_acquire_notify(¶m , &fd, &mtu);
3147 if (BLUETOOTH_ERROR_NONE == result && fd > -1) {
3148 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
3150 GUnixFDList *fd_list = NULL;
3151 GError *error = NULL;
3153 g_array_append_vals(*out_param1, &mtu, sizeof(int));
3154 /* Add socket fd to unix_fd_list */
3155 fd_list = g_unix_fd_list_new();
3156 g_unix_fd_list_append(fd_list, fd, &error);
3157 g_assert_no_error(error);
3159 _bt_service_method_return_with_unix_fd_list(
3160 context, *out_param1, result, fd_list);
3162 g_object_unref(fd_list);
3168 result = _bt_gatt_watch_characteristic(¶m , client_id, is_notify);
3169 if (BLUETOOTH_ERROR_NONE == result) {
3170 /* Save the informations to invocation */
3171 _bt_save_invocation_context(context, result, sender, function_name,
3172 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3177 case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: {
3178 gboolean is_enabled;
3179 bluetooth_device_address_t address;
3181 sender = (char*)g_dbus_method_invocation_get_sender(context);
3183 __bt_service_get_parameters(in_param1,
3184 &address, sizeof(bluetooth_device_address_t));
3185 __bt_service_get_parameters(in_param2, &is_enabled,
3187 result = _bt_gatt_watch_service_changed_indication(sender, &address, is_enabled);
3188 BT_INFO("Service changed indication from app [%s]", sender);
3192 case BT_LE_CONN_UPDATE: {
3193 char *sender = NULL;
3194 bluetooth_device_address_t local_address = { {0} };
3195 bluetooth_le_connection_param_t parameters = {0};
3197 sender = (char *)g_dbus_method_invocation_get_sender(context);
3199 __bt_service_get_parameters(in_param1, &local_address,
3200 sizeof(bluetooth_device_address_t));
3201 __bt_service_get_parameters(in_param2, ¶meters,
3202 sizeof(bluetooth_le_connection_param_t));
3204 result = _bt_le_connection_update(sender,
3206 parameters.interval_min,
3207 parameters.interval_max,
3209 parameters.timeout);
3212 case BT_START_LE_DISCOVERY: {
3216 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3218 sender = (char *)g_dbus_method_invocation_get_sender(context);
3220 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3221 BT_ERR("Fail to get the sender pid");
3223 result = _bt_start_le_scan(sender, uid, pid);
3224 if (result == BLUETOOTH_ERROR_NONE) {
3225 _bt_save_invocation_context(context, result, sender,
3226 function_name, NULL);
3228 BT_DBG("Remeber pid / uid for the scan operation");
3229 _bt_bm_add_scan_app(SCAN_LE, uid, pid);
3233 case BT_STOP_LE_DISCOVERY: {
3237 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3239 sender = (char *)g_dbus_method_invocation_get_sender(context);
3241 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3242 BT_ERR("Fail to get the sender pid");
3244 result = _bt_stop_le_scan(sender);
3245 if (result == BLUETOOTH_ERROR_NONE) {
3246 _bt_save_invocation_context(context, result, sender,
3247 function_name, NULL);
3250 BT_DBG("Remove pid / uid for the scan operation");
3251 _bt_bm_remove_scan_app(SCAN_LE, uid, pid);
3255 case BT_IS_LE_DISCOVERYING: {
3256 gboolean le_discovering = FALSE;
3258 le_discovering = _bt_is_le_scanning();
3259 g_array_append_vals(*out_param1,
3260 &le_discovering, sizeof(gboolean));
3263 case BT_SET_SCAN_PARAMETERS: {
3264 bluetooth_le_scan_params_t scan_params;
3266 __bt_service_get_parameters(in_param1, &scan_params,
3267 sizeof(bluetooth_le_scan_params_t));
3269 BT_DBG("bluetooth_le_scan_params_t [%f %f %d]",
3270 scan_params.interval, scan_params.window,
3273 result = _bt_prepare_scan_parameters(&scan_params, 0);
3276 case BT_SET_SCAN_TYPE: {
3278 __bt_service_get_parameters(in_param1, &scan_type, sizeof(int));
3280 BT_DBG("bluetooth_le_scan_type [%d]", scan_type);
3281 result = _bt_prepare_scan_parameters(NULL, scan_type);
3284 #ifdef TIZEN_FEATURE_BT_PAN_NAP
3285 case BT_NETWORK_ACTIVATE:
3286 BT_DBG("BT_NETWORK_ACTIVATE Request recieved Request Handler ");
3287 result = _bt_network_activate();
3289 case BT_NETWORK_DEACTIVATE:
3290 result = _bt_network_deactivate();
3292 case BT_NETWORK_CONNECT: {
3293 bluetooth_device_address_t address = { {0} };
3296 __bt_service_get_parameters(in_param1,
3297 &address, sizeof(bluetooth_device_address_t));
3298 __bt_service_get_parameters(in_param2,
3299 &role, sizeof(int));
3301 result = _bt_network_connect(request_id, role, &address);
3302 if (result != BLUETOOTH_ERROR_NONE) {
3303 g_array_append_vals(*out_param1, &address,
3304 sizeof(bluetooth_device_address_t));
3308 case BT_NETWORK_DISCONNECT: {
3309 bluetooth_device_address_t address = { {0} };
3311 __bt_service_get_parameters(in_param1,
3312 &address, sizeof(bluetooth_device_address_t));
3314 result = _bt_network_disconnect(request_id, &address);
3315 if (result != BLUETOOTH_ERROR_NONE) {
3316 g_array_append_vals(*out_param1, &address,
3317 sizeof(bluetooth_device_address_t));
3321 case BT_NETWORK_SERVER_DISCONNECT: {
3322 bluetooth_device_address_t address = { {0} };
3324 __bt_service_get_parameters(in_param1,
3325 &address, sizeof(bluetooth_device_address_t));
3327 result = _bt_network_server_disconnect(request_id, &address);
3328 if (result != BLUETOOTH_ERROR_NONE) {
3329 g_array_append_vals(*out_param1, &address,
3330 sizeof(bluetooth_device_address_t));
3336 #ifdef TIZEN_FEATURE_BT_IPSP
3337 case BT_LE_IPSP_INIT:
3338 result = _bt_initialize_ipsp();
3340 case BT_LE_IPSP_DEINIT:
3341 result = _bt_deinitialize_ipsp();
3343 case BT_LE_IPSP_CONNECT: {
3344 bluetooth_device_address_t address = { {0} };
3345 __bt_service_get_parameters(in_param1, &address,
3346 sizeof(bluetooth_device_address_t));
3347 result = _bt_connect_le_ipsp_device(&address);
3350 case BT_LE_IPSP_DISCONNECT: {
3351 bluetooth_device_address_t address = { {0} };
3352 __bt_service_get_parameters(in_param1, &address,
3353 sizeof(bluetooth_device_address_t));
3354 result = _bt_disconnect_le_ipsp_device(&address);
3358 case BT_IS_ADVERTISING: {
3359 gboolean advertising = FALSE;
3360 advertising = _bt_is_advertising();
3361 g_array_append_vals(*out_param1, &advertising,
3365 case BT_IS_LE_2M_PHY_SUPPORTED: {
3366 gboolean is_2m_phy_supported = FALSE;
3368 is_2m_phy_supported = _bt_is_le_2m_phy_supported();
3369 g_array_append_vals(*out_param1, &is_2m_phy_supported, sizeof(gboolean));
3372 case BT_IS_LE_CODED_PHY_SUPPORTED: {
3373 gboolean is_coded_phy_supported = FALSE;
3375 is_coded_phy_supported = _bt_is_le_coded_phy_supported();
3376 g_array_append_vals(*out_param1, &is_coded_phy_supported, sizeof(gboolean));
3379 case BT_DISCONNECT_DEVICE: {
3380 bluetooth_device_address_t address = { {0} };
3382 __bt_service_get_parameters(in_param1,
3383 &address, sizeof(bluetooth_device_address_t));
3385 result = _bt_disconnect_device(&address);
3388 case BT_REGISTER_SCAN_FILTER: {
3389 bluetooth_le_scan_filter_t scan_filter;
3391 sender = (char*)g_dbus_method_invocation_get_sender(context);
3392 __bt_service_get_parameters(in_param1, &scan_filter,
3393 sizeof(bluetooth_le_scan_filter_t));
3395 BT_DBG("bluetooth_le_scan_filter_t [features : 0x%.2x]",
3396 scan_filter.added_features);
3398 result = _bt_register_scan_filter(sender, &scan_filter);
3403 case BT_TDS_PROVIDER_REGISTER: {
3404 char *sender = NULL;
3406 sender = (char *)g_dbus_method_invocation_get_sender(context);
3407 result = _bt_tds_provider_register(sender);
3412 case BT_TDS_PROVIDER_UNREGISTER: {
3413 char *sender = NULL;
3415 sender = (char *)g_dbus_method_invocation_get_sender(context);
3416 result = _bt_tds_provider_unregister(sender);
3421 case BT_TDS_PROVIDER_SET_MANUF_DATA: {
3422 char *sender = NULL;
3423 unsigned int length = 0;
3424 bluetooth_advertising_data_t manuf_data;
3426 __bt_service_get_parameters(in_param1,
3427 &length, sizeof(unsigned int));
3428 __bt_service_get_parameters(in_param2,
3429 &manuf_data, sizeof(bluetooth_advertising_data_t));
3430 sender = (char *)g_dbus_method_invocation_get_sender(context);
3432 result = _bt_tds_provider_set_manuf_data(sender, manuf_data.data, length);
3436 case BT_TDS_PROVIDER_CREATE: {
3437 char *sender = NULL;
3438 unsigned int tds_handle = 0;
3441 __bt_service_get_parameters(in_param1,
3442 &tds_handle, sizeof(unsigned int));
3443 __bt_service_get_parameters(in_param2,
3444 &transport, sizeof(int));
3445 sender = (char *)g_dbus_method_invocation_get_sender(context);
3446 result = _bt_tds_provider_transport_create(sender, transport, tds_handle);
3451 case BT_TDS_PROVIDER_DESTROY: {
3452 char *sender = NULL;
3453 unsigned int tds_handle = 0;
3455 __bt_service_get_parameters(in_param1,
3456 &tds_handle, sizeof(unsigned int));
3457 sender = (char *)g_dbus_method_invocation_get_sender(context);
3458 result = _bt_tds_provider_transport_remove(sender, tds_handle);
3463 case BT_TDS_PROVIDER_SET_TRANSPORT_DATA: {
3464 char *sender = NULL;
3465 unsigned int tds_handle = 0;
3466 int transport_state = 0;
3467 bluetooth_tds_data_t tds_data;
3469 __bt_service_get_parameters(in_param1,
3470 &tds_handle, sizeof(unsigned int));
3471 __bt_service_get_parameters(in_param2,
3472 &transport_state, sizeof(int));
3473 __bt_service_get_parameters(in_param3,
3474 &tds_data, sizeof(bluetooth_tds_data_t));
3475 sender = (char *)g_dbus_method_invocation_get_sender(context);
3477 result = _bt_tds_provider_set_transport_data(sender, tds_handle,
3478 transport_state, tds_data.data, tds_data.length);
3482 case BT_TDS_SEND_ACTIVATION_RESPONSE: {
3483 bluetooth_device_address_t address = { {0} };
3484 bluetooth_tds_data_t tds_data;
3485 char *sender = NULL;
3486 unsigned int tds_handle = 0;
3489 __bt_service_get_parameters(in_param1,
3490 &tds_handle, sizeof(unsigned int));
3491 __bt_service_get_parameters(in_param2,
3492 &response, sizeof(int));
3493 __bt_service_get_parameters(in_param3, &address,
3494 sizeof(bluetooth_device_address_t));
3495 __bt_service_get_parameters(in_param4,
3496 &tds_data, sizeof(bluetooth_tds_data_t));
3497 sender = (char *)g_dbus_method_invocation_get_sender(context);
3499 result = _bt_tds_provider_send_activation_response(sender, tds_handle,
3500 &address, response, tds_data.data, tds_data.length);
3505 sender = (char*)g_dbus_method_invocation_get_sender(context);
3506 BT_INFO("Mesh: Init by [%s]", sender);
3507 result = _bt_mesh_init(sender);
3508 /* Save invocation */
3509 if (result == BLUETOOTH_ERROR_NONE) {
3510 BT_INFO("Mesh: Save Invoation");
3511 sender = (char*)g_dbus_method_invocation_get_sender(context);
3512 _bt_save_invocation_context(context,
3514 function_name, NULL);
3518 case BT_MESH_DEINIT:
3519 sender = (char*)g_dbus_method_invocation_get_sender(context);
3520 BT_INFO("Mesh: De-Init by [%s]", sender);
3521 result = _bt_mesh_deinit(sender);
3524 case BT_MESH_NETWORK_CREATE: {
3525 bluetooth_mesh_node_t node;
3526 GSList *model_list = NULL;
3527 int total_models = 0;
3530 const char *network_name = NULL;
3531 bluetooth_mesh_network_t *network;
3533 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
3534 sender = (char*)g_dbus_method_invocation_get_sender(context);
3536 __bt_service_get_parameters(in_param1,
3537 &node, sizeof(bluetooth_mesh_node_t));
3538 network_name = (const char *)g_variant_get_data(in_param2);
3540 BT_INFO("MESH: Network name [%s]", network_name);
3542 param3 = g_array_new(TRUE, TRUE, sizeof(gchar));
3543 __bt_fill_garray_from_variant(in_param3, param3);
3545 total_models = (param3->len) / sizeof(bluetooth_mesh_model_t);
3546 for (i = 0; i < total_models; i++) {
3547 bluetooth_mesh_model_t *info = NULL;
3548 bluetooth_mesh_model_t *mod = NULL;
3550 info = &g_array_index(param3,
3551 bluetooth_mesh_model_t, i);
3553 mod = g_memdup(info, sizeof(bluetooth_mesh_model_t));
3556 model_list = g_slist_append(model_list,
3559 result = _bt_mesh_network_create(requester_unique_creds,
3560 sender, network_name, &node, model_list);
3562 /* Save invocation */
3563 if (result == BLUETOOTH_ERROR_NONE) {
3564 BT_INFO("Mesh: Save Invoation");
3565 network = g_malloc0(sizeof(bluetooth_mesh_network_t));
3567 /* Save Network name & UUID, Token will be received in event */
3568 _bt_mesh_util_convert_hex_to_string(
3569 (uint8_t *) node.uuid, 16,
3571 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
3572 BT_INFO("Mesh: Mesh Netwok UUID [%s]", network->uuid);
3573 g_strlcpy(network->name.name, network_name,
3574 sizeof(network->name.name));
3575 g_strlcpy(network->app_cred,
3576 requester_unique_creds,
3577 sizeof(network->app_cred));
3578 sender = (char*)g_dbus_method_invocation_get_sender(context);
3579 BT_INFO("Mesh: Network Create by [%s]", sender);
3580 _bt_save_invocation_context(context,
3582 function_name, (gpointer)network);
3584 g_array_append_vals(*out_param1, &node, sizeof(bluetooth_mesh_node_t));
3585 BT_ERR("Mesh: Mesh Network creation schedule failed");
3586 g_slist_free_full(model_list, g_free);
3590 BT_INFO("Mesh: Cleanup");
3591 g_free((gpointer)requester_unique_creds);
3592 g_array_free(param3, TRUE);
3593 BT_INFO("Mesh: Cleanup Done");
3596 case BT_MESH_NETWORK_DESTROY: {
3597 bluetooth_mesh_network_t network;
3598 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3600 __bt_service_get_parameters(in_param1,
3601 &network, sizeof(bluetooth_mesh_network_t));
3603 BT_INFO("Mesh: Destroy Network");
3604 result = _bt_mesh_network_destroy(requester_unique_creds,
3607 if (result != BLUETOOTH_ERROR_NONE) {
3608 g_array_append_vals(*out_param1,
3609 &network, sizeof(bluetooth_mesh_network_t));
3611 BT_INFO("Mesh: Destroy Network scheduled: add invocation");
3612 bluetooth_mesh_network_t *net = \
3613 g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3615 sender = (char*)g_dbus_method_invocation_get_sender(context);
3616 _bt_save_invocation_context(context, result, sender,
3617 function_name, (gpointer)net);
3621 case BT_MESH_NETWORK_LOAD: {
3623 bluetooth_mesh_network_t *network;
3624 token = (char *)g_variant_get_data(in_param1);
3625 BT_INFO("MESH: Network Load: Token string [%s]", token);
3626 result = _bt_mesh_network_load(requester_unique_creds, sender, token);
3627 /* Save invocation */
3628 if (result == BLUETOOTH_ERROR_NONE) {
3629 network = g_malloc0(sizeof(bluetooth_mesh_network_t));
3630 g_strlcpy(network->token.token, token,
3631 BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
3632 g_strlcpy(network->app_cred, requester_unique_creds,
3633 sizeof(network->app_cred));
3635 sender = (char*)g_dbus_method_invocation_get_sender(context);
3636 _bt_save_invocation_context(context, result, sender,
3637 function_name, (gpointer)network);
3639 g_free((gpointer)requester_unique_creds);
3642 case BT_MESH_NETWORK_UNLOAD: {
3643 bluetooth_mesh_network_t network;
3644 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3646 __bt_service_get_parameters(in_param1,
3647 &network, sizeof(bluetooth_mesh_network_t));
3649 BT_INFO("MESH: Network Unload: Network UUID [%s]", network.uuid);
3650 result = _bt_mesh_network_unload(requester_unique_creds,
3654 case BT_MESH_NETWORK_JOIN: {
3655 bluetooth_mesh_node_t node;
3656 GSList *model_list = NULL;
3657 int total_models = 0;
3661 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
3662 sender = (char*)g_dbus_method_invocation_get_sender(context);
3664 __bt_service_get_parameters(in_param1,
3665 &node, sizeof(bluetooth_mesh_node_t));
3667 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
3668 __bt_fill_garray_from_variant(in_param2, param2);
3670 total_models = (param2->len) / sizeof(bluetooth_mesh_model_t);
3671 for (i = 0; i < total_models; i++) {
3672 bluetooth_mesh_model_t *info = NULL;
3673 bluetooth_mesh_model_t *mod = NULL;
3674 info = &g_array_index(param2,
3675 bluetooth_mesh_model_t, i);
3676 mod = g_memdup(info, sizeof(bluetooth_mesh_model_t));
3679 model_list = g_slist_append(model_list,
3683 BT_INFO("MESH: Network Join bt-service");
3684 //result = BLUETOOTH_ERROR_NONE;
3685 result = _bt_mesh_network_join(requester_unique_creds,
3686 sender, &node, model_list);
3687 if (result != BLUETOOTH_ERROR_NONE) {
3688 g_array_append_vals(*out_param1, &node, sizeof(bluetooth_mesh_node_t));
3689 BT_ERR("Mesh: Mesh Join Network schedule failed");
3690 g_slist_free_full(model_list, g_free);
3693 BT_INFO("return of _bt_mesh_network_join : [%d]", result);
3696 case BT_MESH_CANCEL_JOIN: {
3697 bluetooth_mesh_node_info_t node;
3698 memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t));
3700 __bt_service_get_parameters(in_param1,
3701 &node, sizeof(bluetooth_mesh_node_info_t));
3703 BT_INFO("Mesh: Cancel Join request");
3704 result = _bt_mesh_cancel_join(requester_unique_creds,
3706 if (result != BLUETOOTH_ERROR_NONE) {
3707 g_array_append_vals(*out_param1,
3708 &node, sizeof(bluetooth_mesh_node_t));
3712 case BT_MESH_NETWORK_SCAN: {
3713 bluetooth_mesh_network_t network;
3714 bluetooth_mesh_scan_param_t param;
3715 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3716 memset(¶m, 0x00, sizeof(bluetooth_mesh_scan_param_t));
3718 __bt_service_get_parameters(in_param1,
3719 &network, sizeof(bluetooth_mesh_network_t));
3721 __bt_service_get_parameters(in_param2,
3722 ¶m, sizeof(bluetooth_mesh_scan_param_t));
3724 result = _bt_mesh_network_scan(requester_unique_creds,
3725 sender, &network, ¶m);
3727 if (result != BLUETOOTH_ERROR_NONE) {
3728 g_array_append_vals(*out_param1,
3729 &network, sizeof(bluetooth_mesh_network_t));
3731 bluetooth_mesh_network_t *net = \
3732 g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3734 sender = (char*)g_dbus_method_invocation_get_sender(context);
3735 _bt_save_invocation_context(context, result, sender,
3736 function_name, (gpointer)net);
3740 case BT_MESH_NETWORK_CANCEL_SCAN: {
3741 bluetooth_mesh_network_t network;
3742 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3744 __bt_service_get_parameters(in_param1,
3745 &network, sizeof(bluetooth_mesh_network_t));
3747 result = _bt_mesh_network_scan_cancel(requester_unique_creds,
3750 if (result != BLUETOOTH_ERROR_NONE)
3751 g_array_append_vals(*out_param1,
3752 &network, sizeof(bluetooth_mesh_network_t));
3755 case BT_MESH_NETWORK_SET_CAPABILITIES: {
3756 bluetooth_mesh_network_t network;
3757 bluetooth_mesh_provisioner_caps_t caps;
3758 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3759 memset(&caps, 0x00, sizeof(bluetooth_mesh_provisioner_caps_t));
3761 __bt_service_get_parameters(in_param1,
3762 &network, sizeof(bluetooth_mesh_network_t));
3764 __bt_service_get_parameters(in_param2,
3765 &caps, sizeof(bluetooth_mesh_provisioner_caps_t));
3767 result = _bt_mesh_network_set_provisioner_caps(
3768 requester_unique_creds, sender, &network, &caps);
3772 case BT_MESH_NETWORK_PROVISION_DEVICE: {
3773 bluetooth_mesh_provisioning_request_t req;
3774 memset(&req, 0x00, sizeof(bluetooth_mesh_provisioning_request_t));
3776 __bt_service_get_parameters(in_param1,
3777 &req, sizeof(bluetooth_mesh_provisioning_request_t));
3779 BT_INFO("Mesh: Provision Device UUID [%s]", req.dev_uuid);
3780 BT_INFO("Mesh: Provision Device in network[%s]", req.net_uuid);
3782 result = _bt_mesh_network_provision_device(
3783 requester_unique_creds, sender, &req);
3785 /* Save invocation */
3786 if (result != BLUETOOTH_ERROR_NONE) {
3787 g_array_append_vals(*out_param1, &req,
3788 sizeof(bluetooth_mesh_provisioning_request_t));
3790 bluetooth_mesh_provisioning_request_t *param = \
3791 g_memdup(&req, sizeof(bluetooth_mesh_provisioning_request_t));
3793 sender = (char*)g_dbus_method_invocation_get_sender(context);
3794 _bt_save_invocation_context(context, result, sender,
3795 function_name, (gpointer)param);
3799 case BT_MESH_AUTHENTICATION_REPLY: {
3800 BT_INFO("Mesh: BT_MESH_AUTHENTICATION_REPLY");
3801 const char *auth_value = NULL;
3802 gboolean authentication_reply = FALSE;
3804 auth_value = g_variant_get_data(in_param2);
3805 __bt_service_get_parameters(in_param3,
3806 &authentication_reply, sizeof(gboolean));
3807 __bt_service_get_parameters(in_param1,
3808 &auth_type, sizeof(int));
3809 BT_INFO("Mesh: Auth Reply Type [%d]", auth_type);
3810 BT_INFO("Mesh: Auth Value [%s]", auth_value);
3811 BT_INFO("Mesh: Auth Accept [%d]", authentication_reply);
3812 result = _bt_mesh_authentication_reply(auth_type,
3813 auth_value, authentication_reply);
3816 case BT_MESH_NETWORK_SET_NAME: {
3817 bluetooth_mesh_network_t network;
3818 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3820 __bt_service_get_parameters(in_param1,
3821 &network, sizeof(bluetooth_mesh_network_t));
3823 result = _bt_mesh_network_set_name(requester_unique_creds, sender, &network);
3827 case BT_MESH_NETWORK_ADD_NETKEY: {
3828 bluetooth_mesh_network_t network;
3829 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3831 __bt_service_get_parameters(in_param1,
3832 &network, sizeof(bluetooth_mesh_network_t));
3834 result = _bt_mesh_network_add_netkey(requester_unique_creds,
3837 if (result != BLUETOOTH_ERROR_NONE) {
3838 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3840 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3842 sender = (char*)g_dbus_method_invocation_get_sender(context);
3843 _bt_save_invocation_context(context, result, sender,
3844 function_name, (gpointer)net);
3848 case BT_MESH_NETWORK_DELETE_NETKEY: {
3849 bluetooth_mesh_network_t network;
3852 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3854 __bt_service_get_parameters(in_param1,
3855 &network, sizeof(bluetooth_mesh_network_t));
3856 __bt_service_get_parameters(in_param2,
3857 &index, sizeof(guint16));
3859 result = _bt_mesh_network_delete_netkey(requester_unique_creds,
3860 sender, &network, index);
3862 if (result != BLUETOOTH_ERROR_NONE) {
3863 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3865 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3867 sender = (char*)g_dbus_method_invocation_get_sender(context);
3868 _bt_save_invocation_context(context, result, sender,
3869 function_name, (gpointer)net);
3873 case BT_MESH_NETWORK_UPDATE_NETKEY: {
3874 bluetooth_mesh_network_t network;
3877 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3879 __bt_service_get_parameters(in_param1,
3880 &network, sizeof(bluetooth_mesh_network_t));
3881 __bt_service_get_parameters(in_param2,
3882 &index, sizeof(guint16));
3884 result = _bt_mesh_network_update_netkey(requester_unique_creds,
3885 sender, &network, index);
3887 if (result != BLUETOOTH_ERROR_NONE) {
3888 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3890 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3892 sender = (char*)g_dbus_method_invocation_get_sender(context);
3893 _bt_save_invocation_context(context, result, sender,
3894 function_name, (gpointer)net);
3898 case BT_MESH_NETWORK_ADD_APPKEY: {
3899 bluetooth_mesh_network_t network;
3902 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3904 __bt_service_get_parameters(in_param1,
3905 &network, sizeof(bluetooth_mesh_network_t));
3906 __bt_service_get_parameters(in_param2,
3907 &net_idx, sizeof(guint16));
3909 result = _bt_mesh_network_add_appkey(requester_unique_creds,
3910 sender, &network, net_idx);
3912 if (result != BLUETOOTH_ERROR_NONE) {
3913 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3915 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3917 sender = (char*)g_dbus_method_invocation_get_sender(context);
3918 _bt_save_invocation_context(context, result, sender,
3919 function_name, (gpointer)net);
3923 case BT_MESH_NETWORK_UPDATE_APPKEY: {
3924 bluetooth_mesh_network_t network;
3928 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3930 __bt_service_get_parameters(in_param1,
3931 &network, sizeof(bluetooth_mesh_network_t));
3932 __bt_service_get_parameters(in_param2,
3933 &net_idx, sizeof(guint16));
3934 __bt_service_get_parameters(in_param3,
3935 &app_idx, sizeof(guint16));
3937 result = _bt_mesh_network_update_appkey(requester_unique_creds,
3938 sender, &network, net_idx, app_idx);
3940 if (result != BLUETOOTH_ERROR_NONE) {
3941 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3943 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3945 sender = (char*)g_dbus_method_invocation_get_sender(context);
3946 _bt_save_invocation_context(context, result, sender,
3947 function_name, (gpointer)net);
3951 case BT_MESH_NETWORK_DELETE_APPKEY: {
3952 bluetooth_mesh_network_t network;
3956 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3958 __bt_service_get_parameters(in_param1,
3959 &network, sizeof(bluetooth_mesh_network_t));
3960 __bt_service_get_parameters(in_param2,
3961 &net_idx, sizeof(guint16));
3962 __bt_service_get_parameters(in_param3,
3963 &app_idx, sizeof(guint16));
3965 result = _bt_mesh_network_delete_appkey(requester_unique_creds,
3966 sender, &network, net_idx, app_idx);
3968 if (result != BLUETOOTH_ERROR_NONE) {
3969 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3971 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3973 sender = (char*)g_dbus_method_invocation_get_sender(context);
3974 _bt_save_invocation_context(context, result, sender,
3975 function_name, (gpointer)net);
3979 case BT_MESH_NETWORK_GET_NETKEYS: {
3980 bluetooth_mesh_network_t network;
3981 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3982 __bt_service_get_parameters(in_param1,
3983 &network, sizeof(bluetooth_mesh_network_t));
3984 result = _bt_mesh_network_get_netkeys(requester_unique_creds,
3985 sender, &network, out_param1);
3988 case BT_MESH_NETWORK_GET_APPKEYS: {
3989 bluetooth_mesh_network_t network;
3992 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3993 __bt_service_get_parameters(in_param1,
3994 &network, sizeof(bluetooth_mesh_network_t));
3995 __bt_service_get_parameters(in_param2,
3996 &net_idx, sizeof(guint16));
3997 result = _bt_mesh_network_get_appkeys(
3998 requester_unique_creds, sender,
3999 &network, net_idx, out_param1);
4002 case BT_MESH_NETWORK_GET_NODES: {
4003 bluetooth_mesh_network_t network;
4004 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4005 __bt_service_get_parameters(in_param1,
4006 &network, sizeof(bluetooth_mesh_network_t));
4007 result = _bt_mesh_network_get_nodes(
4008 requester_unique_creds, sender,
4009 &network, out_param1);
4012 case BT_MESH_ELEMENT_GET_MODELS: {
4013 bluetooth_mesh_network_t network;
4017 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4018 __bt_service_get_parameters(in_param1,
4019 &network, sizeof(bluetooth_mesh_network_t));
4020 __bt_service_get_parameters(in_param2,
4021 &node_addr, sizeof(guint16));
4022 __bt_service_get_parameters(in_param3,
4023 &elem_idx, sizeof(int));
4024 result = _bt_mesh_element_get_models(requester_unique_creds, sender,
4025 &network, node_addr, elem_idx, out_param1);
4028 case BT_MESH_NODE_BROWSE: {
4029 bluetooth_mesh_node_discover_t req;
4030 memset(&req, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4032 __bt_service_get_parameters(in_param1,
4033 &req, sizeof(bluetooth_mesh_node_discover_t));
4035 result = _bt_mesh_browse_remote_node(
4036 requester_unique_creds, sender, &req);
4038 /* Save invocation */
4039 if (result != BLUETOOTH_ERROR_NONE) {
4040 g_array_append_vals(*out_param1, &req,
4041 sizeof(bluetooth_mesh_node_discover_t));
4043 bluetooth_mesh_node_discover_t *param = \
4044 g_memdup(&req, sizeof(bluetooth_mesh_node_discover_t));
4046 sender = (char*)g_dbus_method_invocation_get_sender(context);
4047 _bt_save_invocation_context(context, result, sender,
4048 function_name, (gpointer)param);
4052 case BT_MESH_NODE_GET_VENDOR_FEATURES: {
4053 bluetooth_mesh_node_features_t req;
4054 memset(&req, 0x00, sizeof(bluetooth_mesh_node_features_t));
4056 __bt_service_get_parameters(in_param1,
4057 &req, sizeof(bluetooth_mesh_node_features_t));
4059 result = _bt_mesh_node_discover_vendor_features(
4060 requester_unique_creds, sender, &req);
4062 /* Save invocation */
4063 if (result != BLUETOOTH_ERROR_NONE) {
4064 g_array_append_vals(*out_param1,
4065 &req, sizeof(bluetooth_mesh_node_features_t));
4067 bluetooth_mesh_node_features_t *param = \
4068 g_memdup(&req, sizeof(bluetooth_mesh_node_features_t));
4070 sender = (char*)g_dbus_method_invocation_get_sender(context);
4071 _bt_save_invocation_context(context, result, sender,
4072 function_name, (gpointer)param);
4076 case BT_MESH_NODE_CONFIGURE_KEY: {
4077 bluetooth_mesh_key_configure_t req;
4079 memset(&req, 0x00, sizeof(bluetooth_mesh_key_configure_t));
4081 __bt_service_get_parameters(in_param1,
4082 &req, sizeof(bluetooth_mesh_key_configure_t));
4084 result = _bt_mesh_node_configure_key(
4085 requester_unique_creds, sender, &req);
4087 /* Save invocation */
4088 if (result != BLUETOOTH_ERROR_NONE) {
4089 g_array_append_vals(*out_param1,
4090 &req, sizeof(bluetooth_mesh_key_configure_t));
4092 bluetooth_mesh_key_configure_t *param = \
4093 g_memdup(&req, sizeof(bluetooth_mesh_key_configure_t));
4095 sender = (char*)g_dbus_method_invocation_get_sender(context);
4096 _bt_save_invocation_context(context, result, sender,
4097 function_name, (gpointer)param);
4101 case BT_MESH_NODE_TTL_EXECUTE: {
4102 bluetooth_mesh_node_ttl_info_t req;
4104 memset(&req, 0x00, sizeof(bluetooth_mesh_node_ttl_info_t));
4106 __bt_service_get_parameters(in_param1,
4107 &req, sizeof(bluetooth_mesh_node_ttl_info_t));
4109 result = _bt_mesh_ttl_execute_remote_node(
4110 requester_unique_creds, sender, &req);
4112 /* Save invocation */
4113 if (result != BLUETOOTH_ERROR_NONE) {
4114 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_node_ttl_info_t));
4116 bluetooth_mesh_node_ttl_info_t *param = \
4117 g_memdup(&req, sizeof(bluetooth_mesh_node_ttl_info_t));
4119 sender = (char*)g_dbus_method_invocation_get_sender(context);
4120 _bt_save_invocation_context(context, result, sender,
4121 function_name, (gpointer)param);
4125 case BT_MESH_MODEL_CONFIGURE_APPKEY: {
4126 bluetooth_mesh_model_configure_t req;
4128 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4130 __bt_service_get_parameters(in_param1,
4131 &req, sizeof(bluetooth_mesh_model_configure_t));
4133 result = _bt_mesh_node_model_appkey_execute(
4134 requester_unique_creds, sender, &req);
4136 /* Save invocation */
4137 if (result != BLUETOOTH_ERROR_NONE) {
4138 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4140 bluetooth_mesh_model_configure_t *param = \
4141 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4143 sender = (char*)g_dbus_method_invocation_get_sender(context);
4144 _bt_save_invocation_context(context, result, sender,
4145 function_name, (gpointer)param);
4149 case BT_MESH_MODEL_EXECUTE_MSG: {
4150 bluetooth_mesh_model_msg_t req;
4152 memset(&req, 0x00, sizeof(bluetooth_mesh_model_msg_t));
4154 __bt_service_get_parameters(in_param1,
4155 &req, sizeof(bluetooth_mesh_model_msg_t));
4157 result = _bt_mesh_model_execute_msg(
4158 requester_unique_creds, sender, &req);
4160 /* Save invocation */
4161 if (result != BLUETOOTH_ERROR_NONE) {
4162 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_msg_t));
4164 bluetooth_mesh_model_msg_t *param = \
4165 g_memdup(&req, sizeof(bluetooth_mesh_model_msg_t));
4167 sender = (char*)g_dbus_method_invocation_get_sender(context);
4168 _bt_save_invocation_context(context, result, sender,
4169 function_name, (gpointer)param);
4173 case BT_MESH_MODEL_RESPONSE_MSG: {
4174 bluetooth_mesh_model_msg_t req;
4175 memset(&req, 0x00, sizeof(bluetooth_mesh_model_msg_t));
4176 __bt_service_get_parameters(in_param1,
4177 &req, sizeof(bluetooth_mesh_model_msg_t));
4179 result = _bt_mesh_model_send_response(
4180 requester_unique_creds, sender, &req);
4181 if (result != BLUETOOTH_ERROR_NONE)
4182 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_msg_t));
4185 case BT_MESH_NODE_GET_NETKEYS: {
4186 bluetooth_mesh_node_discover_t node;
4187 memset(&node, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4188 __bt_service_get_parameters(in_param1,
4189 &node, sizeof(bluetooth_mesh_node_discover_t));
4190 result = _bt_mesh_network_node_get_netkeys(
4191 requester_unique_creds, &node, out_param1);
4194 case BT_MESH_NODE_GET_APPKEYS: {
4195 bluetooth_mesh_node_discover_t node;
4196 memset(&node, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4197 __bt_service_get_parameters(in_param1,
4198 &node, sizeof(bluetooth_mesh_node_discover_t));
4199 result = _bt_mesh_network_node_get_appkeys(
4200 requester_unique_creds, sender, &node, out_param1);
4203 case BT_MESH_NODE_RESET: {
4204 bluetooth_mesh_node_info_t node;
4205 memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t));
4207 __bt_service_get_parameters(in_param1,
4208 &node, sizeof(bluetooth_mesh_node_info_t));
4210 BT_INFO("Mesh: Reset the Node");
4211 result = _bt_mesh_network_reset_node(requester_unique_creds,
4216 case BT_MESH_MODEL_GET_APPKEY_LIST: {
4217 bluetooth_mesh_model_configure_t req;
4219 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4221 __bt_service_get_parameters(in_param1,
4222 &req, sizeof(bluetooth_mesh_model_configure_t));
4224 result = _bt_mesh_node_model_get_appkey_list(
4225 requester_unique_creds, sender, &req);
4227 /* Save invocation */
4228 if (result != BLUETOOTH_ERROR_NONE) {
4229 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4231 bluetooth_mesh_model_configure_t *param = \
4232 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4234 sender = (char*)g_dbus_method_invocation_get_sender(context);
4235 _bt_save_invocation_context(context, result, sender,
4236 function_name, (gpointer)param);
4240 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST: {
4241 bluetooth_mesh_model_configure_t req;
4243 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4245 __bt_service_get_parameters(in_param1,
4246 &req, sizeof(bluetooth_mesh_model_configure_t));
4248 result = _bt_mesh_node_model_get_subscription_list(
4249 requester_unique_creds, sender, &req);
4251 /* Save invocation */
4252 if (result != BLUETOOTH_ERROR_NONE) {
4253 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4255 bluetooth_mesh_model_configure_t *param = \
4256 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4258 sender = (char*)g_dbus_method_invocation_get_sender(context);
4259 _bt_save_invocation_context(context, result, sender,
4260 function_name, (gpointer)param);
4265 case BT_MESH_NETWORK_CREATE_GROUP: {
4266 bluetooth_mesh_network_t net;
4267 bluetooth_mesh_network_group_info_t res;
4268 gboolean is_virtual;
4271 memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
4272 memset(&res, 0x00, sizeof(bluetooth_mesh_network_group_info_t));
4274 __bt_service_get_parameters(in_param1,
4275 &net, sizeof(bluetooth_mesh_network_t));
4276 __bt_service_get_parameters(in_param2,
4277 &is_virtual, sizeof(gboolean));
4278 __bt_service_get_parameters(in_param3,
4279 &grp_addr, sizeof(guint16));
4281 result = _bt_mesh_network_create_group(
4282 requester_unique_creds, sender, &net,
4283 is_virtual, grp_addr, &res);
4285 if (result == BLUETOOTH_ERROR_NONE)
4286 g_array_append_vals(*out_param1, &res,
4287 sizeof(bluetooth_mesh_network_group_info_t));
4290 case BT_MESH_NETWORK_REMOVE_GROUP: {
4291 bluetooth_mesh_network_t net;
4292 bluetooth_mesh_network_group_info_t req;
4294 memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
4295 memset(&req, 0x00, sizeof(bluetooth_mesh_network_group_info_t));
4297 __bt_service_get_parameters(in_param1,
4298 &net, sizeof(bluetooth_mesh_network_t));
4299 __bt_service_get_parameters(in_param2,
4300 &req, sizeof(bluetooth_mesh_network_group_info_t));
4302 result = _bt_mesh_network_remove_group(
4303 requester_unique_creds, sender, &net, &req);
4307 case BT_MESH_MODEL_CONFIG_GROUP_SUB: {
4308 bluetooth_mesh_model_configure_t req;
4310 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4312 __bt_service_get_parameters(in_param1,
4313 &req, sizeof(bluetooth_mesh_model_configure_t));
4315 result = _bt_mesh_model_configure_group_subscription(
4316 requester_unique_creds, sender, &req);
4318 /* Save invocation */
4319 if (result != BLUETOOTH_ERROR_NONE) {
4320 g_array_append_vals(*out_param1,
4321 &req, sizeof(bluetooth_mesh_model_configure_t));
4323 bluetooth_mesh_model_configure_t *param = \
4324 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4326 sender = (char*)g_dbus_method_invocation_get_sender(context);
4327 _bt_save_invocation_context(context, result, sender,
4328 function_name, (gpointer)param);
4332 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB: {
4333 bluetooth_mesh_model_configure_t req;
4335 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4337 __bt_service_get_parameters(in_param1,
4338 &req, sizeof(bluetooth_mesh_model_configure_t));
4340 result = _bt_mesh_model_configure_virtual_group_subscription(
4341 requester_unique_creds, sender, &req);
4343 /* Save invocation */
4344 if (result != BLUETOOTH_ERROR_NONE) {
4345 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4347 bluetooth_mesh_model_configure_t *param = \
4348 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4350 sender = (char*)g_dbus_method_invocation_get_sender(context);
4351 _bt_save_invocation_context(context, result, sender,
4352 function_name, (gpointer)param);
4356 case BT_MESH_MODEL_SET_PUBLICATION: {
4357 bluetooth_mesh_model_configure_t req;
4359 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4361 __bt_service_get_parameters(in_param1,
4362 &req, sizeof(bluetooth_mesh_model_configure_t));
4364 result = _bt_mesh_model_set_publication(
4365 requester_unique_creds, sender, &req);
4367 /* Save invocation */
4368 if (result != BLUETOOTH_ERROR_NONE) {
4369 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4371 bluetooth_mesh_model_configure_t *param = g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4373 sender = (char*)g_dbus_method_invocation_get_sender(context);
4374 _bt_save_invocation_context(context, result, sender,
4375 function_name, (gpointer)param);
4379 case BT_MESH_MODEL_GET_PUBLICATION: {
4380 bluetooth_mesh_model_configure_t req;
4382 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4384 __bt_service_get_parameters(in_param1,
4385 &req, sizeof(bluetooth_mesh_model_configure_t));
4387 result = _bt_mesh_model_get_publication(
4388 requester_unique_creds, sender, &req);
4390 /* Save invocation */
4391 if (result != BLUETOOTH_ERROR_NONE) {
4392 g_array_append_vals(*out_param1,
4393 &req, sizeof(bluetooth_mesh_model_configure_t));
4395 bluetooth_mesh_model_configure_t *param = \
4396 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4398 sender = (char*)g_dbus_method_invocation_get_sender(context);
4399 _bt_save_invocation_context(context, result, sender,
4400 function_name, (gpointer)param);
4404 case BT_MESH_NETWORK_GET_GROUPS: {
4405 bluetooth_mesh_network_t network;
4406 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4407 __bt_service_get_parameters(in_param1,
4408 &network, sizeof(bluetooth_mesh_network_t));
4409 BT_INFO("Mesh: Request:: Get Groups");
4410 result = _bt_mesh_network_get_groups(
4411 requester_unique_creds, sender, &network, out_param1);
4415 BT_INFO("UnSupported function [%d]", function_name);
4416 result = BLUETOOTH_ERROR_NOT_SUPPORT;
4422 #ifdef TIZEN_FEATURE_BT_OBEX
4423 /* Function definitions*/
4424 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
4429 size = g_variant_get_size(var);
4431 data = (char *)g_variant_get_data(var);
4433 param = g_array_append_vals(param, data, size);
4439 int __bt_obexd_request(int function_name,
4442 GDBusMethodInvocation *context,
4443 GVariant *in_param1,
4444 GVariant *in_param2,
4445 GVariant *in_param3,
4446 GVariant *in_param4,
4447 GArray **out_param1)
4451 int result = BLUETOOTH_ERROR_NONE;
4453 BT_DBG("function_name : %x", function_name);
4455 switch (function_name) {
4456 case BT_OPP_PUSH_FILES: {
4457 BT_DBG("BT_OPP_PUSH_FILES");
4459 bluetooth_device_address_t address = { {0} };
4460 bt_file_path_t *path;
4465 __bt_service_get_parameters(in_param1, &address,
4466 sizeof(bluetooth_device_address_t));
4467 __bt_service_get_parameters(in_param3, &file_count,
4470 file_path = g_new0(char *, file_count + 1);
4472 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
4473 __bt_fill_garray_from_variant(in_param2, param2);
4475 for (i = 0; i < file_count; i++) {
4476 path = &g_array_index(param2, bt_file_path_t, i);
4477 file_path[i] = g_strdup(path->path);
4479 BT_DBG("_bt_opp_client_push_files");
4480 result = _bt_opp_client_push_files(request_id, context,
4481 &address, file_path,
4484 for (i = 0; i < file_count; i++)
4485 g_free(file_path[i]);
4488 g_array_free(param2, TRUE);
4492 case BT_OPP_CANCEL_PUSH: {
4493 result = _bt_opp_client_cancel_push();
4497 case BT_OPP_IS_PUSHING_FILES: {
4498 gboolean is_sending = FALSE;
4500 result = _bt_opp_client_is_sending(&is_sending);
4502 g_array_append_vals(*out_param1, &is_sending,
4506 case BT_OPP_GET_TRANSFER_PROGRESS: {
4509 guint8 progress = 0;
4511 __bt_service_get_parameters(in_param1, &direction,
4513 __bt_service_get_parameters(in_param2, &transfer_id,
4516 result = _bt_opp_get_client_progress(&progress);
4518 result = _bt_opp_get_server_progress(transfer_id, &progress);
4520 g_array_append_vals(*out_param1, &progress,
4526 case BT_MAP_CREATE_SESSION: {
4527 BT_DBG("BT_MAP_CREATE_SESSION");
4528 char *address = (char *)g_variant_get_data(in_param1);
4529 char *session_id = NULL;
4530 result = _bt_create_session_sync(address, &session_id);
4531 if (result == BLUETOOTH_ERROR_NONE)
4532 g_array_append_vals(*out_param1, session_id, strlen(session_id)+1);
4536 case BT_MAP_DESTROY_SESSION: {
4537 BT_DBG("BT_MAP_DESTROY_SESSION");
4538 char* session_id = (char *)g_variant_get_data(in_param1);
4539 result = _bt_destroy_session_sync(session_id);
4540 if (result == BLUETOOTH_ERROR_NONE)
4541 BT_DBG("successfully destroyed session");
4545 case BT_MAP_SET_FOLDER: {
4546 BT_DBG("BT_MAP_SET_FOLDER");
4547 char *session_id = (char *)g_variant_get_data(in_param1);
4548 char *name = (char *)g_variant_get_data(in_param2);
4549 result = _bt_map_client_set_folder(session_id, name);
4553 case BT_MAP_LIST_FOLDERS: {
4554 BT_DBG("BT_MAP_LIST_FOLDERS");
4556 char* session_id = (char *)g_variant_get_data(in_param1);
4557 char* filter_serialized = (char*)g_variant_get_data(in_param2);
4559 result = _bt_map_client_list_folders(request_id, context, session_id, filter_serialized);
4560 if (result == BLUETOOTH_ERROR_NONE)
4561 BT_DBG("_bt_map_client_list_folders succeed");
4566 case BT_MAP_LIST_FILTER_FIELDS: {
4567 BT_DBG("BT_MAP_LIST_FILTER_FIELDS");
4569 char* session_id = (char *)g_variant_get_data(in_param1);
4571 result = _bt_map_client_list_filter_fields(request_id, context, session_id);
4572 if (result == BLUETOOTH_ERROR_NONE)
4573 BT_DBG("_bt_map_client_list_filter_fields succeed");
4578 case BT_MAP_LIST_MESSAGES: {
4579 BT_DBG("BT_MAP_LIST_MESSAGES");
4581 char* session_id = (char*)g_variant_get_data(in_param1);
4582 char* folder = (char*)g_variant_get_data(in_param2);
4583 char* filter_serialized = (char*)g_variant_get_data(in_param3);
4585 result = _bt_map_client_list_messages(request_id, context, session_id, folder, filter_serialized);
4586 if (result == BLUETOOTH_ERROR_NONE)
4587 BT_DBG("_bt_map_client_list_messages succeed");
4589 BT_DBG("_bt_map_client_list_messages failed");
4594 case BT_MAP_UPDATE_INBOX: {
4595 BT_DBG("BT_MAP_UPDATE_INBOX");
4596 char* session_id = (char *)g_variant_get_data(in_param1);
4597 result = _bt_map_client_update_inbox(session_id);
4601 case BT_MAP_PUSH_MESSAGE: {
4602 BT_DBG("BT_MAP_PUSH_MESSAGE");
4604 char* session_id = (char *)g_variant_get_data(in_param1);
4605 char* source_file = (char *)g_variant_get_data(in_param2);
4606 char* folder = (char *)g_variant_get_data(in_param3);
4607 char* args_serialized = (char *)g_variant_get_data(in_param4);
4609 result = _bt_map_client_push_message(
4610 request_id, context, session_id, source_file, folder, args_serialized);
4611 if (result == BLUETOOTH_ERROR_NONE)
4612 BT_DBG("_bt_map_client_push_message succeed");
4614 BT_ERR("_bt_map_client_push_message failed");
4619 case BT_MAP_GET_MESSAGE: {
4620 BT_DBG("BT_MAP_GET_MESSAGE");
4621 // TODO session currently is not used, but should be valid
4622 //char* session_id = (char *)g_variant_get_data(in_param1);
4623 char* message_object = (char *)g_variant_get_data(in_param2);
4624 char* target_file = (char *)g_variant_get_data(in_param3);
4625 bool attachment = false;
4626 __bt_service_get_parameters(in_param4, &attachment, sizeof(bool));
4628 result = _bt_map_client_get_message(request_id, context, message_object,
4629 target_file, attachment);
4630 if (result == BLUETOOTH_ERROR_NONE)
4631 BT_DBG("_bt_map_client_get_message succeed");
4636 case BT_OBEX_SERVER_ALLOCATE: {
4642 sender = (char *)g_dbus_method_invocation_get_sender(context);
4644 path = (char *)g_variant_get_data(in_param1);
4645 __bt_service_get_parameters(in_param2, &is_native,
4647 __bt_service_get_parameters(in_param3, &app_pid,
4650 result = _bt_obex_server_allocate(sender,
4651 path, app_pid, is_native);
4655 case BT_OBEX_SERVER_DEALLOCATE: {
4659 __bt_service_get_parameters(in_param1, &is_native,
4661 __bt_service_get_parameters(in_param2, &app_pid,
4664 result = _bt_obex_server_deallocate(app_pid, is_native);
4667 case BT_OBEX_SERVER_IS_ACTIVATED: {
4668 gboolean is_activated = FALSE;
4670 result = _bt_obex_server_is_activated(&is_activated);
4672 g_array_append_vals(*out_param1, &is_activated,
4677 case BT_OBEX_SERVER_ACCEPT_CONNECTION: {
4678 result = _bt_obex_server_accept_connection(request_id);
4682 case BT_OBEX_SERVER_REJECT_CONNECTION: {
4683 result = _bt_obex_server_reject_connection();
4687 case BT_OBEX_SERVER_ACCEPT_FILE: {
4690 file_name = (char *)g_variant_get_data(in_param1);
4692 result = _bt_obex_server_accept_authorize(file_name, TRUE);
4696 case BT_OBEX_SERVER_REJECT_FILE: {
4697 result = _bt_obex_server_reject_authorize();
4701 case BT_OBEX_SERVER_SET_PATH: {
4703 char *destination_path;
4705 destination_path = (char *)g_variant_get_data(in_param1);
4706 __bt_service_get_parameters(in_param2, &is_native,
4709 result = _bt_obex_server_set_destination_path(destination_path,
4714 case BT_OBEX_SERVER_SET_ROOT: {
4717 root = (char *)g_variant_get_data(in_param1);
4719 result = _bt_obex_server_set_root(root);
4723 case BT_OBEX_SERVER_CANCEL_TRANSFER: {
4726 __bt_service_get_parameters(in_param1, &transfer_id,
4729 result = _bt_obex_server_cancel_transfer(transfer_id);
4733 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS: {
4734 result = _bt_obex_server_cancel_all_transfers();
4738 case BT_OBEX_SERVER_IS_RECEIVING: {
4739 gboolean is_receiving = FALSE;
4741 result = _bt_obex_server_is_receiving(&is_receiving);
4743 g_array_append_vals(*out_param1, &is_receiving,
4747 case BT_PBAP_CONNECT: {
4748 bluetooth_device_address_t address = { {0} };
4750 __bt_service_get_parameters(in_param1, &address,
4751 sizeof(bluetooth_device_address_t));
4753 result = _bt_pbap_connect(&address);
4756 case BT_PBAP_DISCONNECT: {
4757 bluetooth_device_address_t address = { {0} };
4759 __bt_service_get_parameters(in_param1, &address,
4760 sizeof(bluetooth_device_address_t));
4762 result = _bt_pbap_disconnect(&address);
4765 case BT_PBAP_GET_PHONEBOOK_SIZE: {
4766 bluetooth_device_address_t address = { {0} };
4767 bt_pbap_folder_t folder = { 0, };
4769 __bt_service_get_parameters(in_param1, &address,
4770 sizeof(bluetooth_device_address_t));
4771 __bt_service_get_parameters(in_param2, &folder,
4772 sizeof(bt_pbap_folder_t));
4774 result = _bt_pbap_get_phonebook_size(&address,
4775 folder.addressbook, folder.folder_type);
4778 case BT_PBAP_GET_PHONEBOOK: {
4779 bluetooth_device_address_t address = { {0} };
4780 bt_pbap_folder_t folder = { 0, };
4781 bt_pbap_pull_parameters_t app_param = { 0, };
4783 __bt_service_get_parameters(in_param1, &address,
4784 sizeof(bluetooth_device_address_t));
4785 __bt_service_get_parameters(in_param2, &folder,
4786 sizeof(bt_pbap_folder_t));
4787 __bt_service_get_parameters(in_param3, &app_param,
4788 sizeof(bt_pbap_pull_parameters_t));
4790 result = _bt_pbap_get_phonebook(&address, folder.addressbook,
4791 folder.folder_type, &app_param);
4794 case BT_PBAP_GET_LIST: {
4795 bluetooth_device_address_t address = { {0} };
4796 bt_pbap_folder_t folder = { 0, };
4797 bt_pbap_list_parameters_t app_param = { 0, };
4799 __bt_service_get_parameters(in_param1, &address,
4800 sizeof(bluetooth_device_address_t));
4801 __bt_service_get_parameters(in_param2, &folder,
4802 sizeof(bt_pbap_folder_t));
4803 __bt_service_get_parameters(in_param3, &app_param,
4804 sizeof(bt_pbap_list_parameters_t));
4806 result = _bt_pbap_get_list(&address, folder.addressbook,
4807 folder.folder_type, &app_param);
4810 case BT_PBAP_PULL_VCARD: {
4811 bluetooth_device_address_t address = { {0} };
4812 bt_pbap_folder_t folder = { 0, };
4813 bt_pbap_pull_vcard_parameters_t app_param = { 0, };
4815 __bt_service_get_parameters(in_param1, &address,
4816 sizeof(bluetooth_device_address_t));
4817 __bt_service_get_parameters(in_param2, &folder,
4818 sizeof(bt_pbap_folder_t));
4819 __bt_service_get_parameters(in_param3, &app_param,
4820 sizeof(bt_pbap_pull_vcard_parameters_t));
4822 result = _bt_pbap_pull_vcard(&address, folder.addressbook,
4823 folder.folder_type, &app_param);
4826 case BT_PBAP_PHONEBOOK_SEARCH: {
4827 bluetooth_device_address_t address = { {0} };
4828 bt_pbap_folder_t folder = { 0, };
4829 bt_pbap_search_parameters_t app_param = { 0, };
4831 __bt_service_get_parameters(in_param1, &address,
4832 sizeof(bluetooth_device_address_t));
4833 __bt_service_get_parameters(in_param2, &folder,
4834 sizeof(bt_pbap_folder_t));
4835 __bt_service_get_parameters(in_param3, &app_param,
4836 sizeof(bt_pbap_search_parameters_t));
4838 result = _bt_pbap_phonebook_search(&address, folder.addressbook,
4839 folder.folder_type, &app_param);
4844 BT_ERR("Unknown function!");
4845 result = BLUETOOTH_ERROR_INTERNAL;
4854 int __bt_agent_request(int function_name,
4857 GDBusMethodInvocation *context,
4858 GVariant *in_param1,
4859 GVariant *in_param2,
4860 GVariant *in_param3,
4861 GVariant *in_param4,
4862 GArray **out_param1)
4865 switch (function_name) {
4866 case BT_SET_AUTHORIZATION: {
4873 sender = (char *)g_dbus_method_invocation_get_sender(context);
4874 __bt_service_get_parameters(in_param1, &type, sizeof(int));
4875 uuid = (char *)g_variant_get_data(in_param2);
4876 path = (char *)g_variant_get_data(in_param3);
4877 __bt_service_get_parameters(in_param4, &fd, sizeof(int));
4879 result = _bt_register_osp_server_in_agent(sender, type, uuid, path, fd);
4882 case BT_UNSET_AUTHORIZATION: {
4886 __bt_service_get_parameters(in_param1, &type, sizeof(int));
4887 uuid = (char *)g_variant_get_data(in_param2);
4889 result = _bt_unregister_osp_server_in_agent(type, uuid);
4893 BT_ERR("Unknown function!");
4894 result = BLUETOOTH_ERROR_INTERNAL;
4901 int __bt_core_request(int function_name,
4904 GDBusMethodInvocation *context,
4905 GVariant *in_param1)
4909 switch (function_name) {
4910 case BT_ENABLE_ADAPTER:
4913 _bt_set_adapter_request_state(TRUE);
4914 status = _bt_adapter_get_status();
4916 if (status == BT_ACTIVATING) {
4917 BT_DBG("Enabling in progress");
4918 result = BLUETOOTH_ERROR_IN_PROGRESS;
4919 } else if (status == BT_ACTIVATED) {
4920 BT_DBG("Already enabled");
4921 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
4923 _bt_adapter_set_status(BT_ACTIVATING);
4924 result = BLUETOOTH_ERROR_NONE;
4929 case BT_DISABLE_ADAPTER:
4933 status = _bt_adapter_get_status();
4934 if (status == BT_DEACTIVATING) {
4935 BT_DBG("Disabling in progress");
4936 result = BLUETOOTH_ERROR_IN_PROGRESS;
4937 } else if (status == BT_DEACTIVATED) {
4938 BT_DBG("Already disabled");
4939 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
4941 _bt_adapter_set_status(BT_DEACTIVATING);
4942 result = BLUETOOTH_ERROR_NONE;
4947 case BT_ENABLE_ADAPTER_LE:
4949 bt_le_status_t le_status;
4950 _bt_set_le_request_state(TRUE);
4951 le_status = _bt_adapter_get_le_status();
4952 if (le_status == BT_LE_ACTIVATING) {
4953 BT_DBG("Enabling in progress");
4954 result = BLUETOOTH_ERROR_IN_PROGRESS;
4955 } else if (le_status == BT_LE_ACTIVATED) {
4956 BT_DBG("Already enabled");
4957 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
4959 _bt_adapter_set_le_status(BT_LE_ACTIVATING);
4960 result = BLUETOOTH_ERROR_NONE;
4965 case BT_DISABLE_ADAPTER_LE:
4967 bt_le_status_t le_status;
4969 le_status = _bt_adapter_get_le_status();
4970 if (le_status == BT_LE_DEACTIVATING) {
4971 BT_DBG("Disabling in progress");
4972 result = BLUETOOTH_ERROR_IN_PROGRESS;
4973 } else if (le_status == BT_LE_DEACTIVATED) {
4974 BT_DBG("Already disabled");
4975 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
4977 _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
4978 result = BLUETOOTH_ERROR_NONE;
4984 BT_ERR("Unknown function!");
4985 result = BLUETOOTH_ERROR_INTERNAL;
4992 static int __bt_service_get_requester_app_id(const char *unique_name, char *app_id, int len)
4997 retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
4998 retv_if(unique_name == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
5000 ret = __bt_service_get_sender_pid(unique_name, &pid);
5001 if (ret != BLUETOOTH_ERROR_NONE) {
5002 BT_ERR("Fail to get the sender pid");
5006 ret = aul_app_get_appid_bypid(pid, app_id, len);
5007 if (ret != AUL_R_OK) {
5008 BT_ERR("app_id not found");
5009 return BLUETOOTH_ERROR_NOT_SUPPORT;
5011 BT_DBG("Sender app_id: %s", app_id);
5013 return BLUETOOTH_ERROR_NONE;
5016 #ifdef TIZEN_FEATURE_BT_CONTAINER
5017 static void __bt_service_free_nspid(struct nspid_t *nspid)
5019 g_free(nspid->unique_name);
5023 static void __bt_service_cleanup_nspid_list(const char *unique_name)
5026 struct nspid_t *nspid;
5028 for (l = nspid_list; l; l = g_slist_next(l)) {
5032 if (!g_strcmp0(nspid->unique_name, unique_name)) {
5033 nspid_list = g_slist_remove(nspid_list, nspid);
5034 __bt_service_free_nspid(nspid);
5040 static gboolean __bt_service_is_container_request(const char *unique_name)
5044 char path[1024], buf[1024];
5046 gboolean is_container = FALSE;
5048 struct nspid_t *nspid;
5050 for (l = nspid_list; l; l = g_slist_next(l)) {
5054 if (!g_strcmp0(nspid->unique_name, unique_name))
5055 return nspid->is_container;
5058 ret = __bt_service_get_sender_pid(unique_name, &pid);
5059 if (ret != BLUETOOTH_ERROR_NONE)
5062 sprintf(path, "/proc/%d/status", pid);
5063 fp = fopen(path, "r");
5065 BT_ERR("fopen() failed. %d(%s)", errno, strerror(errno));
5069 while (fgets(buf, sizeof(buf), fp)) {
5070 if (strstr(buf, "NSpid:")) {
5071 char *p = strchr(buf + 7, '\t'); /* find 2nd '\t' */
5073 BT_DBG("caller is container process");
5074 is_container = TRUE;
5082 nspid = g_malloc0(sizeof(struct nspid_t));
5083 nspid->unique_name = g_strdup(unique_name);
5084 nspid->is_container = is_container;
5085 nspid_list = g_slist_append(nspid_list, nspid);
5087 return is_container;
5091 gboolean __bt_service_check_privilege(int function_name,
5093 const char *unique_name)
5096 gboolean result = TRUE;
5097 char *client_creds = NULL;
5098 char *user_creds = NULL;
5099 char *client_session = "";
5100 enum cynara_client_creds client_creds_method = CLIENT_METHOD_SMACK;
5101 enum cynara_user_creds user_creds_method = USER_METHOD_UID;
5102 char err_msg[256] = {0, };
5104 retv_if(unique_name == NULL, FALSE);
5105 retv_if(bt_service_conn == NULL, FALSE);
5107 #ifdef TIZEN_FEATURE_BT_CONTAINER
5108 /* Privilege will be checked in container if the request is from container */
5109 if (__bt_service_is_container_request(unique_name)) {
5110 BT_DBG("This request is from container, temporarily allow");
5115 ret_val = cynara_creds_get_default_client_method(&client_creds_method);
5116 if (ret_val != CYNARA_API_SUCCESS) {
5117 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5118 BT_ERR("Fail to get default client method: %s", err_msg);
5122 ret_val = cynara_creds_get_default_user_method(&user_creds_method);
5123 if (ret_val != CYNARA_API_SUCCESS) {
5124 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5125 BT_ERR("Fail to get default user method: %s", err_msg);
5129 ret_val = cynara_creds_gdbus_get_client(bt_service_conn, unique_name, client_creds_method, &client_creds);
5130 if (ret_val != CYNARA_API_SUCCESS) {
5131 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5132 BT_ERR("Fail to get client credential: %s", err_msg);
5136 ret_val = cynara_creds_gdbus_get_user(bt_service_conn, unique_name, user_creds_method, &user_creds);
5137 if (ret_val != CYNARA_API_SUCCESS) {
5138 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5139 BT_ERR("Fail to get user credential: %s", err_msg);
5145 BT_DBG("%s, %s, %s", unique_name, client_creds, user_creds);
5147 switch (function_name) {
5148 case BT_SET_LOCAL_NAME:
5149 case BT_START_DISCOVERY:
5150 case BT_START_CUSTOM_DISCOVERY:
5151 case BT_CANCEL_DISCOVERY:
5152 case BT_OOB_ADD_REMOTE_DATA:
5153 case BT_OOB_REMOVE_REMOTE_DATA:
5154 case BT_OOB_READ_LOCAL_DATA:
5155 case BT_SET_ADVERTISING:
5156 case BT_SET_CUSTOM_ADVERTISING:
5157 case BT_SET_ADVERTISING_PARAMETERS:
5158 case BT_START_LE_DISCOVERY:
5159 case BT_STOP_LE_DISCOVERY:
5160 case BT_SET_SCAN_PARAMETERS:
5161 case BT_SET_SCAN_TYPE:
5162 case BT_UPDATE_LE_CONNECTION_MODE:
5164 case BT_BOND_DEVICE:
5165 case BT_CANCEL_BONDING:
5166 case BT_UNBOND_DEVICE:
5168 case BT_SET_AUTHORIZATION:
5169 case BT_UNSET_AUTHORIZATION:
5170 case BT_SEARCH_SERVICE:
5172 case BT_RFCOMM_CLIENT_CONNECT:
5173 if (function_name == BT_RFCOMM_CLIENT_CONNECT)
5174 BT_PERMANENT_LOG("Connect socket");
5175 case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
5176 case BT_RFCOMM_SOCKET_DISCONNECT:
5177 if (function_name == BT_RFCOMM_SOCKET_DISCONNECT)
5178 BT_PERMANENT_LOG("Disconnect socket");
5179 case BT_RFCOMM_SOCKET_WRITE:
5180 case BT_RFCOMM_CREATE_SOCKET:
5181 case BT_RFCOMM_REMOVE_SOCKET:
5182 case BT_RFCOMM_SEND_RX_DETAILS:
5183 case BT_RFCOMM_SEND_TX_DETAILS:
5184 case BT_RFCOMM_UPDATE_CONNECTION_INFO:
5186 case BT_OPP_PUSH_FILES:
5187 case BT_OPP_CANCEL_PUSH:
5188 /* TODO: MAP? MAP functions, see above */
5190 case BT_OBEX_SERVER_ACCEPT_CONNECTION:
5191 case BT_OBEX_SERVER_REJECT_CONNECTION:
5192 case BT_OBEX_SERVER_ACCEPT_FILE:
5193 case BT_OBEX_SERVER_REJECT_FILE:
5194 case BT_OBEX_SERVER_SET_PATH:
5195 case BT_OBEX_SERVER_SET_ROOT:
5196 case BT_OBEX_SERVER_CANCEL_TRANSFER:
5197 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS:
5199 case BT_AUDIO_SELECT_ROLE:
5200 case BT_AUDIO_CONNECT:
5201 case BT_AUDIO_DISCONNECT:
5203 case BT_AG_DISCONNECT:
5205 case BT_AV_DISCONNECT:
5206 case BT_AV_SOURCE_CONNECT:
5207 case BT_AV_SOURCE_DISCONNECT:
5208 case BT_AVRCP_TARGET_CONNECT:
5209 case BT_AVRCP_TARGET_DISCONNECT:
5210 case BT_AVRCP_CONTROL_CONNECT:
5211 case BT_AVRCP_CONTROL_DISCONNECT:
5212 case BT_AVRCP_HANDLE_CONTROL:
5213 case BT_AVRCP_SET_TRACK_INFO:
5214 case BT_AVRCP_SET_PROPERTY:
5215 case BT_AVRCP_SET_PROPERTIES:
5216 case BT_AVRCP_CONTROL_SET_PROPERTY:
5218 case BT_AUDIO_SET_ABSOLUTE_VOLUME:
5219 case BT_AUDIO_GET_ABSOLUTE_VOLUME:
5220 case BT_AUDIO_IS_AVC_ACTIVATED:
5223 case BT_HF_DISCONNECT:
5225 case BT_HID_CONNECT:
5226 case BT_HID_DISCONNECT:
5228 case BT_HID_DEVICE_ACTIVATE:
5229 case BT_HID_DEVICE_DEACTIVATE:
5230 case BT_HID_DEVICE_CONNECT:
5231 case BT_HID_DEVICE_DISCONNECT:
5232 case BT_HID_DEVICE_SEND_MOUSE_EVENT:
5233 case BT_HID_DEVICE_SEND_KEY_EVENT:
5234 case BT_HID_DEVICE_SEND_REPLY_TO_REPORT:
5235 case BT_HID_DEVICE_SEND_CUSTOM_EVENT:
5238 case BT_DISCONNECT_LE:
5240 case BT_SET_ADVERTISING_DATA:
5241 case BT_SET_SCAN_RESPONSE_DATA:
5243 case BT_HDP_CONNECT:
5244 case BT_HDP_DISCONNECT:
5245 case BT_HDP_SEND_DATA:
5246 case BT_HDP_REGISTER_SINK_APP:
5247 case BT_HDP_UNREGISTER_SINK_APP:
5250 case BT_DPM_SET_ALLOW_BT_MODE:
5251 case BT_DPM_GET_ALLOW_BT_MODE:
5252 case BT_DPM_SET_DEVICE_RESTRITION:
5253 case BT_DPM_GET_DEVICE_RESTRITION:
5254 case BT_DPM_SET_UUID_RESTRITION:
5255 case BT_DPM_GET_UUID_RESTRITION:
5256 case BT_DPM_ADD_DEVICES_BLACKLIST:
5257 case BT_DPM_ADD_DEVICES_WHITELIST:
5258 case BT_DPM_ADD_UUIDS_BLACKLIST:
5259 case BT_DPM_ADD_UUIDS_WHITELIST:
5260 case BT_DPM_CLEAR_DEVICES_BLACKLIST:
5261 case BT_DPM_CLEAR_DEVICES_WHITELIST:
5262 case BT_DPM_CLEAR_UUIDS_BLACKLIST:
5263 case BT_DPM_CLEAR_UUIDS_WHITELIST:
5264 case BT_DPM_REMOVE_DEVICE_BLACKLIST:
5265 case BT_DPM_REMOVE_DEVICE_WHITELIST:
5266 case BT_DPM_REMOVE_UUID_BLACKLIST:
5267 case BT_DPM_REMOVE_UUID_WHITELIST:
5268 case BT_DPM_GET_DEVICES_BLACKLIST:
5269 case BT_DPM_GET_DEVICES_WHITELIST:
5270 case BT_DPM_GET_UUIDS_BLACKLIST:
5271 case BT_DPM_GET_UUIDS_WHITELIST:
5272 case BT_DPM_SET_ALLOW_OUTGOING_CALL:
5273 case BT_DPM_GET_ALLOW_OUTGOING_CALL:
5274 case BT_DPM_SET_PAIRING_STATE:
5275 case BT_DPM_GET_PAIRING_STATE:
5276 case BT_DPM_SET_PROFILE_STATE:
5277 case BT_DPM_GET_PROFILE_STATE:
5278 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE:
5279 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE:
5280 case BT_DPM_SET_DISCOVERABLE_STATE:
5281 case BT_DPM_GET_DISCOVERABLE_STATE:
5282 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE:
5283 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE:
5284 case BT_DPM_SET_DATA_TRANSFER_STATE:
5285 case BT_DPM_GET_DATA_TRANSFER_STATE:
5287 case BT_NETWORK_ACTIVATE:
5288 case BT_NETWORK_DEACTIVATE:
5289 case BT_NETWORK_CONNECT:
5290 case BT_NETWORK_DISCONNECT:
5291 case BT_NETWORK_SERVER_DISCONNECT:
5293 case BT_GATT_GET_PRIMARY_SERVICES:
5294 case BT_GATT_GET_SERVICE_PROPERTIES: /* GATT Client */
5295 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: /* GATT Client */
5296 case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: /* GATT Client */
5297 case BT_GATT_DISCOVER_CHARACTERISTICS:
5298 case BT_GATT_SET_PROPERTY_REQUEST:
5299 case BT_GATT_READ_CHARACTERISTIC:
5300 case BT_GATT_READ_DESCRIPTOR_VALUE: /* GATT Client */
5301 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: /* GATT Client */
5302 case BT_GATT_ACQUIRE_WRITE:
5303 case BT_GATT_WRITE_DESCRIPTOR_VALUE: /* GATT Client */
5304 case BT_GATT_WATCH_CHARACTERISTIC: /* GATT Client */
5305 case BT_GATT_CLIENT_REGISTER: /* GATT Client */
5306 case BT_GATT_CLIENT_UNREGISTER: /* GATT Client */
5307 case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
5308 case BT_GATT_REGISTER_APPLICATION:
5309 case BT_GATT_REGISTER_SERVICE:
5310 case BT_GATT_SEND_RESPONSE:
5312 case BT_GATT_SERVER_REGISTER:
5313 case BT_GATT_SERVER_ADD_SERVICE:
5314 case BT_GATT_SERVER_ADD_CHARACTERISTIC:
5315 case BT_GATT_SERVER_ADD_DESCRIPTOR:
5316 case BT_GATT_SERVER_START_SERVICE:
5317 case BT_GATT_SERVER_STOP_SERVICE:
5318 case BT_GATT_SERVER_DELETE_SERVICE:
5319 case BT_GATT_SERVER_SEND_RESPONSE:
5320 case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE:
5321 case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE:
5322 case BT_GATT_SERVER_SEND_INDICATION:
5323 case BT_GATT_SERVER_UPDATE_VALUE:
5324 case BT_GATT_SERVER_DEREGISTER:
5326 case BT_REQ_ATT_MTU:
5327 case BT_PBAP_CONNECT:
5328 case BT_PBAP_DISCONNECT:
5329 case BT_PBAP_GET_PHONEBOOK_SIZE:
5330 case BT_PBAP_GET_PHONEBOOK:
5331 case BT_PBAP_GET_LIST:
5332 case BT_PBAP_PULL_VCARD:
5333 case BT_PBAP_PHONEBOOK_SEARCH:
5335 case BT_RFCOMM_LISTEN_AND_ACCEPT:
5337 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5338 BT_PRIVILEGE_PUBLIC);
5340 BT_INFO("Client Credentials [%s]", client_creds);
5341 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5342 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PUBLIC);
5346 /* Need to check mediastorage privilege */
5347 if (function_name == BT_PBAP_GET_PHONEBOOK ||
5348 function_name == BT_PBAP_PULL_VCARD) {
5349 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5350 MEDIASTORAGE_PRIVILEGE);
5352 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5353 BT_ERR("Fail to access: %s", MEDIASTORAGE_PRIVILEGE);
5359 case BT_ENABLE_ADAPTER:
5360 case BT_DISABLE_ADAPTER:
5361 case BT_RESET_ADAPTER:
5362 case BT_RECOVER_ADAPTER:
5363 case BT_BATTERY_READ_DATA:
5364 case BT_ENABLE_ADAPTER_LE:
5365 case BT_DISABLE_ADAPTER_LE:
5366 case BT_SET_CONNECTABLE:
5367 case BT_SET_DISCOVERABLE_MODE:
5368 case BT_ADD_WHITE_LIST:
5369 case BT_REMOVE_WHITE_LIST:
5370 case BT_CLEAR_WHITE_LIST:
5371 case BT_SET_MANUFACTURER_DATA:
5373 case BT_CANCEL_SEARCH_SERVICE:
5374 case BT_ENABLE_RSSI:
5375 case BT_DISCONNECT_DEVICE:
5377 case BT_RFCOMM_ACCEPT_CONNECTION:
5378 case BT_RFCOMM_REJECT_CONNECTION:
5379 case BT_RFCOMM_LISTEN:
5381 case BT_HID_ENABLE_BARCODE_FEATURE:
5383 case BT_AVRCP_TRANSPORT_SET_PROPERTY:
5384 case BT_AVRCP_HANDLE_CONTROL_TO_DEST:
5386 case BT_SET_CONTENT_PROTECT:
5387 case BT_BOND_DEVICE_BY_TYPE:
5388 case BT_SET_LE_PRIVACY:
5389 case BT_SET_LE_STATIC_RANDOM_ADDRESS:
5390 case BT_LE_CONN_UPDATE:
5391 case BT_GET_DEVICE_IDA:
5392 case BT_LE_READ_MAXIMUM_DATA_LENGTH:
5393 case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH:
5394 case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH:
5395 case BT_LE_SET_DATA_LENGTH:
5396 case BT_LE_OOB_READ_LOCAL_DATA:
5397 case BT_LE_OOB_ADD_REMOTE_DATA:
5399 case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS:
5400 case BT_ENABLE_GATT_DATA_BATCHING:
5401 case BT_DISABLE_GATT_DATA_BATCHING:
5403 case BT_LE_IPSP_INIT:
5404 case BT_LE_IPSP_DEINIT:
5405 case BT_LE_IPSP_CONNECT:
5406 case BT_LE_IPSP_DISCONNECT:
5407 case BT_PXP_MONITOR_SET_PROPERTY:
5408 case BT_PXP_MONITOR_GET_PROPERTY:
5409 case BT_PXP_MONITOR_GET_SUPPORTED_SERIVCES:
5410 case BT_PXP_REPORTER_REGISTER:
5411 case BT_PXP_REPORTER_UNREGISTER:
5412 case BT_PXP_REPORTER_GET_PROPERTY:
5415 case BT_TDS_PROVIDER_REGISTER:
5416 case BT_TDS_PROVIDER_UNREGISTER:
5417 case BT_TDS_PROVIDER_SET_MANUF_DATA:
5418 case BT_TDS_PROVIDER_CREATE:
5419 case BT_TDS_PROVIDER_DESTROY:
5420 case BT_TDS_PROVIDER_SET_TRANSPORT_DATA:
5421 case BT_TDS_SEND_ACTIVATION_RESPONSE:
5422 case BT_TDS_READ_TRANSPORT_DATA:
5423 case BT_TDS_ENABLE_CONTROL_POINT:
5424 case BT_TDS_ACTIVATE_CONTROL_POINT:
5427 case BT_OTP_SERVER_INIT:
5428 case BT_OTP_SERVER_DEINIT:
5429 case BT_OTP_READ_VALUE:
5430 case BT_OTP_ENABLE_NOTIFICATION:
5431 case BT_OTP_WRITE_VALUE:
5432 case BT_LE_OTC_CONNECT:
5433 case BT_LE_OTC_DISCONNECT:
5435 case BT_MAP_CREATE_SESSION:
5436 case BT_MAP_DESTROY_SESSION:
5437 case BT_MAP_SET_FOLDER:
5438 case BT_MAP_LIST_FOLDERS:
5439 case BT_MAP_LIST_FILTER_FIELDS:
5440 case BT_MAP_LIST_MESSAGES:
5441 case BT_MAP_UPDATE_INBOX:
5442 case BT_MAP_PUSH_MESSAGE:
5443 case BT_MAP_GET_MESSAGE:
5446 case BT_MESH_DEINIT:
5447 case BT_MESH_NETWORK_CREATE:
5448 case BT_MESH_NETWORK_DESTROY:
5449 case BT_MESH_NETWORK_LOAD:
5450 case BT_MESH_NETWORK_UNLOAD:
5451 case BT_MESH_NETWORK_JOIN:
5452 case BT_MESH_CANCEL_JOIN:
5453 case BT_MESH_NETWORK_SCAN:
5454 case BT_MESH_NETWORK_CANCEL_SCAN:
5455 case BT_MESH_NETWORK_SET_CAPABILITIES:
5456 case BT_MESH_NETWORK_PROVISION_DEVICE:
5457 case BT_MESH_AUTHENTICATION_REPLY:
5458 case BT_MESH_NETWORK_SET_NAME:
5459 case BT_MESH_NETWORK_ADD_NETKEY:
5460 case BT_MESH_NETWORK_DELETE_NETKEY:
5461 case BT_MESH_NETWORK_UPDATE_NETKEY:
5462 case BT_MESH_NETWORK_ADD_APPKEY:
5463 case BT_MESH_NETWORK_DELETE_APPKEY:
5464 case BT_MESH_NETWORK_UPDATE_APPKEY:
5465 case BT_MESH_NETWORK_GET_NETKEYS:
5466 case BT_MESH_NETWORK_GET_APPKEYS:
5467 case BT_MESH_NETWORK_GET_NODES:
5468 case BT_MESH_ELEMENT_GET_MODELS:
5469 case BT_MESH_NODE_BROWSE:
5470 case BT_MESH_NODE_GET_VENDOR_FEATURES:
5471 case BT_MESH_NODE_CONFIGURE_KEY:
5472 case BT_MESH_NODE_TTL_EXECUTE:
5473 case BT_MESH_NODE_GET_NETKEYS:
5474 case BT_MESH_NODE_GET_APPKEYS:
5475 case BT_MESH_NODE_RESET:
5476 case BT_MESH_MODEL_CONFIGURE_APPKEY:
5477 case BT_MESH_MODEL_GET_APPKEY_LIST:
5478 case BT_MESH_MODEL_EXECUTE_MSG:
5479 case BT_MESH_MODEL_RESPONSE_MSG:
5480 case BT_MESH_NETWORK_CREATE_GROUP:
5481 case BT_MESH_NETWORK_REMOVE_GROUP:
5482 case BT_MESH_MODEL_CONFIG_GROUP_SUB:
5483 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB:
5484 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST:
5485 case BT_MESH_MODEL_SET_PUBLICATION:
5486 case BT_MESH_MODEL_GET_PUBLICATION:
5487 case BT_MESH_NETWORK_GET_GROUPS:
5489 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5490 BT_PRIVILEGE_PLATFORM);
5492 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5493 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PLATFORM);
5498 case BT_CHECK_ADAPTER:
5501 case BT_GET_LOCAL_NAME:
5502 case BT_GET_LOCAL_ADDRESS:
5503 case BT_GET_LOCAL_VERSION:
5504 case BT_IS_SERVICE_USED:
5505 case BT_GET_DISCOVERABLE_MODE:
5506 case BT_GET_DISCOVERABLE_TIME:
5507 case BT_IS_DISCOVERYING:
5508 case BT_IS_LE_DISCOVERYING:
5509 case BT_IS_CONNECTABLE:
5510 case BT_GET_CONNECTABLE:
5511 case BT_GET_BONDED_DEVICES:
5512 case BT_GET_PROFILE_CONNECTED_DEVICES:
5513 case BT_GET_BONDED_DEVICE:
5514 case BT_PASSKEY_REPLY:
5515 case BT_PASSKEY_CONFIRMATION_REPLY:
5516 case BT_GET_IS_ALIAS_SET:
5517 case BT_IS_DEVICE_CONNECTED:
5518 case BT_GET_CONNECTED_LINK_TYPE:
5519 case BT_SET_PROFILE_TRUSTED:
5520 case BT_GET_PROFILE_TRUSTED:
5521 case BT_GET_SPEAKER_GAIN:
5522 case BT_SET_SPEAKER_GAIN:
5523 case BT_RFCOMM_CLIENT_IS_CONNECTED:
5524 case BT_RFCOMM_IS_UUID_AVAILABLE:
5525 case BT_GET_ADVERTISING_DATA:
5526 case BT_GET_SCAN_RESPONSE_DATA:
5527 case BT_IS_ADVERTISING:
5528 case BT_IS_LE_2M_PHY_SUPPORTED:
5529 case BT_IS_LE_CODED_PHY_SUPPORTED:
5530 case BT_REGISTER_SCAN_FILTER:
5531 case BT_IS_SCAN_FILTER_SUPPORTED:
5532 case BT_GET_ATT_MTU:
5534 case BT_OBEX_SERVER_ALLOCATE:
5535 case BT_OBEX_SERVER_DEALLOCATE:
5536 case BT_OBEX_SERVER_IS_ACTIVATED:
5537 case BT_OPP_GET_TRANSFER_PROGRESS:
5538 case BT_AVRCP_CONTROL_GET_PROPERTY:
5539 case BT_AVRCP_GET_TRACK_INFO:
5540 /* Non-privilege control */
5543 BT_ERR("Unknown function!");
5548 if (function_name >= BT_FUNC_MESH_BASE) {
5549 BT_INFO("MESH Function called");
5550 char app_id[256] = { 0, };
5552 if (BLUETOOTH_ERROR_NONE == __bt_service_get_requester_app_id(unique_name,
5553 app_id, sizeof(app_id))) {
5554 requester_unique_creds = g_strdup(app_id);
5556 BT_DBG("Requester app_id not found, use client creds");
5557 requester_unique_creds = g_strdup(client_creds);
5559 BT_DBG("Requester unique_creds: %s", requester_unique_creds);
5561 BT_INFO("Non MESH Function called client creds [%s]", client_creds);
5573 GDBusNodeInfo *__bt_service_create_method_node_info
5574 (const gchar *introspection_data)
5577 GDBusNodeInfo *node_info = NULL;
5579 if (introspection_data == NULL) {
5580 BT_ERR("Introspection XML not present");
5584 node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
5587 BT_ERR("Unable to create node: %s", err->message);
5588 g_clear_error(&err);
5593 int __bt_service_register_object(GDBusConnection *conn,
5594 GDBusNodeInfo *node_info, gboolean reg)
5596 static guint service_id = 0;
5597 GError *error = NULL;
5600 if (node_info == NULL)
5603 service_id = g_dbus_connection_register_object(conn,
5605 node_info->interfaces[0],
5607 NULL, NULL, &error);
5608 if (service_id == 0)
5611 if (service_id > 0) {
5612 g_dbus_connection_unregister_object(conn,
5621 static void __name_owner_changed(GDBusConnection *connection,
5622 const gchar *sender_name,
5623 const gchar *object_path,
5624 const gchar *interface_name,
5625 const gchar *signal_name,
5626 GVariant *parameters,
5629 const char *name = NULL;
5630 const char *old_owner = NULL;
5631 const char *new_owner = NULL;
5633 g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
5634 if (*new_owner != '\0')
5637 _bt_check_hdp_app_termination(name);
5639 /* Advertising App Termination */
5640 _bt_check_adv_app_termination(name);
5642 /* Check if le_scanning app is terminated */
5643 _bt_check_le_scanner_app_termination(name);
5645 /* Check if RFCOMM app is terminated */
5646 _bt_rfcomm_check_termination(name);
5648 /* Mesh App Termination */
5649 _bt_check_mesh_app_termination(name);
5651 /* Stop the Transport Discovery service */
5652 _bt_tds_stop_by_terminated_process(name);
5654 #ifdef TIZEN_FEATURE_BT_CONTAINER
5655 /* Cleanup the NSpid list */
5656 __bt_service_cleanup_nspid_list(name);
5660 static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
5661 const gchar *name, gpointer user_data)
5663 GDBusNodeInfo *node_info = NULL;
5665 BT_INFO("bus acquired");
5667 ret_if(connection == NULL);
5669 node_info = __bt_service_create_method_node_info(
5670 bt_service_introspection_xml);
5671 ret_if(node_info == NULL);
5673 __bt_service_register_object(connection, node_info, TRUE);
5674 g_dbus_node_info_unref(node_info);
5676 bt_service_conn = connection;
5679 static void __bt_service_name_acquired_handler(GDBusConnection *connection,
5680 const gchar *name, gpointer user_data)
5682 BT_INFO("name acquired");
5683 name_acquired = TRUE;
5686 static void __bt_service_name_lost_handler(GDBusConnection *connection,
5687 const gchar *name, gpointer user_data)
5689 BT_INFO("name lost");
5690 name_acquired = FALSE;
5693 gboolean _is_name_acquired(void)
5695 return name_acquired;
5698 void _bt_service_unref_connection(void)
5702 if (bt_service_conn) {
5703 g_dbus_connection_flush_sync(bt_service_conn, NULL, NULL);
5704 g_object_unref(bt_service_conn);
5705 bt_service_conn = NULL;
5711 int _bt_service_register(void)
5713 GDBusConnection *conn;
5716 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
5717 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
5718 bt_service_conn = conn;
5720 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
5722 G_BUS_NAME_OWNER_FLAGS_NONE,
5723 __bt_service_bus_acquired_handler,
5724 __bt_service_name_acquired_handler,
5725 __bt_service_name_lost_handler,
5727 BT_DBG("owner_id is [%d]", owner_id);
5731 /* Subscribe for name owner changed signal */
5732 owner_sig_id = g_dbus_connection_signal_subscribe(conn,
5733 BT_FREEDESKTOP_SERVICE, BT_FREEDESKTOP_INTERFACE,
5734 BT_NAME_OWNER_CHANGED, NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
5735 __name_owner_changed, NULL, NULL);
5736 BT_INFO("owner_sig_id: %d", owner_sig_id);
5738 return BLUETOOTH_ERROR_NONE;
5741 if (bt_service_conn) {
5742 g_object_unref(bt_service_conn);
5743 bt_service_conn = NULL;
5746 return BLUETOOTH_ERROR_INTERNAL;
5749 void _bt_service_unregister(void)
5751 if (bt_service_conn) {
5752 sd_notify(0, "STOPPING=1");
5754 if (owner_sig_id > 0) {
5755 g_dbus_connection_signal_unsubscribe(
5756 bt_service_conn, owner_sig_id);
5761 g_bus_unown_name(owner_id);
5765 __bt_service_register_object(bt_service_conn, NULL, FALSE);
5768 #ifdef TIZEN_FEATURE_BT_CONTAINER
5770 g_slist_free_full(nspid_list, (GDestroyNotify)__bt_service_free_nspid);
5776 int _bt_service_cynara_init(void)
5779 char err_msg[256] = {0, };
5781 retv_if(p_cynara != NULL, BLUETOOTH_ERROR_ALREADY_INITIALIZED);
5783 result = cynara_initialize(&p_cynara, conf);
5785 if (result != CYNARA_API_SUCCESS) {
5786 cynara_strerror(result, err_msg, sizeof(err_msg));
5787 BT_ERR("Fail to initialize cynara: [%s]", err_msg);
5788 return BLUETOOTH_ERROR_INTERNAL;
5791 return BLUETOOTH_ERROR_NONE;
5794 void _bt_service_cynara_deinit(void)
5797 char err_msg[256] = {0, };
5799 ret_if(p_cynara == NULL);
5801 result = cynara_finish(p_cynara);
5803 if (result != CYNARA_API_SUCCESS) {
5804 cynara_strerror(result, err_msg, sizeof(err_msg));
5805 BT_ERR("Fail to finish cynara: [%s]", err_msg);
5813 void _bt_service_method_return(GDBusMethodInvocation *invocation,
5814 GArray *out_param, int result)
5818 out_var = g_variant_new_from_data((const GVariantType *)"ay",
5819 out_param->data, out_param->len, TRUE, NULL, NULL);
5821 g_dbus_method_invocation_return_value(invocation,
5822 g_variant_new("(iv)", result, out_var));
5825 void _bt_service_method_return_with_unix_fd_list(GDBusMethodInvocation *invocation,
5826 GArray *out_param, int result, GUnixFDList *fd_list)
5830 out_var = g_variant_new_from_data((const GVariantType *)"ay",
5831 out_param->data, out_param->len, TRUE, NULL, NULL);
5833 g_dbus_method_invocation_return_value_with_unix_fd_list(invocation,
5834 g_variant_new("(iv)", result, out_var), fd_list);