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 static GDBusConnection *bt_service_conn;
76 static guint owner_id = 0;
77 static guint owner_sig_id = 0;
78 static gboolean is_le_intended = FALSE;
80 static cynara *p_cynara;
81 static cynara_configuration *conf;
82 static const char *requester_unique_creds = NULL;
84 static const gchar bt_service_introspection_xml[] =
85 "<node name='/org/projectx/bt_service'>"
86 " <interface name='org.projectx.bt'>"
87 " <method name='service_request'>"
88 /* Input Parameters */
89 " <arg type='i' name='service_type' direction='in' />"
90 " <arg type='i' name='service_function' direction='in' />"
91 " <arg type='i' name='request_type' direction='in' />"
92 " <arg type='ay' name='input_param1' direction='in' />"
93 " <arg type='ay' name='input_param2' direction='in' />"
94 " <arg type='ay' name='input_param3' direction='in' />"
95 " <arg type='ay' name='input_param4' direction='in' />"
96 " <arg type='ay' name='input_param5' direction='in' />"
97 /* Return Parameters */
98 " <arg type='i' name='output_param1' direction='out' />"
99 " <arg type='v' name='output_param2' direction='out' />"
101 " <method name='get_avc_mode'>"
103 " <arg type='u' name='avc_mode' direction='out' />"
108 static gboolean name_acquired = FALSE;
110 static char *current_sender_playing = NULL;
112 GDBusNodeInfo *node_info_g = NULL;
114 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param);
116 static void __bt_service_method(GDBusConnection *connection,
118 const gchar *object_path,
119 const gchar *interface_name,
120 const gchar *method_name,
121 GVariant *parameters,
122 GDBusMethodInvocation *invocation,
125 int __bt_bluez_request(int function_name,
128 GDBusMethodInvocation *context,
133 GArray **out_param1);
134 int __bt_obexd_request(int function_name,
137 GDBusMethodInvocation *context,
142 GArray **out_param1);
143 int __bt_agent_request(int function_name,
146 GDBusMethodInvocation *context,
151 GArray **out_param1);
152 int __bt_core_request(int function_name,
155 GDBusMethodInvocation *context,
156 GVariant *in_param1);
158 gboolean __bt_service_check_privilege(int function_name,
160 const char *unique_name);
162 /* Function definitions*/
163 GSList *_bt_get_invocation_list(void)
165 return invocation_list;
168 void _bt_free_info_from_invocation_list(invocation_info_t *req_info)
170 ret_if(NULL == req_info);
171 invocation_list = g_slist_remove(invocation_list, req_info);
172 g_free(req_info->sender);
173 g_free(req_info->user_data);
177 void _bt_set_le_intended_status(gboolean value)
179 is_le_intended = value;
182 static void __bt_service_get_parameters(GVariant *in_param,
183 void *value, int size)
186 buf = (void *)g_variant_get_data(in_param);
187 memcpy(value, buf, size);
190 static gboolean __bt_is_sync_function(int service_function)
192 /*TODO: Keep adding sync methods with expect replies from bluetooth service */
193 if (service_function == BT_GET_LOCAL_ADDRESS
194 || service_function == BT_GET_LOCAL_NAME
195 || service_function == BT_GET_LOCAL_VERSION
196 || service_function == BT_GET_BONDED_DEVICES
197 || service_function == BT_GET_BONDED_DEVICE
198 || service_function == BT_GET_PROFILE_CONNECTED_DEVICES
199 || service_function == BT_GET_IS_ALIAS_SET
200 || service_function == BT_GET_CONNECTED_LINK_TYPE
201 || service_function == BT_IS_SERVICE_USED
202 || service_function == BT_RFCOMM_LISTEN_AND_ACCEPT
203 || service_function == BT_RFCOMM_LISTEN
204 || service_function == BT_HDP_REGISTER_SINK_APP
205 || service_function == BT_HDP_UNREGISTER_SINK_APP
206 || service_function == BT_HDP_GET_FD
207 || service_function == BT_AVRCP_GET_TRACK_INFO
208 || service_function == BT_AVRCP_CONTROL_GET_PROPERTY
209 || service_function == BT_SET_ADVERTISING_DATA
210 || service_function == BT_SET_SCAN_RESPONSE_DATA
211 || service_function == BT_SET_ADVERTISING
212 || service_function == BT_SET_CUSTOM_ADVERTISING
213 || service_function == BT_GATT_SERVER_REGISTER
214 || service_function == BT_GATT_SERVER_ADD_SERVICE
215 || service_function == BT_GATT_SERVER_ADD_CHARACTERISTIC
216 || service_function == BT_GATT_SERVER_ADD_DESCRIPTOR
217 || service_function == BT_GATT_SERVER_START_SERVICE
218 || service_function == BT_GATT_SERVER_STOP_SERVICE
219 || service_function == BT_GATT_SERVER_DELETE_SERVICE
220 || service_function == BT_START_LE_DISCOVERY
221 || service_function == BT_STOP_LE_DISCOVERY
222 || service_function == BT_GET_CONNECTABLE
223 || service_function == BT_GATT_CLIENT_REGISTER
224 || service_function == BT_GATT_GET_PRIMARY_SERVICES
225 || service_function == BT_GATT_GET_SERVICE_PROPERTIES
226 || service_function == BT_GATT_GET_INCLUDED_SERVICES
227 || service_function == BT_GATT_GET_CHARACTERISTIC_PROPERTIES
228 || service_function == BT_GATT_WATCH_CHARACTERISTIC
229 || service_function == BT_GATT_ACQUIRE_WRITE
230 || service_function == BT_AUDIO_SELECT_ROLE
232 || service_function == BT_MESH_INIT
233 || service_function == BT_MESH_NETWORK_CREATE
234 || service_function == BT_MESH_NETWORK_DESTROY
235 || service_function == BT_MESH_NETWORK_LOAD
236 || service_function == BT_MESH_NETWORK_SCAN
237 || service_function == BT_MESH_NETWORK_ADD_NETKEY
238 || service_function == BT_MESH_NETWORK_DELETE_NETKEY
239 || service_function == BT_MESH_NETWORK_UPDATE_NETKEY
240 || service_function == BT_MESH_NETWORK_ADD_APPKEY
241 || service_function == BT_MESH_NETWORK_DELETE_APPKEY
242 || service_function == BT_MESH_NETWORK_UPDATE_APPKEY)
248 void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
249 char *sender, int service_function,
250 gpointer invocation_data)
252 invocation_info_t *info;
253 info = g_malloc0(sizeof(invocation_info_t));
254 info->context = invocation;
255 info->result = result;
256 info->sender = g_strdup(sender);
257 info->service_function = service_function;
258 info->user_data = invocation_data;
259 invocation_list = g_slist_append(invocation_list, info);
263 static int __bt_service_get_sender_pid(const char *unique_name, pid_t *pid)
266 char err_msg[256] = {0, };
268 retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
270 ret = cynara_creds_gdbus_get_pid(bt_service_conn, unique_name, pid);
271 if (ret != CYNARA_API_SUCCESS) {
272 cynara_strerror(ret, err_msg, sizeof(err_msg));
273 BT_ERR("Fail to get user credential: %s", err_msg);
275 return BLUETOOTH_ERROR_INTERNAL;
278 return BLUETOOTH_ERROR_NONE;
281 static int __bt_bm_request_data(_bt_battery_data_t *latest)
283 int ret = _bt_bm_read_data(latest);
284 if (ret == BLUETOOTH_ERROR_NONE) {
285 BT_DBG("Received data from bluetooth battery monitor: %ld %ld %d %d",
286 latest->session_start_time, latest->session_end_time,
287 latest->session_scan_time, latest->session_connected_time);
289 if (latest->atm_list == NULL) {
290 BT_DBG("No app data transaction for this session");
294 for (GSList *l = latest->atm_list; l != NULL; l = g_slist_next(l)) {
295 _bt_battery_app_data_t *t = (_bt_battery_app_data_t *)(l->data);
296 BT_DBG("%ld %ld %d %d", (long int)(t->uid), (long int)(t->pid), t->rx_bytes, t->tx_bytes);
300 BT_ERR("Error encountered");
304 static void __bt_service_method(GDBusConnection *connection,
306 const gchar *object_path,
307 const gchar *interface_name,
308 const gchar *method_name,
309 GVariant *parameters,
310 GDBusMethodInvocation *invocation,
315 BT_DBG("Method[%s] Object Path[%s] Interface Name[%s]",
316 method_name, object_path, interface_name);
318 if (g_strcmp0(method_name, "service_request") == 0) {
320 int service_function;
322 GVariant *param1 = NULL;
323 GVariant *param2 = NULL;
324 GVariant *param3 = NULL;
325 GVariant *param4 = NULL;
326 GVariant *param5 = NULL;
327 GArray *out_param1 = NULL;
328 GVariant *out_var = NULL;
329 GVariant *temp = NULL;
333 g_variant_get(parameters, "(iii@ay@ay@ay@ay@ay)", &service_type,
334 &service_function, &request_type,
335 ¶m1, ¶m2, ¶m3, ¶m4, ¶m5);
337 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
339 if (service_type == BT_CORE_SERVICE) {
340 BT_DBG("No need to check privilege from bt-core");
341 } else if (__bt_service_check_privilege(service_function,
342 service_type, (const char *)sender) == FALSE) {
343 BT_ERR("Client don't have the privilege to excute this function");
344 result = BLUETOOTH_ERROR_PERMISSION_DEINED;
348 BT_DBG("SERVICE TYPE [%d] SERVICE FUNC [%d]",
349 service_type, service_function);
350 switch (service_type) {
351 case BT_BLUEZ_SERVICE:
352 result = __bt_bluez_request(service_function,
353 request_type, request_id,
354 invocation, param1, param2,
355 param3, param4, &out_param1);
357 case BT_OBEX_SERVICE:
358 result = __bt_obexd_request(service_function,
359 request_type, request_id,
362 param4, &out_param1);
364 case BT_AGENT_SERVICE:
365 result = __bt_agent_request(service_function,
366 request_type, request_id,
369 param4, &out_param1);
371 case BT_CORE_SERVICE:
372 result = __bt_core_request(service_function,
373 request_type, request_id,
376 case BT_CHECK_PRIVILEGE:
377 result = BLUETOOTH_ERROR_NONE;
380 BT_ERR("Unknown service type");
381 result = BLUETOOTH_ERROR_INTERNAL;
385 if (result != BLUETOOTH_ERROR_NONE)
388 if (service_type == BT_CHECK_PRIVILEGE)
391 if (service_function == BT_OPP_PUSH_FILES)
394 if (request_type == BT_ASYNC_REQ ||
395 __bt_is_sync_function(service_function)) {
396 /* Do not send reply to bt-api over dbus,
397 Invocation context is already saved in service_function */
402 out_var = g_variant_new_from_data((const GVariantType *)"ay",
403 out_param1->data, out_param1->len,
406 temp = g_variant_new("(iv)", result, out_var);
407 g_dbus_method_invocation_return_value(invocation, temp);
408 g_array_free(out_param1, TRUE);
412 g_variant_unref(param1);
413 g_variant_unref(param2);
414 g_variant_unref(param3);
415 g_variant_unref(param4);
416 g_variant_unref(param5);
420 BT_ERR_C("Request is failed [%s] [0x%x]",
421 _bt_convert_error_to_string(result), result);
423 out_var = g_variant_new_from_data((const GVariantType *)"ay",
424 out_param1->data, out_param1->len,
427 temp = g_variant_new("(iv)", result, out_var);
428 g_dbus_method_invocation_return_value(invocation, temp);
430 g_array_free(out_param1, TRUE);
433 g_variant_unref(param1);
434 g_variant_unref(param2);
435 g_variant_unref(param3);
436 g_variant_unref(param4);
437 g_variant_unref(param5);
439 else if (g_strcmp0(method_name, "get_avc_mode") == 0) {
440 unsigned int mode = 0;
442 if (_bt_audio_get_avc_mode(&mode) != BLUETOOTH_ERROR_NONE)
443 BT_ERR("Fail to get the avc mode");
445 BT_DBG("Absolute Volume Control mode: %d", mode);
447 g_dbus_method_invocation_return_value(invocation,
448 g_variant_new("(u)", mode));
456 static const GDBusInterfaceVTable method_table = {
463 int __bt_bluez_request(int function_name,
466 GDBusMethodInvocation *context,
473 int result = BLUETOOTH_ERROR_NONE;
476 switch (function_name) {
477 case BT_ENABLE_ADAPTER: {
478 result = _bt_enable_adapter();
479 _bt_adapter_start_enable_timer();
482 case BT_DISABLE_ADAPTER: {
483 result = _bt_disable_adapter();
486 case BT_RECOVER_ADAPTER:
487 result = _bt_recover_adapter();
489 case BT_RESET_ADAPTER:
490 result = _bt_reset_adapter();
492 case BT_BATTERY_READ_DATA: {
493 _bt_battery_data_t *data = NULL;
494 data = g_malloc0(sizeof(_bt_battery_data_t));
495 result = __bt_bm_request_data(data);
497 bt_battery_dbus_data_t dbus_data;
498 memset(&dbus_data, 0, sizeof(bt_battery_dbus_data_t));
499 dbus_data.session_start_time = data->session_start_time;
500 dbus_data.session_end_time = data->session_end_time;
501 dbus_data.session_scan_time = data->session_scan_time;
502 dbus_data.session_connected_time = data->session_connected_time;
503 dbus_data.tx_time = data->tx_time;
504 dbus_data.rx_time = data->rx_time;
505 dbus_data.idle_time = data->idle_time;
507 /*Populating app data*/
509 for (GSList *l = data->atm_list; l != NULL; l = g_slist_next(l)) {
510 bt_battery_app_data *t = (bt_battery_app_data *)(l->data);
511 memcpy(&dbus_data.app_data[n], t, sizeof(bt_battery_app_data));
514 dbus_data.num_app = n;
515 g_array_append_vals(*out_param1, &dbus_data, sizeof(bt_battery_dbus_data_t));
516 g_slist_free_full(data->atm_list, g_free);
521 case BT_CHECK_ADAPTER: {
522 int enabled = BT_ADAPTER_DISABLED;
523 result = _bt_check_adapter(&enabled);
525 g_array_append_vals(*out_param1, &enabled,
529 case BT_ENABLE_ADAPTER_LE:
530 _bt_set_le_intended_status(TRUE);
531 result = _bt_enable_adapter_le();
533 case BT_DISABLE_ADAPTER_LE:
534 _bt_set_le_intended_status(FALSE);
535 result = _bt_disable_adapter_le();
537 case BT_START_DISCOVERY: {
538 unsigned short max_response;
539 unsigned short discovery_duration;
540 unsigned int classOfDeviceMask;
543 __bt_service_get_parameters(in_param1,
544 &max_response, sizeof(unsigned short));
545 __bt_service_get_parameters(in_param2,
546 &discovery_duration, sizeof(unsigned short));
547 __bt_service_get_parameters(in_param3,
548 &classOfDeviceMask, sizeof(unsigned int));
549 __bt_service_get_parameters(in_param4, &uid, sizeof(uid_t));
551 result = _bt_start_discovery(max_response, discovery_duration, classOfDeviceMask);
553 if (result == BLUETOOTH_ERROR_NONE) {
556 sender = (char*)g_dbus_method_invocation_get_sender(context);
558 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
559 BT_ERR("Fail to get the sender pid");
561 BT_DBG("Remeber pid / uid for the scan operation");
562 _bt_bm_add_scan_app(SCAN_REGACY, uid, pid);
567 case BT_START_CUSTOM_DISCOVERY: {
568 bt_discovery_role_type_t role;
570 __bt_service_get_parameters(in_param1,
571 &role, sizeof(bt_discovery_role_type_t));
572 result = _bt_start_custom_discovery(role);
576 case BT_CANCEL_DISCOVERY:
577 result = _bt_cancel_discovery();
579 case BT_IS_DISCOVERYING: {
580 gboolean discovering = FALSE;
581 discovering = _bt_is_discovering();
582 g_array_append_vals(*out_param1,
583 &discovering, sizeof(gboolean));
586 case BT_GET_LOCAL_ADDRESS: {
587 result = _bt_get_local_address();
589 /* Save invocation */
590 if (result == BLUETOOTH_ERROR_NONE) {
591 sender = (char*)g_dbus_method_invocation_get_sender(context);
592 _bt_save_invocation_context(context, result, sender,
593 function_name, NULL);
597 case BT_GET_LOCAL_VERSION: {
598 result = _bt_get_local_version();
600 /* Save invocation */
601 if (result == BLUETOOTH_ERROR_NONE) {
602 sender = (char*)g_dbus_method_invocation_get_sender(context);
603 _bt_save_invocation_context(context, result, sender,
604 function_name, NULL);
608 case BT_GET_LOCAL_NAME: {
609 result = _bt_get_local_name();
611 /* Save invocation */
612 if (result == BLUETOOTH_ERROR_NONE) {
613 sender = (char*)g_dbus_method_invocation_get_sender(context);
614 _bt_save_invocation_context(context, result, sender,
615 function_name, NULL);
619 case BT_SET_LOCAL_NAME: {
620 bluetooth_device_name_t local_name = { {0} };
621 __bt_service_get_parameters(in_param1,
622 &local_name, sizeof(bluetooth_device_name_t));
623 result = _bt_set_local_name(local_name.name);
626 case BT_GET_DISCOVERABLE_MODE: {
627 int discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
628 result = _bt_get_discoverable_mode(&discoverable_mode);
629 g_array_append_vals(*out_param1, &discoverable_mode, sizeof(int));
632 case BT_GET_DISCOVERABLE_TIME: {
635 result = _bt_get_timeout_value(&timeout);
636 g_array_append_vals(*out_param1, &timeout, sizeof(int));
639 case BT_SET_DISCOVERABLE_MODE: {
640 int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
643 __bt_service_get_parameters(in_param1, &mode, sizeof(int));
644 __bt_service_get_parameters(in_param2, &time, sizeof(int));
646 result = _bt_set_discoverable_mode(mode, time);
649 case BT_IS_CONNECTABLE: {
650 gboolean is_connectable = FALSE;
652 is_connectable = _bt_is_connectable();
653 g_array_append_vals(*out_param1, &is_connectable, sizeof(gboolean));
656 case BT_GET_CONNECTABLE: {
657 result = _bt_get_connectable();
659 /* Save invocation */
660 if (result == BLUETOOTH_ERROR_NONE) {
661 sender = (char*)g_dbus_method_invocation_get_sender(context);
662 _bt_save_invocation_context(context, result, sender,
663 function_name, NULL);
667 case BT_SET_CONNECTABLE: {
668 gboolean is_connectable;
670 __bt_service_get_parameters(in_param1,
671 &is_connectable, sizeof(gboolean));
672 result = _bt_set_connectable(is_connectable);
675 case BT_IS_SERVICE_USED: {
678 uuid = (char *)g_variant_get_data(in_param1);
679 BT_INFO("UUID to be searched [%s]", uuid);
680 result = _bt_is_service_used();
682 /* Save invocation */
683 if (result == BLUETOOTH_ERROR_NONE) {
684 sender = (char*)g_dbus_method_invocation_get_sender(context);
685 _bt_save_invocation_context(context, result, sender,
686 function_name, g_strdup(uuid));
690 case BT_GET_BONDED_DEVICES: {
691 result = _bt_get_bonded_devices();
692 /* Save invocation */
693 if (result == BLUETOOTH_ERROR_NONE) {
694 sender = (char*)g_dbus_method_invocation_get_sender(context);
695 _bt_save_invocation_context(context, result, sender,
696 function_name, NULL);
700 case BT_GET_BONDED_DEVICE: {
701 bluetooth_device_address_t address = { {0} };
703 __bt_service_get_parameters(in_param1,
704 &address, sizeof(bluetooth_device_address_t));
706 result = _bt_get_bonded_device_info(&address);
707 /* Save invocation */
708 if (result == BLUETOOTH_ERROR_NONE) {
709 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
711 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
715 _bt_convert_addr_type_to_string(addr, address.addr);
716 sender = (char*)g_dbus_method_invocation_get_sender(context);
717 _bt_save_invocation_context(context, result, sender,
718 function_name, addr);
722 case BT_GET_PROFILE_CONNECTED_DEVICES: {
724 uuid = (char *)g_variant_get_data(in_param1);
725 result = _bt_get_profile_connected_devices(uuid);
727 /* Save invocation */
728 if (result == BLUETOOTH_ERROR_NONE) {
729 sender = (char *)g_dbus_method_invocation_get_sender(context);
730 _bt_save_invocation_context(context, result, sender,
731 function_name, NULL);
736 bluetooth_device_address_t address = { {0} };
737 const char *local_name;
739 __bt_service_get_parameters(in_param1,
740 &address, sizeof(bluetooth_device_address_t));
741 local_name = (const char *)g_variant_get_data(in_param2);
743 result = _bt_set_alias(&address, local_name);
746 case BT_BOND_DEVICE: {
747 bluetooth_device_address_t address = { {0} };
749 __bt_service_get_parameters(in_param1,
750 &address, sizeof(bluetooth_device_address_t));
751 result = _bt_bond_device(&address, BLUETOOTH_DEV_CONN_DEFAULT, out_param1);
753 /* Save invocation */
754 if (result == BLUETOOTH_ERROR_NONE) {
755 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
756 _bt_convert_addr_type_to_string(addr, address.addr);
757 sender = (char*)g_dbus_method_invocation_get_sender(context);
758 _bt_save_invocation_context(context, result, sender,
759 function_name, (gpointer)addr);
761 bluetooth_device_info_t dev_info;
763 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
764 memcpy(&dev_info.device_address, &address,
765 sizeof(bluetooth_device_address_t));
766 g_array_append_vals(*out_param1, &dev_info,
767 sizeof(bluetooth_device_info_t));
771 case BT_BOND_DEVICE_BY_TYPE: {
772 bluetooth_device_address_t address = { {0} };
773 unsigned short conn_type = 0;
775 __bt_service_get_parameters(in_param1,
776 &address, sizeof(bluetooth_device_address_t));
777 __bt_service_get_parameters(in_param2,
778 &conn_type, sizeof(unsigned short));
780 result = _bt_bond_device(&address, conn_type, out_param1);
781 /* Save invocation */
782 if (result == BLUETOOTH_ERROR_NONE) {
783 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
784 _bt_convert_addr_type_to_string(addr, address.addr);
785 sender = (char*)g_dbus_method_invocation_get_sender(context);
786 _bt_save_invocation_context(context, result, sender,
787 function_name, (gpointer)addr);
789 bluetooth_device_info_t dev_info;
791 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
792 memcpy(&dev_info.device_address, &address,
793 sizeof(bluetooth_device_address_t));
794 g_array_append_vals(*out_param1, &dev_info,
795 sizeof(bluetooth_device_info_t));
799 case BT_UNBOND_DEVICE: {
800 bluetooth_device_address_t address = { {0} };
802 __bt_service_get_parameters(in_param1,
803 &address, sizeof(bluetooth_device_address_t));
804 result = _bt_unbond_device(&address, out_param1);
806 /* Save invocation */
807 if (result == BLUETOOTH_ERROR_NONE) {
808 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
809 _bt_convert_addr_type_to_string(addr, address.addr);
810 sender = (char*)g_dbus_method_invocation_get_sender(context);
811 _bt_save_invocation_context(context, result, sender,
812 function_name, (gpointer)addr);
814 g_array_append_vals(*out_param1, &address,
815 sizeof(bluetooth_device_address_t));
819 case BT_CANCEL_BONDING:{
820 result = _bt_cancel_bonding();
823 case BT_SEARCH_SERVICE: {
824 bluetooth_device_address_t address = { {0} };
825 __bt_service_get_parameters(in_param1,
826 &address, sizeof(bluetooth_device_address_t));
827 result = _bt_search_device(&address);
828 /* Save invocation */
829 if (result == BLUETOOTH_ERROR_NONE) {
830 char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
831 _bt_convert_addr_type_to_string(addr, address.addr);
832 sender = (char*)g_dbus_method_invocation_get_sender(context);
833 _bt_save_invocation_context(context, result, sender,
834 function_name, (gpointer)addr);
836 bt_sdp_info_t sdp_info;
838 memset(&sdp_info, 0x00, sizeof(bt_sdp_info_t));
839 memcpy(&sdp_info.device_addr, &address,
840 sizeof(bluetooth_device_address_t));
841 g_array_append_vals(*out_param1, &sdp_info, sizeof(bt_sdp_info_t));
845 case BT_CANCEL_SEARCH_SERVICE: {
846 result = _bt_cancel_search_device();
849 case BT_SET_PASSKEY_NOTIFICATION: {
853 sender = (char *)g_dbus_method_invocation_get_sender(context);
854 __bt_service_get_parameters(in_param1,
855 &enable, sizeof(gboolean));
857 result = _bt_set_passkey_notification(sender, enable);
860 case BT_SET_PIN_CODE: {
861 bluetooth_device_address_t address = { {0} };
862 bluetooth_device_pin_code_t pin_code = { {0} };
864 __bt_service_get_parameters(in_param1,
865 &address, sizeof(bluetooth_device_address_t));
866 __bt_service_get_parameters(in_param2,
867 &pin_code, sizeof(bluetooth_device_pin_code_t));
869 result = _bt_set_pin_code(&address, &pin_code);
872 case BT_UNSET_PIN_CODE: {
873 bluetooth_device_address_t address = { {0} };
875 __bt_service_get_parameters(in_param1,
876 &address, sizeof(bluetooth_device_address_t));
878 result = _bt_unset_pin_code(&address);
881 case BT_PASSKEY_REPLY: {
882 const char *passkey = NULL;
883 gboolean authentication_reply = FALSE;
884 passkey = g_variant_get_data(in_param1);
885 __bt_service_get_parameters(in_param2,
886 &authentication_reply, sizeof(gboolean));
887 result = _bt_passkey_reply(passkey, authentication_reply);
890 case BT_PASSKEY_CONFIRMATION_REPLY: {
891 gboolean confirmation_reply = FALSE;
892 __bt_service_get_parameters(in_param1,
893 &confirmation_reply, sizeof(gboolean));
894 result = _bt_passkey_confirmation_reply(confirmation_reply);
897 case BT_GET_IS_ALIAS_SET: {
898 bluetooth_device_address_t address = { {0} };
900 __bt_service_get_parameters(in_param1,
901 &address, sizeof(bluetooth_device_address_t));
903 result = _bt_is_alias_set(&address);
904 if (result == BLUETOOTH_ERROR_NONE) {
905 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
907 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
911 _bt_convert_addr_type_to_string(addr, address.addr);
912 sender = (char*)g_dbus_method_invocation_get_sender(context);
913 _bt_save_invocation_context(context, result, sender,
914 function_name, addr);
918 case BT_SET_AUTHORIZATION: {
919 bluetooth_device_address_t address = { {0} };
921 __bt_service_get_parameters(in_param1,
922 &address, sizeof(bluetooth_device_address_t));
923 __bt_service_get_parameters(in_param2,
924 &authorize, sizeof(gboolean));
925 result = _bt_set_authorization(&address, authorize);
928 case BT_SET_LE_PRIVACY: {
929 gboolean set_privacy;
930 __bt_service_get_parameters(in_param1, &set_privacy,
932 result = _bt_set_le_privacy(set_privacy);
935 case BT_ADD_WHITE_LIST: {
936 bluetooth_device_address_t address = { {0} };
937 int address_type = 0;
939 __bt_service_get_parameters(in_param1,
940 &address, sizeof(bluetooth_device_address_t));
941 __bt_service_get_parameters(in_param2,
942 &address_type, sizeof(int));
943 result = _bt_set_white_list(&address, address_type, is_add);
946 case BT_REMOVE_WHITE_LIST: {
947 bluetooth_device_address_t address = { {0} };
948 int address_type = 0;
950 __bt_service_get_parameters(in_param1,
951 &address, sizeof(bluetooth_device_address_t));
952 __bt_service_get_parameters(in_param2,
953 &address_type, sizeof(int));
954 result = _bt_set_white_list(&address, address_type, is_add);
957 case BT_UPDATE_LE_CONNECTION_MODE: {
959 bluetooth_device_address_t remote_address = { { 0 } };
960 bluetooth_le_connection_param_t parameters = { 0 };
961 bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED;
963 __bt_service_get_parameters(in_param1, &remote_address,
964 sizeof(bluetooth_device_address_t));
965 __bt_service_get_parameters(in_param2, &mode,
966 sizeof(bluetooth_le_connection_mode_t));
968 result = _bt_get_le_connection_parameter(mode, ¶meters);
969 if (result != BLUETOOTH_ERROR_NONE)
972 sender = (char *)g_dbus_method_invocation_get_sender(context);
974 result = _bt_le_connection_update(sender,
976 parameters.interval_min,
977 parameters.interval_max,
982 case BT_SET_MANUFACTURER_DATA: {
983 bluetooth_manufacturer_data_t m_data = { 0 };
984 __bt_service_get_parameters(in_param1,
985 &m_data, sizeof(bluetooth_manufacturer_data_t));
986 result = _bt_set_manufacturer_data(&m_data);
990 case BT_IS_DEVICE_CONNECTED: {
991 bluetooth_device_address_t address = { {0} };
992 gboolean connected = FALSE;
995 __bt_service_get_parameters(in_param1,
996 &address, sizeof(bluetooth_device_address_t));
997 __bt_service_get_parameters(in_param2,
998 &service_type, sizeof(int));
1000 #if defined(TIZEN_FEATURE_BT_PAN_NAP)
1001 if ((service_type == BLUETOOTH_NAP_SERVICE) || (service_type == BLUETOOTH_NAP_SERVER_SERVICE))
1002 connected = _bt_is_nap_panu_device_connected(&address, service_type);
1004 connected = _bt_is_device_connected(&address, service_type);
1006 connected = _bt_is_device_connected(&address, service_type);
1008 BT_INFO("is_connected: %d", connected);
1009 g_array_append_vals(*out_param1, &connected, sizeof(gboolean));
1012 case BT_GET_CONNECTED_LINK_TYPE: {
1013 bluetooth_device_address_t address = { {0} };
1015 __bt_service_get_parameters(in_param1,
1016 &address, sizeof(bluetooth_device_address_t));
1018 result = _bt_get_connected_link(&address);
1019 if (result == BLUETOOTH_ERROR_NONE) {
1020 char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
1022 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
1026 _bt_convert_addr_type_to_string(addr, address.addr);
1027 sender = (char*)g_dbus_method_invocation_get_sender(context);
1028 _bt_save_invocation_context(context, result, sender,
1029 function_name, addr);
1033 case BT_IS_SCAN_FILTER_SUPPORTED:{
1034 int is_supported = 0;
1036 if (_bt_is_scan_filter_supported() == TRUE)
1039 g_array_append_vals(*out_param1,
1040 &is_supported, sizeof(int));
1044 case BT_ENABLE_RSSI: {
1045 bluetooth_device_address_t bd_addr;
1047 bt_rssi_threshold_t rssi_threshold;
1049 int in_range_threshold;
1052 BT_DBG("Enable RSSI");
1054 __bt_service_get_parameters(in_param1,
1055 &bd_addr, sizeof(bluetooth_device_address_t));
1056 __bt_service_get_parameters(in_param2,
1057 &link_type, sizeof(int));
1058 __bt_service_get_parameters(in_param3,
1059 &rssi_threshold, sizeof(bt_rssi_threshold_t));
1061 low_threshold = rssi_threshold.low_threshold;
1062 in_range_threshold = rssi_threshold.in_range_threshold;
1063 high_threshold = rssi_threshold.high_threshold;
1065 result = _bt_enable_rssi(&bd_addr, link_type, low_threshold,
1066 in_range_threshold, high_threshold);
1071 bluetooth_device_address_t bd_addr;
1073 BT_DBG("Get RSSI Strength");
1075 __bt_service_get_parameters(in_param1,
1076 &bd_addr, sizeof(bluetooth_device_address_t));
1077 __bt_service_get_parameters(in_param2,
1078 &link_type, sizeof(int));
1080 result = _bt_get_rssi_strength(&bd_addr, link_type);
1083 case BT_SET_PROFILE_TRUSTED: {
1084 bluetooth_device_address_t bd_addr = { {0} };
1088 __bt_service_get_parameters(in_param1, &bd_addr,
1089 sizeof(bluetooth_device_address_t));
1090 __bt_service_get_parameters(in_param2, &profile, sizeof(int));
1091 __bt_service_get_parameters(in_param3, &trust, sizeof(int));
1093 result = _bt_set_trust_profile(&bd_addr, profile, trust);
1096 case BT_GET_PROFILE_TRUSTED: {
1097 bluetooth_device_address_t bd_addr = { {0} };
1099 guint trusted_profile = 0;
1101 __bt_service_get_parameters(in_param1, &bd_addr,
1102 sizeof(bluetooth_device_address_t));
1103 __bt_service_get_parameters(in_param2, &profile, sizeof(int));
1105 result = _bt_get_trust_profile(&bd_addr, profile, &trusted_profile);
1106 BT_DBG("TRUST %d", trusted_profile);
1107 if (result == BLUETOOTH_ERROR_NONE) {
1108 g_array_append_vals(*out_param1, &trusted_profile,
1114 case BT_HID_CONNECT: {
1115 bluetooth_device_address_t address = { {0} };
1117 __bt_service_get_parameters(in_param1,
1118 &address, sizeof(bluetooth_device_address_t));
1120 result = _bt_hid_connect(&address);
1121 if (result != BLUETOOTH_ERROR_NONE) {
1122 g_array_append_vals(*out_param1, &address,
1123 sizeof(bluetooth_device_address_t));
1125 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1126 _bt_convert_addr_type_to_string(addr, address.addr);
1127 sender = (char*)g_dbus_method_invocation_get_sender(context);
1128 _bt_save_invocation_context(context, result, sender,
1129 function_name, (gpointer)addr);
1133 case BT_HID_DISCONNECT: {
1134 bluetooth_device_address_t address = { {0} };
1136 __bt_service_get_parameters(in_param1,
1137 &address, sizeof(bluetooth_device_address_t));
1139 result = _bt_hid_disconnect(&address);
1140 if (result != BLUETOOTH_ERROR_NONE) {
1141 g_array_append_vals(*out_param1, &address,
1142 sizeof(bluetooth_device_address_t));
1144 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1145 _bt_convert_addr_type_to_string(addr, address.addr);
1146 sender = (char*)g_dbus_method_invocation_get_sender(context);
1147 _bt_save_invocation_context(context, result, sender,
1148 function_name, (gpointer)addr);
1152 case BT_DPM_SET_ALLOW_BT_MODE: {
1153 dpm_bt_allow_t value = DPM_BT_ERROR;
1155 __bt_service_get_parameters(in_param1, &value,
1158 result = _bt_dpm_set_allow_bluetooth_mode(value);
1161 case BT_DPM_GET_ALLOW_BT_MODE: {
1162 int value = DPM_BT_ERROR;
1164 result = _bt_dpm_get_allow_bluetooth_mode(&value);
1165 g_array_append_vals(*out_param1, &value, sizeof(int));
1168 case BT_DPM_SET_DEVICE_RESTRITION: {
1169 dpm_status_t value = DPM_STATUS_ERROR;
1171 __bt_service_get_parameters(in_param1, &value,
1174 result = _bt_dpm_activate_bluetooth_device_restriction(value);
1177 case BT_DPM_GET_DEVICE_RESTRITION: {
1178 int value = DPM_STATUS_ERROR;
1180 result = _bt_dpm_is_bluetooth_device_restriction_active(&value);
1181 g_array_append_vals(*out_param1, &value, sizeof(int));
1184 case BT_DPM_SET_UUID_RESTRITION: {
1185 dpm_status_t value = DPM_STATUS_ERROR;
1187 __bt_service_get_parameters(in_param1, &value,
1190 result = _bt_dpm_activate_bluetoooth_uuid_restriction(value);
1193 case BT_DPM_GET_UUID_RESTRITION: {
1194 int value = DPM_STATUS_ERROR;
1196 result = _bt_dpm_is_bluetooth_uuid_restriction_active(&value);
1197 g_array_append_vals(*out_param1, &value, sizeof(int));
1200 case BT_DPM_ADD_DEVICES_BLACKLIST: {
1201 bluetooth_device_address_t address = { {0} };
1203 __bt_service_get_parameters(in_param1, &address,
1204 sizeof(bluetooth_device_address_t));
1206 result = _bt_dpm_add_bluetooth_devices_to_blacklist(&address);
1209 case BT_DPM_ADD_DEVICES_WHITELIST: {
1210 bluetooth_device_address_t address = { {0} };
1212 __bt_service_get_parameters(in_param1, &address,
1213 sizeof(bluetooth_device_address_t));
1215 result = _bt_dpm_add_bluetooth_devices_to_whitelist(&address);
1218 case BT_DPM_ADD_UUIDS_BLACKLIST: {
1219 const char *uuid = NULL;
1221 uuid = g_variant_get_data(in_param1);
1223 result = _bt_dpm_add_bluetooth_uuids_to_blacklist(uuid);
1226 case BT_DPM_ADD_UUIDS_WHITELIST: {
1227 const char *uuid = NULL;
1229 uuid = g_variant_get_data(in_param1);
1231 result = _bt_dpm_add_bluetooth_uuids_to_whitelist(uuid);
1234 case BT_DPM_CLEAR_DEVICES_BLACKLIST: {
1235 result = _bt_dpm_clear_bluetooth_devices_from_blacklist();
1238 case BT_DPM_CLEAR_DEVICES_WHITELIST: {
1239 result = _bt_dpm_clear_bluetooth_devices_from_whitelist();
1242 case BT_DPM_CLEAR_UUIDS_BLACKLIST: {
1243 result = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
1246 case BT_DPM_CLEAR_UUIDS_WHITELIST: {
1247 result = _bt_dpm_clear_bluetooth_uuids_from_whitelist();
1250 case BT_DPM_REMOVE_DEVICE_BLACKLIST: {
1251 bluetooth_device_address_t address = { {0} };
1253 __bt_service_get_parameters(in_param1, &address,
1254 sizeof(bluetooth_device_address_t));
1256 result = _bt_dpm_remove_bluetooth_devices_from_blacklist(&address);
1259 case BT_DPM_REMOVE_DEVICE_WHITELIST: {
1260 bluetooth_device_address_t address = { {0} };
1262 __bt_service_get_parameters(in_param1, &address,
1263 sizeof(bluetooth_device_address_t));
1265 result = _bt_dpm_remove_bluetooth_devices_from_whitelist(&address);
1268 case BT_DPM_REMOVE_UUID_BLACKLIST: {
1269 const char *uuid = NULL;
1271 uuid = g_variant_get_data(in_param1);
1273 result = _bt_dpm_remove_bluetooth_uuids_from_blacklist(uuid);
1276 case BT_DPM_REMOVE_UUID_WHITELIST: {
1277 const char *uuid = NULL;
1279 uuid = g_variant_get_data(in_param1);
1281 result = _bt_dpm_remove_bluetooth_uuids_from_whitelist(uuid);
1285 case BT_DPM_GET_DEVICES_BLACKLIST: {
1286 result = _bt_dpm_get_bluetooth_devices_from_blacklist(out_param1);
1289 case BT_DPM_GET_DEVICES_WHITELIST: {
1290 result = _bt_dpm_get_bluetooth_devices_from_whitelist(out_param1);
1293 case BT_DPM_GET_UUIDS_BLACKLIST: {
1294 result = _bt_dpm_get_bluetooth_uuids_from_blacklist(out_param1);
1297 case BT_DPM_GET_UUIDS_WHITELIST: {
1298 result = _bt_dpm_get_bluetooth_uuids_from_whitelist(out_param1);
1301 case BT_DPM_SET_ALLOW_OUTGOING_CALL: {
1302 dpm_status_t value = DPM_STATUS_ERROR;
1304 __bt_service_get_parameters(in_param1, &value,
1307 result = _bt_dpm_set_allow_bluetooth_outgoing_call(value);
1311 case BT_DPM_GET_ALLOW_OUTGOING_CALL: {
1312 int value = DPM_STATUS_ERROR;
1314 result = _bt_dpm_get_allow_bluetooth_outgoing_call(&value);
1315 g_array_append_vals(*out_param1, &value, sizeof(int));
1318 case BT_DPM_SET_PAIRING_STATE: {
1319 dpm_status_t value = DPM_STATUS_ERROR;
1321 __bt_service_get_parameters(in_param1, &value,
1324 result = _bt_dpm_set_bluetooth_pairing_state(value);
1328 case BT_DPM_GET_PAIRING_STATE: {
1329 int value = DPM_STATUS_ERROR;
1331 result = _bt_dpm_get_bluetooth_pairing_state(&value);
1332 g_array_append_vals(*out_param1, &value, sizeof(int));
1335 case BT_DPM_SET_PROFILE_STATE: {
1336 int value = DPM_STATUS_ERROR;
1337 int profile = DPM_PROFILE_NONE;
1339 __bt_service_get_parameters(in_param1, &profile,
1341 __bt_service_get_parameters(in_param2, &value,
1344 result = _bt_dpm_set_bluetooth_profile_state(profile, value);
1348 case BT_DPM_GET_PROFILE_STATE: {
1349 int value = DPM_STATUS_ERROR;
1350 int profile = DPM_PROFILE_NONE;
1352 __bt_service_get_parameters(in_param1, &profile,
1355 result = _bt_dpm_get_bluetooth_profile_state(profile, &value);
1356 g_array_append_vals(*out_param1, &value, sizeof(int));
1359 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE: {
1360 int value = DPM_BT_ERROR;
1362 __bt_service_get_parameters(in_param1, &value,
1365 result = _bt_dpm_set_bluetooth_desktop_connectivity_state(value);
1369 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE: {
1370 int value = DPM_STATUS_ERROR;
1372 result = _bt_dpm_get_bluetooth_desktop_connectivity_state(&value);
1373 g_array_append_vals(*out_param1, &value, sizeof(int));
1376 case BT_DPM_SET_DISCOVERABLE_STATE: {
1377 int value = DPM_STATUS_ERROR;
1379 __bt_service_get_parameters(in_param1, &value,
1382 result = _bt_dpm_set_bluetooth_discoverable_state(value);
1386 case BT_DPM_GET_DISCOVERABLE_STATE: {
1387 int value = DPM_STATUS_ERROR;
1389 result = _bt_dpm_get_bluetooth_discoverable_state(&value);
1390 g_array_append_vals(*out_param1, &value, sizeof(int));
1393 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE: {
1394 int value = DPM_STATUS_ERROR;
1396 __bt_service_get_parameters(in_param1, &value,
1399 result = _bt_dpm_set_bluetooth_limited_discoverable_state(value);
1403 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE: {
1404 int value = DPM_STATUS_ERROR;
1406 result = _bt_dpm_get_bluetooth_limited_discoverable_state(&value);
1407 g_array_append_vals(*out_param1, &value, sizeof(int));
1410 case BT_DPM_SET_DATA_TRANSFER_STATE: {
1411 int value = DPM_STATUS_ERROR;
1413 __bt_service_get_parameters(in_param1, &value,
1416 result = _bt_dpm_set_bluetooth_data_transfer_state(value);
1420 case BT_DPM_GET_DATA_TRANSFER_STATE: {
1421 int value = DPM_STATUS_ERROR;
1423 result = _bt_dpm_get_allow_bluetooth_data_transfer_state(&value);
1424 g_array_append_vals(*out_param1, &value, sizeof(int));
1427 case BT_RFCOMM_CLIENT_CONNECT: {
1428 bluetooth_device_address_t address = { {0} };
1432 __bt_service_get_parameters(in_param1,
1433 &address, sizeof(bluetooth_device_address_t));
1434 input_string = (char *)g_variant_get_data(in_param2);
1435 __bt_service_get_parameters(in_param3, &connect_type, sizeof(int));
1437 if (connect_type == BT_RFCOMM_UUID)
1438 result = _bt_rfcomm_connect_using_uuid(&address, input_string);
1440 result = _bt_rfcomm_connect_using_channel(&address, input_string);
1442 if (result != BLUETOOTH_ERROR_NONE) {
1443 bluetooth_rfcomm_connection_t conn_info;
1445 BT_ERR("BT_RFCOMM_CLIENT_CONNECT failed, send error");
1446 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
1447 if (connect_type == BT_RFCOMM_UUID)
1448 g_strlcpy(conn_info.uuid, input_string, BLUETOOTH_UUID_STRING_MAX);
1450 g_strlcpy(conn_info.uuid, "not_used", BLUETOOTH_UUID_STRING_MAX);
1452 conn_info.device_role = RFCOMM_ROLE_CLIENT;
1453 conn_info.socket_fd = -1;
1454 g_array_append_vals(*out_param1, &conn_info,
1455 sizeof(bluetooth_rfcomm_connection_t));
1457 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1458 _bt_convert_addr_type_to_string(addr, address.addr);
1459 sender = (char*)g_dbus_method_invocation_get_sender(context);
1460 _bt_save_invocation_context(context, result, sender, function_name, addr);
1464 case BT_RFCOMM_SOCKET_DISCONNECT: {
1466 * Bluetooth RFCOMM socket disconnection will be done from bt-api, call to bt-service
1467 * is only used for privilege check, so return BLUETOOTH_ERROR_NONE from here.
1469 result = BLUETOOTH_ERROR_NONE;
1472 case BT_RFCOMM_SOCKET_WRITE: {
1474 * This call to bt-service is only used for privilege check, so return
1475 * BLUETOOTH_ERROR_NONE from here.
1477 result = BLUETOOTH_ERROR_NONE;
1480 case BT_RFCOMM_CREATE_SOCKET: {
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_LISTEN_AND_ACCEPT: {
1492 sender = (char *)g_dbus_method_invocation_get_sender(context);
1493 uuid = (char *)g_variant_get_data(in_param1);
1495 result = _bt_rfcomm_socket_listen(sender, uuid, true);
1497 result = BLUETOOTH_ERROR_NONE;
1498 _bt_save_invocation_context(context,
1499 result, sender, function_name, NULL);
1501 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1505 case BT_RFCOMM_LISTEN: {
1509 sender = (char *)g_dbus_method_invocation_get_sender(context);
1510 uuid = (char *)g_variant_get_data(in_param1);
1512 result = _bt_rfcomm_socket_listen(sender, uuid, false);
1514 result = BLUETOOTH_ERROR_NONE;
1515 _bt_save_invocation_context(context,
1516 result, sender, function_name, NULL);
1518 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1522 case BT_RFCOMM_ACCEPT_CONNECTION: {
1525 address = (char *)g_variant_get_data(in_param1);
1526 result = _bt_rfcomm_reply_conn_authorization(address, TRUE);
1529 case BT_RFCOMM_REJECT_CONNECTION: {
1532 address = (char *)g_variant_get_data(in_param1);
1533 result = _bt_rfcomm_reply_conn_authorization(address, FALSE);
1536 case BT_RFCOMM_REMOVE_SOCKET: {
1538 * This call to bt-service is only used for privilege check, so return
1539 * BLUETOOTH_ERROR_NONE from here.
1541 result = BLUETOOTH_ERROR_NONE;
1544 case BT_RFCOMM_SEND_RX_DETAILS: {
1548 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
1549 __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t));
1550 __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int));
1551 _bt_bm_add_transaction_details(uid, pid, size, RX_DATA);
1554 case BT_RFCOMM_SEND_TX_DETAILS: {
1558 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
1559 __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t));
1560 __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int));
1561 _bt_bm_add_transaction_details(uid, pid, size, TX_DATA);
1564 case BT_RFCOMM_UPDATE_CONNECTION_INFO: {
1565 gboolean connected = FALSE;
1567 int role = RFCOMM_ROLE_SERVER;
1569 sender = (char *)g_dbus_method_invocation_get_sender(context);
1571 __bt_service_get_parameters(in_param1, &role, sizeof(int));
1572 __bt_service_get_parameters(in_param2, &connected, sizeof(gboolean));
1573 __bt_service_get_parameters(in_param3, &socket_fd, sizeof(int));
1575 if (connected == TRUE)
1576 result = _bt_rfcomm_conn_added(sender, role, socket_fd);
1578 result = _bt_rfcomm_conn_removed(sender, role, socket_fd);
1582 case BT_AUDIO_SELECT_ROLE: {
1583 bluetooth_audio_role_t role;
1585 __bt_service_get_parameters(in_param1,
1586 &role, sizeof(bluetooth_audio_role_t));
1588 result = _bt_audio_select_role(role);
1589 if (result == BLUETOOTH_ERROR_NONE) {
1590 sender = (char*)g_dbus_method_invocation_get_sender(context);
1591 _bt_save_invocation_context(context, result, sender,
1592 function_name, NULL);
1596 case BT_AUDIO_SET_ABSOLUTE_VOLUME: {
1597 unsigned int volume = 0;
1599 __bt_service_get_parameters(in_param1,
1600 &volume, sizeof(unsigned int));
1602 result = _bt_audio_set_absolute_volume(volume);
1605 case BT_AUDIO_GET_ABSOLUTE_VOLUME: {
1606 unsigned int volume = 0;
1608 result = _bt_audio_get_absolute_volume(&volume);
1609 g_array_append_vals(*out_param1, &volume, sizeof(unsigned int));
1612 case BT_AUDIO_IS_AVC_ACTIVATED: {
1615 result = _bt_audio_is_avc_activated(&activated);
1616 g_array_append_vals(*out_param1, &activated, sizeof(bool));
1619 case BT_AV_CONNECT: {
1620 bluetooth_device_address_t address = { {0} };
1621 __bt_service_get_parameters(in_param1,
1622 &address, sizeof(bluetooth_device_address_t));
1624 result = _bt_audio_is_profile_connection_in_progress(BT_AV_CONNECT, &address);
1626 if (result == BLUETOOTH_ERROR_NONE)
1627 result = _bt_audio_connect(BT_AUDIO_A2DP, &address);
1629 if (result != BLUETOOTH_ERROR_NONE) {
1630 BT_ERR("AV Connect Request has failed to execute");
1631 char addr[BT_ADDRESS_STRING_SIZE];
1632 _bt_convert_addr_type_to_string(addr, address.addr);
1633 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1635 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1636 _bt_convert_addr_type_to_string(addr, address.addr);
1637 sender = (char*)g_dbus_method_invocation_get_sender(context);
1638 _bt_save_invocation_context(context, result, sender,
1639 function_name, (gpointer)addr);
1643 case BT_AUDIO_CONNECT: {
1644 bluetooth_device_address_t address = { {0} };
1645 __bt_service_get_parameters(in_param1,
1646 &address, sizeof(bluetooth_device_address_t));
1648 result = _bt_audio_is_profile_connection_in_progress(BT_AUDIO_CONNECT, &address);
1650 if (result == BLUETOOTH_ERROR_NONE)
1651 result = _bt_audio_connect(BT_AUDIO_ALL, &address);
1653 if (result != BLUETOOTH_ERROR_NONE) {
1654 BT_ERR("Audio All Connect Request has failed to execute");
1655 char addr[BT_ADDRESS_STRING_SIZE];
1656 _bt_convert_addr_type_to_string(addr, address.addr);
1657 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1659 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1660 _bt_convert_addr_type_to_string(addr, address.addr);
1661 sender = (char*)g_dbus_method_invocation_get_sender(context);
1662 _bt_save_invocation_context(context, result, sender,
1663 function_name, (gpointer)addr);
1667 case BT_AUDIO_DISCONNECT: {
1668 bluetooth_device_address_t address = { {0} };
1669 __bt_service_get_parameters(in_param1,
1670 &address, sizeof(bluetooth_device_address_t));
1672 result = _bt_audio_disconnect(BT_AUDIO_ALL, &address);
1674 if (result != BLUETOOTH_ERROR_NONE) {
1675 char addr[BT_ADDRESS_STRING_SIZE];
1676 _bt_convert_addr_type_to_string(addr, address.addr);
1677 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1679 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1680 _bt_convert_addr_type_to_string(addr, address.addr);
1681 sender = (char*)g_dbus_method_invocation_get_sender(context);
1682 _bt_save_invocation_context(context, result, sender,
1683 function_name, (gpointer)addr);
1687 case BT_AV_DISCONNECT: {
1688 bluetooth_device_address_t address = { {0} };
1689 __bt_service_get_parameters(in_param1,
1690 &address, sizeof(bluetooth_device_address_t));
1692 result = _bt_audio_disconnect(BT_AUDIO_A2DP, &address);
1694 if (result != BLUETOOTH_ERROR_NONE) {
1695 char addr[BT_ADDRESS_STRING_SIZE];
1696 _bt_convert_addr_type_to_string(addr, address.addr);
1697 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1699 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1700 _bt_convert_addr_type_to_string(addr, address.addr);
1701 sender = (char*)g_dbus_method_invocation_get_sender(context);
1702 _bt_save_invocation_context(context, result, sender,
1703 function_name, (gpointer)addr);
1707 case BT_AG_CONNECT: {
1708 bluetooth_device_address_t address = { {0} };
1709 __bt_service_get_parameters(in_param1,
1710 &address, sizeof(bluetooth_device_address_t));
1712 result = _bt_audio_is_profile_connection_in_progress(BT_AG_CONNECT, &address);
1714 if (result == BLUETOOTH_ERROR_NONE)
1715 result = _bt_audio_connect(BT_AUDIO_HSP, &address);
1717 if (result != BLUETOOTH_ERROR_NONE) {
1718 BT_ERR("AG Connect Request has failed to execute");
1719 char addr[BT_ADDRESS_STRING_SIZE];
1720 _bt_convert_addr_type_to_string(addr, address.addr);
1721 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1723 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1724 _bt_convert_addr_type_to_string(addr, address.addr);
1725 sender = (char*)g_dbus_method_invocation_get_sender(context);
1726 _bt_save_invocation_context(context, result, sender,
1727 function_name, (gpointer)addr);
1731 case BT_AG_DISCONNECT: {
1732 bluetooth_device_address_t address = { {0} };
1734 __bt_service_get_parameters(in_param1,
1735 &address, sizeof(bluetooth_device_address_t));
1737 result = _bt_audio_disconnect(BT_AUDIO_HSP, &address);
1739 if (result != BLUETOOTH_ERROR_NONE) {
1740 char addr[BT_ADDRESS_STRING_SIZE];
1741 _bt_convert_addr_type_to_string(addr, address.addr);
1742 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1744 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1745 _bt_convert_addr_type_to_string(addr, address.addr);
1746 sender = (char*)g_dbus_method_invocation_get_sender(context);
1747 _bt_save_invocation_context(context, result, sender,
1748 function_name, (gpointer)addr);
1752 case BT_AV_SOURCE_CONNECT: {
1753 bluetooth_device_address_t address = { {0} };
1755 __bt_service_get_parameters(in_param1,
1756 &address, sizeof(bluetooth_device_address_t));
1758 result = _bt_audio_is_profile_connection_in_progress(BT_AV_SOURCE_CONNECT,
1761 if (result == BLUETOOTH_ERROR_NONE)
1762 result = _bt_audio_connect(BT_AUDIO_A2DP_SOURCE, &address);
1764 if (result != BLUETOOTH_ERROR_NONE) {
1765 BT_ERR("A2DP Source Connect Request has failed to execute");
1766 char addr[BT_ADDRESS_STRING_SIZE];
1767 _bt_convert_addr_type_to_string(addr, address.addr);
1768 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1770 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1771 _bt_convert_addr_type_to_string(addr, address.addr);
1772 sender = (char*)g_dbus_method_invocation_get_sender(context);
1773 _bt_save_invocation_context(context, result, sender,
1774 function_name, (gpointer)addr);
1778 case BT_AV_SOURCE_DISCONNECT: {
1779 bluetooth_device_address_t address = { {0} };
1781 __bt_service_get_parameters(in_param1,
1782 &address, sizeof(bluetooth_device_address_t));
1784 result = _bt_audio_disconnect(BT_AUDIO_A2DP_SOURCE, &address);
1785 if (result != BLUETOOTH_ERROR_NONE) {
1786 char addr[BT_ADDRESS_STRING_SIZE];
1787 _bt_convert_addr_type_to_string(addr, address.addr);
1788 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1790 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1791 _bt_convert_addr_type_to_string(addr, address.addr);
1792 sender = (char*)g_dbus_method_invocation_get_sender(context);
1793 _bt_save_invocation_context(context, result, sender,
1794 function_name, (gpointer)addr);
1798 case BT_HF_CONNECT: {
1799 bluetooth_device_address_t address = { {0} };
1801 __bt_service_get_parameters(in_param1,
1802 &address, sizeof(bluetooth_device_address_t));
1804 result = _bt_audio_is_profile_connection_in_progress(BT_HF_CONNECT,
1807 if (result == BLUETOOTH_ERROR_NONE)
1808 result = _bt_hf_connect(&address);
1810 if (result != BLUETOOTH_ERROR_NONE) {
1811 BT_ERR("HF Connect Request has failed to execute");
1812 char addr[BT_ADDRESS_STRING_SIZE];
1813 _bt_convert_addr_type_to_string(addr, address.addr);
1814 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1816 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1817 _bt_convert_addr_type_to_string(addr, address.addr);
1818 sender = (char*)g_dbus_method_invocation_get_sender(context);
1819 _bt_save_invocation_context(context, result, sender,
1820 function_name, (gpointer)addr);
1824 case BT_HF_DISCONNECT: {
1825 bluetooth_device_address_t address = { {0} };
1827 __bt_service_get_parameters(in_param1,
1828 &address, sizeof(bluetooth_device_address_t));
1830 result = _bt_hf_disconnect(&address);
1831 if (result != BLUETOOTH_ERROR_NONE) {
1832 char addr[BT_ADDRESS_STRING_SIZE];
1833 _bt_convert_addr_type_to_string(addr, address.addr);
1834 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1836 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1837 _bt_convert_addr_type_to_string(addr, address.addr);
1838 sender = (char*)g_dbus_method_invocation_get_sender(context);
1839 _bt_save_invocation_context(context, result, sender,
1840 function_name, (gpointer)addr);
1844 case BT_AVRCP_TARGET_CONNECT: {
1845 bluetooth_device_address_t address = { {0} };
1847 __bt_service_get_parameters(in_param1,
1848 &address, sizeof(bluetooth_device_address_t));
1850 result = _bt_audio_is_profile_connection_in_progress(BT_AVRCP_TARGET_CONNECT,
1853 if (result == BLUETOOTH_ERROR_NONE)
1854 result = _bt_audio_connect(BT_AVRCP_TARGET, &address);
1856 if (result != BLUETOOTH_ERROR_NONE) {
1857 BT_ERR("AVRCP Target Connect Request has failed to execute");
1858 char addr[BT_ADDRESS_STRING_SIZE];
1859 _bt_convert_addr_type_to_string(addr, address.addr);
1860 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1862 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1863 _bt_convert_addr_type_to_string(addr, address.addr);
1864 sender = (char*)g_dbus_method_invocation_get_sender(context);
1865 _bt_save_invocation_context(context, result, sender,
1866 function_name, (gpointer)addr);
1870 case BT_AVRCP_TARGET_DISCONNECT: {
1871 bluetooth_device_address_t address = { {0} };
1873 __bt_service_get_parameters(in_param1,
1874 &address, sizeof(bluetooth_device_address_t));
1876 result = _bt_audio_disconnect(BT_AVRCP_TARGET, &address);
1877 if (result != BLUETOOTH_ERROR_NONE) {
1878 char addr[BT_ADDRESS_STRING_SIZE];
1879 _bt_convert_addr_type_to_string(addr, address.addr);
1880 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1882 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1883 _bt_convert_addr_type_to_string(addr, address.addr);
1884 sender = (char*)g_dbus_method_invocation_get_sender(context);
1885 _bt_save_invocation_context(context, result, sender,
1886 function_name, (gpointer)addr);
1890 case BT_AVRCP_CONTROL_CONNECT: {
1891 bluetooth_device_address_t address = { {0} };
1893 __bt_service_get_parameters(in_param1,
1894 &address, sizeof(bluetooth_device_address_t));
1896 result = _bt_audio_is_profile_connection_in_progress(BT_AVRCP_CONTROL_CONNECT,
1899 if (result == BLUETOOTH_ERROR_NONE)
1900 result = _bt_audio_connect(BT_AVRCP, &address);
1902 if (result != BLUETOOTH_ERROR_NONE) {
1903 BT_ERR("AVRCP Control Connect Request has failed to execute");
1904 char addr[BT_ADDRESS_STRING_SIZE];
1905 _bt_convert_addr_type_to_string(addr, address.addr);
1906 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1908 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1909 _bt_convert_addr_type_to_string(addr, address.addr);
1910 sender = (char*)g_dbus_method_invocation_get_sender(context);
1911 _bt_save_invocation_context(context, result, sender,
1912 function_name, (gpointer)addr);
1916 case BT_AVRCP_CONTROL_DISCONNECT: {
1917 bluetooth_device_address_t address = { {0} };
1919 __bt_service_get_parameters(in_param1,
1920 &address, sizeof(bluetooth_device_address_t));
1922 result = _bt_audio_disconnect(BT_AVRCP, &address);
1923 if (result != BLUETOOTH_ERROR_NONE) {
1924 char addr[BT_ADDRESS_STRING_SIZE];
1925 _bt_convert_addr_type_to_string(addr, address.addr);
1926 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1928 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1929 _bt_convert_addr_type_to_string(addr, address.addr);
1930 sender = (char*)g_dbus_method_invocation_get_sender(context);
1931 _bt_save_invocation_context(context, result, sender,
1932 function_name, (gpointer)addr);
1936 case BT_AVRCP_HANDLE_CONTROL: {
1938 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1939 result = _bt_avrcp_control_cmd(key_code);
1942 case BT_AVRCP_HANDLE_CONTROL_TO_DEST: {
1944 bluetooth_device_address_t address = { { 0 } };
1946 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1947 __bt_service_get_parameters(in_param2,
1948 &address, sizeof(bluetooth_device_address_t));
1950 result = _bt_avrcp_control_cmd_to_dest(key_code, &address);
1953 case BT_AVRCP_CONTROL_SET_PROPERTY: {
1957 __bt_service_get_parameters(in_param1,
1958 &type, sizeof(int));
1959 __bt_service_get_parameters(in_param2,
1960 &value, sizeof(unsigned int));
1962 result = _bt_avrcp_control_set_property(type, value);
1965 case BT_AVRCP_TRANSPORT_SET_PROPERTY: {
1970 __bt_service_get_parameters(in_param1,
1971 &type, sizeof(int));
1972 __bt_service_get_parameters(in_param2,
1973 &value, sizeof(unsigned int));
1975 result = _bt_avrcp_transport_set_property(type, value);
1979 case BT_AVRCP_CONTROL_GET_PROPERTY: {
1982 __bt_service_get_parameters(in_param1, &type, sizeof(int));
1984 result = _bt_avrcp_control_get_property(type);
1985 /* Save invocation */
1986 if (result == BLUETOOTH_ERROR_NONE) {
1987 sender = (char*)g_dbus_method_invocation_get_sender(context);
1988 _bt_save_invocation_context(context, result, sender,
1989 function_name, g_memdup(&type, sizeof(int)));
1993 case BT_AVRCP_GET_TRACK_INFO: {
1994 result = _bt_avrcp_control_get_track_info();
1995 /* Save invocation */
1996 if (result == BLUETOOTH_ERROR_NONE) {
1997 sender = (char*)g_dbus_method_invocation_get_sender(context);
1998 _bt_save_invocation_context(context, result, sender,
1999 function_name, NULL);
2003 case BT_HDP_REGISTER_SINK_APP: {
2004 unsigned short data_type;
2005 bt_hdp_role_type_t role;
2006 bt_hdp_qos_type_t channel_type;
2007 int *app_id = g_new0(int, 1);
2009 __bt_service_get_parameters(in_param1,
2010 &data_type, sizeof(short));
2011 __bt_service_get_parameters(in_param2,
2012 &role, sizeof(bt_hdp_role_type_t));
2013 __bt_service_get_parameters(in_param3,
2014 &channel_type, sizeof(bt_hdp_qos_type_t));
2015 sender = (char*)g_dbus_method_invocation_get_sender(context);
2017 result = _bt_hdp_app_register(role,
2018 channel_type, data_type, sender, app_id);
2019 if (result != BLUETOOTH_ERROR_NONE) {
2020 g_array_append_vals(*out_param1, &app_id, sizeof(app_id));
2023 _bt_save_invocation_context(context, result, sender,
2024 function_name, (gpointer)app_id);
2028 case BT_HDP_UNREGISTER_SINK_APP: {
2030 int *app_id = g_new0(int, 1);
2032 app_handle = (char *)g_variant_get_data(in_param1);
2033 sscanf(app_handle, "health_app_%d", app_id);
2034 result = _bt_hdp_app_unregister(*app_id);
2035 if (result != BLUETOOTH_ERROR_NONE) {
2038 sender = (char*)g_dbus_method_invocation_get_sender(context);
2039 _bt_save_invocation_context(context, result, sender,
2040 function_name, (gpointer)app_id);
2044 case BT_HDP_CONNECT: {
2048 bt_hdp_connected_t *conn_info = NULL;
2050 conn_info = g_malloc0(sizeof(bt_hdp_connected_t));
2052 app_handle = (char *)g_variant_get_data(in_param1);
2053 conn_info->app_handle = app_handle;
2054 sscanf(app_handle, "health_app_%d", &app_id);
2056 __bt_service_get_parameters(in_param2,
2057 &(conn_info->type), sizeof(bt_hdp_qos_type_t));
2058 __bt_service_get_parameters(in_param3,
2059 &(conn_info->device_address),
2060 sizeof(bluetooth_device_address_t));
2062 result = _bt_hdp_connect(app_id, &(conn_info->device_address),
2063 conn_info->type, (int *)(&(conn_info->channel_id)));
2064 if (result != BLUETOOTH_ERROR_NONE) {
2065 g_array_append_vals(*out_param1, conn_info,
2066 sizeof(bt_hdp_connected_t));
2069 sender = (char*)g_dbus_method_invocation_get_sender(context);
2070 _bt_save_invocation_context(context, result, sender,
2071 function_name, (gpointer)conn_info);
2075 case BT_HDP_DISCONNECT: {
2076 bt_hdp_disconnected_t *hdp_disconn_info = NULL;
2078 hdp_disconn_info = g_malloc0(sizeof(bt_hdp_disconnected_t));
2080 __bt_service_get_parameters(in_param1,
2081 &(hdp_disconn_info->channel_id), sizeof(int));
2082 __bt_service_get_parameters(in_param2,
2083 &(hdp_disconn_info->device_address),
2084 sizeof(bluetooth_device_address_t));
2086 result = _bt_hdp_disconnect(hdp_disconn_info->channel_id);
2087 if (result != BLUETOOTH_ERROR_NONE) {
2088 g_array_append_vals(*out_param1, hdp_disconn_info,
2089 sizeof(bt_hdp_disconnected_t));
2090 g_free(hdp_disconn_info);
2092 sender = (char*)g_dbus_method_invocation_get_sender(context);
2093 _bt_save_invocation_context(context, result, sender,
2094 function_name, (gpointer)hdp_disconn_info);
2098 case BT_HDP_GET_FD: {
2099 int *channel_id = g_new0(int, 1);
2101 __bt_service_get_parameters(in_param1, channel_id, sizeof(int));
2103 result = _bt_hdp_get_fd(*channel_id);
2104 if (result != BLUETOOTH_ERROR_NONE) {
2107 sender = (char*)g_dbus_method_invocation_get_sender(context);
2108 _bt_save_invocation_context(context, result, sender,
2109 function_name, (gpointer)channel_id);
2113 case BT_HDP_SEND_DATA: {
2115 * This call to bt-service is only used for privilege check, so return
2116 * BLUETOOTH_ERROR_NONE from here.
2118 result = BLUETOOTH_ERROR_NONE;
2121 case BT_OOB_READ_LOCAL_DATA: { //208
2122 bt_oob_data_t local_oob_data;
2124 memset(&local_oob_data, 0x00, sizeof(bt_oob_data_t));
2125 result = _bt_oob_read_local_data(&local_oob_data);
2127 g_array_append_vals(*out_param1, &local_oob_data,
2128 sizeof(bt_oob_data_t));
2132 case BT_OOB_ADD_REMOTE_DATA: { //209
2133 bluetooth_device_address_t address = { {0} };
2134 unsigned short address_type;
2135 bt_oob_data_t remote_oob_data;
2137 __bt_service_get_parameters(in_param1,
2138 &address, sizeof(bluetooth_device_address_t));
2139 __bt_service_get_parameters(in_param2,
2140 &address_type, sizeof(unsigned short));
2141 __bt_service_get_parameters(in_param3,
2142 &remote_oob_data, sizeof(bt_oob_data_t));
2144 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2148 case BT_OOB_REMOVE_REMOTE_DATA: { //210
2149 bluetooth_device_address_t address = { {0} };
2151 __bt_service_get_parameters(in_param1,
2152 &address, sizeof(bluetooth_device_address_t));
2154 result = _bt_oob_remove_remote_data(&address);
2158 case BT_LE_OOB_READ_LOCAL_DATA: {
2159 bt_oob_data_t local_oob_data;
2160 bt_oob_data_t *local_oob_cache_data;
2162 local_oob_cache_data = _bt_le_oob_get_local_cache_data();
2163 if (local_oob_cache_data && local_oob_cache_data->eir_len) {
2164 g_array_append_vals(*out_param1, local_oob_cache_data,
2165 sizeof(bt_oob_data_t));
2166 return BLUETOOTH_ERROR_NONE;
2169 /* We should modify this logic in later */
2170 if (_bt_is_le_static_random_address_enabled() == false) {
2171 /* Seperate BT & LE address */
2172 _bt_set_le_static_random_address(TRUE);
2175 result = _bt_le_oob_read_local_data(&local_oob_data);
2176 _bt_le_oob_set_local_cache_data(&local_oob_data);
2178 g_array_append_vals(*out_param1, &local_oob_data,
2179 sizeof(bt_oob_data_t));
2183 case BT_LE_OOB_ADD_REMOTE_DATA: {
2184 bluetooth_device_address_t address = { {0} };
2185 unsigned short address_type;
2186 bt_oob_data_t remote_oob_data;
2188 __bt_service_get_parameters(in_param1,
2189 &address, sizeof(bluetooth_device_address_t));
2190 __bt_service_get_parameters(in_param2,
2191 &address_type, sizeof(unsigned short));
2192 __bt_service_get_parameters(in_param3,
2193 &remote_oob_data, sizeof(bt_oob_data_t));
2195 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2199 case BT_AVRCP_SET_TRACK_INFO: {
2200 media_metadata_t data;
2201 media_metadata_attributes_t meta_data;
2203 memset(&data, 0x00, sizeof(media_metadata_t));
2204 memset(&meta_data, 0x00, sizeof(media_metadata_attributes_t));
2206 __bt_service_get_parameters(in_param1,
2207 &data, sizeof(media_metadata_t));
2209 meta_data.title = g_strdup(data.title);
2210 meta_data.artist = g_strdup(data.artist);
2211 meta_data.album = g_strdup(data.album);
2212 meta_data.genre = g_strdup(data.genre);
2213 meta_data.total_tracks = data.total_tracks;
2214 meta_data.number = data.number;
2215 meta_data.duration = (int64_t) data.duration;
2217 result = _bt_avrcp_set_track_info(&meta_data);
2219 g_free((gpointer)meta_data.title);
2220 g_free((gpointer)meta_data.artist);
2221 g_free((gpointer)meta_data.album);
2222 g_free((gpointer)meta_data.genre);
2226 case BT_AVRCP_SET_PROPERTY: {
2230 sender = (char *)g_dbus_method_invocation_get_sender(context);
2232 __bt_service_get_parameters(in_param1,
2233 &type, sizeof(int));
2234 __bt_service_get_parameters(in_param2,
2235 &value, sizeof(unsigned int));
2237 if (value == STATUS_PLAYING) {
2238 if (current_sender_playing)
2239 g_free(current_sender_playing);
2240 current_sender_playing = g_strdup(sender);
2242 if (g_strcmp0(sender, current_sender_playing) == 0 ||
2243 current_sender_playing == NULL) {
2244 BT_INFO("Current Player Status %d type %d Sender %s", value, type, sender);
2246 BT_INFO("Current Player and this sender (%s) are different", sender);
2247 result = BLUETOOTH_ERROR_NONE;
2250 result = _bt_avrcp_set_property(type, value);
2254 case BT_AVRCP_SET_PROPERTIES: {
2255 media_player_settings_t properties;
2257 memset(&properties, 0x00, sizeof(media_player_settings_t));
2258 __bt_service_get_parameters(in_param1,
2259 &properties, sizeof(media_player_settings_t));
2261 result = _bt_avrcp_set_properties(&properties);
2265 case BT_SET_ADVERTISING_DATA: {
2268 bluetooth_advertising_data_t adv = { {0} };
2270 gboolean use_reserved_slot = FALSE;
2272 app = (char *)g_dbus_method_invocation_get_sender(context);
2273 adv_handle = g_malloc0(sizeof(int));
2275 __bt_service_get_parameters(in_param1,
2276 adv_handle, sizeof(int));
2277 __bt_service_get_parameters(in_param3,
2278 &length, sizeof(int));
2279 __bt_service_get_parameters(in_param2,
2281 __bt_service_get_parameters(in_param4,
2282 &use_reserved_slot, sizeof(gboolean));
2283 result = _bt_set_advertising_data(app, *adv_handle,
2284 &adv, length, use_reserved_slot);
2285 if (result != BLUETOOTH_ERROR_NONE) {
2286 BT_ERR("Set Advertising data failed!!");
2289 _bt_save_invocation_context(context, result, app,
2290 function_name, (gpointer)adv_handle);
2294 case BT_SET_SCAN_RESPONSE_DATA: {
2297 bluetooth_scan_resp_data_t rsp = { {0} };
2299 gboolean use_reserved_slot = FALSE;
2301 app = (char *)g_dbus_method_invocation_get_sender(context);
2302 adv_handle = g_malloc0(sizeof(int));
2304 __bt_service_get_parameters(in_param1,
2305 adv_handle, sizeof(int));
2306 __bt_service_get_parameters(in_param3,
2307 &length, sizeof(int));
2308 __bt_service_get_parameters(in_param2,
2310 __bt_service_get_parameters(in_param4,
2311 &use_reserved_slot, sizeof(gboolean));
2313 result = _bt_set_scan_response_data(app, *adv_handle,
2314 &rsp, length, use_reserved_slot);
2316 if (result != BLUETOOTH_ERROR_NONE) {
2317 BT_ERR("Set Scan Response Data failed!!");
2320 _bt_save_invocation_context(context, result, app,
2321 function_name, (gpointer)adv_handle);
2325 case BT_SET_ADVERTISING: {
2328 gboolean enable = FALSE;
2329 gboolean use_reserved_slot = FALSE;
2331 adv_handle = g_malloc0(sizeof(int));
2332 __bt_service_get_parameters(in_param1,
2333 adv_handle, sizeof(int));
2334 __bt_service_get_parameters(in_param2,
2335 &enable, sizeof(gboolean));
2336 __bt_service_get_parameters(in_param3,
2337 &use_reserved_slot, sizeof(gboolean));
2339 app = (char *)g_dbus_method_invocation_get_sender(context);
2341 result = _bt_set_advertising(app, *adv_handle,
2342 enable, use_reserved_slot);
2343 if (result != BLUETOOTH_ERROR_NONE) {
2344 BT_ERR("Start Advertising failed!!");
2347 _bt_save_invocation_context(context, result, app,
2348 function_name, (gpointer)adv_handle);
2352 case BT_SET_CUSTOM_ADVERTISING: {
2355 gboolean enable = FALSE;
2356 bluetooth_advertising_params_t adv_params;
2357 gboolean use_reserved_slot = FALSE;
2359 app = (char *)g_dbus_method_invocation_get_sender(context);
2360 adv_handle = g_malloc0(sizeof(int));
2362 __bt_service_get_parameters(in_param1, adv_handle,
2364 __bt_service_get_parameters(in_param2, &enable,
2366 __bt_service_get_parameters(in_param3, &adv_params,
2367 sizeof(bluetooth_advertising_params_t));
2368 __bt_service_get_parameters(in_param4, &use_reserved_slot,
2371 BT_DBG("bluetooth_advertising_params_t [%d %d %d %d %d]",
2372 adv_params.interval_min, adv_params.interval_max,
2373 adv_params.filter_policy, adv_params.type, adv_params.tx_power_level);
2374 result = _bt_set_custom_advertising(app, *adv_handle,
2375 enable, &adv_params, use_reserved_slot);
2376 if (result != BLUETOOTH_ERROR_NONE) {
2377 BT_ERR("Start Custom Advertising failed!!");
2380 _bt_save_invocation_context(context, result, app,
2381 function_name, (gpointer)adv_handle);
2385 case BT_GET_SCAN_RESPONSE_DATA: {
2386 bluetooth_scan_resp_data_t rsp = { {0} };
2390 app = (char *)g_dbus_method_invocation_get_sender(context);
2392 __bt_service_get_parameters(in_param1, &adv_handle,
2395 result = _bt_get_scan_response_data(app, adv_handle, &rsp, &length);
2396 if (result == BLUETOOTH_ERROR_NONE)
2397 g_array_append_vals(*out_param1, rsp.data, length);
2401 case BT_GET_ADVERTISING_DATA: {
2402 bluetooth_advertising_data_t adv = { {0} };
2406 app = (char *)g_dbus_method_invocation_get_sender(context);
2408 __bt_service_get_parameters(in_param1, &adv_handle,
2411 result = _bt_get_advertising_data(app, adv_handle, &adv, &length);
2412 if (result == BLUETOOTH_ERROR_NONE)
2413 g_array_append_vals(*out_param1, adv.data, length);
2417 case BT_GATT_REGISTER_APPLICATION: {
2418 BT_DBG("Register GATT application:Unhandled!!");
2421 case BT_GATT_SERVER_REGISTER: {
2422 BT_DBG("GATT Server instance initialization");
2425 app = (char *)g_dbus_method_invocation_get_sender(context);
2426 BT_DBG("GATT Server Unique Name [%s]", app);
2428 /* No ADV handle: Set 0 */
2429 result = _bt_register_server_instance(app, 0);
2431 if (result != BLUETOOTH_ERROR_NONE) {
2432 BT_ERR("GATT Server registration failed. result %d", result);
2434 _bt_save_invocation_context(context, result, app,
2435 function_name, NULL);
2439 case BT_GATT_SERVER_DEREGISTER: {
2441 app = (char*)g_dbus_method_invocation_get_sender(context);
2443 result = _bt_unregister_server_instance(app, 0/* Adv Handle*/);
2446 case BT_GATT_SERVER_ADD_SERVICE: {
2447 BT_DBG("GATT Server Add Service");
2453 int *tmp_inst_id = NULL;
2455 app = (char *)g_dbus_method_invocation_get_sender(context);
2457 __bt_service_get_parameters(in_param1, &service_type,
2459 __bt_service_get_parameters(in_param2, &num_handles,
2461 svc_uuid = (char *)g_variant_get_data(in_param3);
2462 __bt_service_get_parameters(in_param4, &instance_id,
2465 result = _bt_gatt_server_add_service(app, service_type, num_handles, svc_uuid, instance_id);
2466 if (result != BLUETOOTH_ERROR_NONE) {
2467 BT_ERR("GATT Server Add Service failed!!");
2469 tmp_inst_id = g_malloc0(sizeof(int));
2470 *tmp_inst_id = instance_id;
2471 _bt_save_invocation_context(context, result, app,
2472 function_name, (gpointer)tmp_inst_id);
2476 case BT_GATT_SERVER_ADD_CHARACTERISTIC: {
2477 BT_DBG("GATT Server Add Characteristic");
2480 int *tmp_inst_id = NULL;
2481 bluetooth_gatt_server_attribute_params_t param;
2482 memset(¶m, 0, sizeof(bluetooth_gatt_server_attribute_params_t));
2484 app = (char*)g_dbus_method_invocation_get_sender(context);
2486 __bt_service_get_parameters(in_param1, ¶m,
2487 sizeof(bluetooth_gatt_server_attribute_params_t));
2488 char_uuid = (char *)g_variant_get_data(in_param2);
2490 result = _bt_gatt_server_add_characteristic(app, char_uuid, ¶m);
2491 if (result != BLUETOOTH_ERROR_NONE) {
2492 BT_ERR("GATT Server Add Service failed!!");
2494 tmp_inst_id = g_malloc0(sizeof(int));
2495 *tmp_inst_id = param.instance_id;
2497 _bt_save_invocation_context(context, result, app,
2498 function_name, (gpointer)tmp_inst_id);
2502 case BT_GATT_SERVER_ADD_DESCRIPTOR: {
2503 BT_DBG("GATT Server Add Descriptor");
2507 bt_gatt_permission_t perm;
2509 int *tmp_inst_id = NULL;
2510 memset(&perm, 0, sizeof(bt_gatt_permission_t));
2512 app = (char *)g_dbus_method_invocation_get_sender(context);
2514 __bt_service_get_parameters(in_param1, &service_handle,
2516 __bt_service_get_parameters(in_param2, &instance_id,
2518 desc_uuid = (char *)g_variant_get_data(in_param4);
2519 __bt_service_get_parameters(in_param3, &perm,
2520 sizeof(bt_gatt_permission_t));
2522 result = _bt_gatt_server_add_descriptor(app, desc_uuid, &perm, service_handle, instance_id);
2523 if (result != BLUETOOTH_ERROR_NONE) {
2524 BT_ERR("GATT Server Add Service failed!!");
2526 tmp_inst_id = g_malloc0(sizeof(int));
2527 *tmp_inst_id = instance_id;
2528 _bt_save_invocation_context(context, result, app,
2529 function_name, (gpointer)tmp_inst_id);
2533 case BT_GATT_SERVER_START_SERVICE: {
2538 int *tmp_inst_id = NULL;
2539 app = (char*)g_dbus_method_invocation_get_sender(context);
2541 __bt_service_get_parameters(in_param1, &service_handle,
2543 __bt_service_get_parameters(in_param2, &instance_id,
2546 result = _bt_gatt_server_start_service(app, service_handle, instance_id);
2548 if (BLUETOOTH_ERROR_NONE == result) {
2549 tmp_inst_id = g_malloc0(sizeof(int));
2550 *tmp_inst_id = instance_id;
2551 _bt_save_invocation_context(context, result, app,
2552 function_name, (gpointer)tmp_inst_id);
2556 case BT_GATT_SERVER_STOP_SERVICE: {
2560 int *tmp_inst_id = NULL;
2561 app = (char*)g_dbus_method_invocation_get_sender(context);
2563 __bt_service_get_parameters(in_param1, &service_handle,
2565 __bt_service_get_parameters(in_param2, &instance_id,
2568 result = _bt_gatt_server_stop_service(app, service_handle, instance_id);
2570 if (BLUETOOTH_ERROR_NONE == result) {
2571 tmp_inst_id = g_malloc0(sizeof(int));
2572 *tmp_inst_id = instance_id;
2573 _bt_save_invocation_context(context, result, app,
2574 function_name, (gpointer)tmp_inst_id);
2578 case BT_GATT_SERVER_DELETE_SERVICE: {
2581 int *tmp_inst_id = NULL;
2583 app = (char*)g_dbus_method_invocation_get_sender(context);
2585 __bt_service_get_parameters(in_param1, &service_handle,
2587 __bt_service_get_parameters(in_param2, &instance_id,
2590 result = _bt_gatt_server_delete_service(app, service_handle, instance_id);
2592 if (BLUETOOTH_ERROR_NONE == result) {
2593 tmp_inst_id = g_malloc0(sizeof(int));
2594 *tmp_inst_id = instance_id;
2595 _bt_save_invocation_context(context, result, app,
2596 function_name, (gpointer)tmp_inst_id);
2600 case BT_GATT_SERVER_SEND_RESPONSE: {
2601 bluetooth_gatt_server_response_params_t param;
2602 bluetooth_gatt_att_data_t data;
2605 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_response_params_t));
2606 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2608 app = (char*)g_dbus_method_invocation_get_sender(context);
2610 __bt_service_get_parameters(in_param1, &data,
2611 sizeof(bluetooth_gatt_att_data_t));
2612 __bt_service_get_parameters(in_param2, ¶m,
2613 sizeof(bluetooth_gatt_server_response_params_t));
2615 result = _bt_gatt_server_send_response(app, &data, ¶m);
2619 case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE: {
2621 bluetooth_gatt_server_acquire_response_params_t param;
2624 msg = g_dbus_method_invocation_get_message(context);
2625 GUnixFDList *fd_list;
2630 fd_list = g_dbus_message_get_unix_fd_list(msg);
2632 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2634 app = (char*)g_dbus_method_invocation_get_sender(context);
2636 __bt_service_get_parameters(in_param1, ¶m,
2637 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2639 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2640 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2641 fd = fd_list_array[0];
2644 result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
2648 case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE: {
2650 bluetooth_gatt_server_acquire_response_params_t param;
2653 msg = g_dbus_method_invocation_get_message(context);
2654 GUnixFDList *fd_list;
2659 fd_list = g_dbus_message_get_unix_fd_list(msg);
2661 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2663 app = (char*)g_dbus_method_invocation_get_sender(context);
2665 __bt_service_get_parameters(in_param1, ¶m,
2666 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2668 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2669 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2670 fd = fd_list_array[0];
2673 result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
2677 case BT_GATT_SERVER_SEND_INDICATION: {
2678 bluetooth_gatt_server_indication_params_t param;
2679 bluetooth_gatt_att_data_t data;
2680 bluetooth_device_address_t address;
2683 app = (char*)g_dbus_method_invocation_get_sender(context);
2685 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_indication_params_t));
2686 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2687 memset(&address, 0x00, sizeof(bluetooth_device_address_t));
2689 __bt_service_get_parameters(in_param1, &data,
2690 sizeof(bluetooth_gatt_att_data_t));
2691 __bt_service_get_parameters(in_param2, ¶m,
2692 sizeof(bluetooth_gatt_server_indication_params_t));
2693 __bt_service_get_parameters(in_param3, &address,
2694 sizeof(bluetooth_device_address_t));
2696 result = _bt_gatt_server_send_indication(app, &address, &data, ¶m);
2700 case BT_GATT_SERVER_UPDATE_VALUE: {
2701 bluetooth_gatt_server_update_value_t param;
2705 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_update_value_t));
2707 app = (char*)g_dbus_method_invocation_get_sender(context);
2709 __bt_service_get_parameters(in_param1, &instance_id,
2711 __bt_service_get_parameters(in_param2, ¶m,
2712 sizeof(bluetooth_gatt_server_update_value_t));
2714 result = _bt_gatt_server_update_attribute_value(app, instance_id, ¶m);
2717 case BT_GET_ATT_MTU: {
2718 bluetooth_device_address_t address = { {0} };
2719 unsigned int mtu = 0;
2721 __bt_service_get_parameters(in_param1,
2722 &address, sizeof(bluetooth_device_address_t));
2723 result = _bt_get_att_mtu(&address, &mtu);
2724 BT_DBG("MTU: %d", mtu);
2726 if (result == BLUETOOTH_ERROR_NONE) {
2727 g_array_append_vals(*out_param1, &mtu,
2728 sizeof(unsigned int));
2732 case BT_REQ_ATT_MTU: {
2733 bluetooth_device_address_t address = { {0} };
2737 sender = (char*)g_dbus_method_invocation_get_sender(context);
2739 __bt_service_get_parameters(in_param1,
2740 &address, sizeof(bluetooth_device_address_t));
2741 __bt_service_get_parameters(in_param2,
2742 &mtu, sizeof(unsigned int));
2743 BT_DBG("BT_REQ_ATT_MTU: %d", mtu);
2744 result = _bt_request_att_mtu(&address, mtu);
2745 if (BLUETOOTH_ERROR_NONE == result) {
2746 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2748 _bt_convert_addr_type_to_string(addr, address.addr);
2750 /* Save the informations to invocation */
2751 _bt_save_invocation_context(context, result, sender,
2752 function_name, (gpointer)addr);
2754 g_array_append_vals(*out_param1, &address,
2755 sizeof(bluetooth_device_address_t));
2759 case BT_GET_DEVICE_IDA: {
2760 bluetooth_device_address_t address = { {0} };
2761 bluetooth_device_address_t id_addr = { {0} };
2763 __bt_service_get_parameters(in_param1,
2764 &address, sizeof(bluetooth_device_address_t));
2766 result = _bt_device_get_ida(&address, &id_addr);
2768 if (result == BLUETOOTH_ERROR_NONE) {
2769 g_array_append_vals(*out_param1, &id_addr,
2770 sizeof(bluetooth_device_address_t));
2774 case BT_SET_LE_STATIC_RANDOM_ADDRESS: {
2777 __bt_service_get_parameters(in_param1, &is_enable,
2780 result = _bt_set_le_static_random_address(is_enable);
2785 case BT_GATT_CLIENT_REGISTER: {
2786 bluetooth_device_address_t address = { {0} };
2789 sender = (char*)g_dbus_method_invocation_get_sender(context);
2791 __bt_service_get_parameters(in_param1,
2792 &address, sizeof(bluetooth_device_address_t));
2794 result = _bt_register_gatt_client_instance(sender, &address);
2795 if (BLUETOOTH_ERROR_NONE == result) {
2796 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2798 _bt_convert_addr_type_to_string(addr, address.addr);
2800 /* Save the informations to invocation */
2801 _bt_save_invocation_context(context, result, sender,
2802 function_name, (gpointer)addr);
2807 case BT_GATT_CLIENT_UNREGISTER: {
2810 sender = (char*)g_dbus_method_invocation_get_sender(context);
2811 __bt_service_get_parameters(in_param1,
2812 &client_id, sizeof(int));
2814 result = _bt_unregister_gatt_client_instance(sender, client_id);
2818 /* Async: Remote Interaction */
2819 case BT_GATT_ACQUIRE_WRITE: {
2823 bluetooth_gatt_client_char_prop_info_t param;
2825 sender = (char*)g_dbus_method_invocation_get_sender(context);
2827 __bt_service_get_parameters(in_param1, ¶m,
2828 sizeof(bluetooth_gatt_client_char_prop_info_t));
2831 result = _bt_gatt_acquire_write(¶m , &fd, &mtu);
2833 g_array_append_vals(*out_param1, &mtu, sizeof(int));
2835 if (BLUETOOTH_ERROR_NONE == result)
2836 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
2838 BT_ERR("GATT Client: gatt acquire write failed");
2842 GUnixFDList *fd_list = NULL;
2843 GError *error = NULL;
2845 /* Add socket fd to unix_fd_list */
2846 fd_list = g_unix_fd_list_new();
2847 g_unix_fd_list_append(fd_list, fd, &error);
2848 g_assert_no_error(error);
2850 _bt_service_method_return_with_unix_fd_list(
2851 context, *out_param1, result, fd_list);
2854 g_object_unref(fd_list);
2858 /* Async: Remote Interaction */
2859 case BT_CONNECT_LE: {
2860 bluetooth_device_address_t address = { {0} };
2861 gboolean auto_connect;
2865 sender = (char*)g_dbus_method_invocation_get_sender(context);
2867 __bt_service_get_parameters(in_param1,
2868 &address, sizeof(bluetooth_device_address_t));
2869 __bt_service_get_parameters(in_param2,
2870 &auto_connect, sizeof(gboolean));
2871 __bt_service_get_parameters(in_param3,
2872 &client_id, sizeof(int));
2874 BT_DBG("GATT Client: client_id[%d]", client_id);
2875 result = _bt_connect_le_device(&address, auto_connect, client_id);
2876 if (BLUETOOTH_ERROR_NONE == result) {
2877 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2878 _bt_convert_addr_type_to_string(addr, address.addr);
2880 /* Save the informations to invocation */
2881 _bt_save_invocation_context(context, result, sender,
2882 function_name, (gpointer)addr);
2885 _bt_handle_invocation_context(function_name, (void *)addr);
2887 BT_ERR("GATT Client: gatt connect failed. client_id[%d]", client_id);
2888 g_array_append_vals(*out_param1, &address,
2889 sizeof(bluetooth_device_address_t));
2893 /* Async: Remote Interaction */
2894 case BT_DISCONNECT_LE: {
2895 bluetooth_device_address_t address = { {0} };
2899 sender = (char*)g_dbus_method_invocation_get_sender(context);
2901 __bt_service_get_parameters(in_param1,
2902 &address, sizeof(bluetooth_device_address_t));
2903 __bt_service_get_parameters(in_param2,
2904 &client_id, sizeof(int));
2906 BT_INFO("GATT Disconnect using client Interface [%d]", client_id);
2907 result = _bt_disconnect_le_device(&address, client_id);
2908 if (BLUETOOTH_ERROR_NONE == result) {
2909 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2911 _bt_convert_addr_type_to_string(addr, address.addr);
2913 /* Save the informations to invocation */
2914 _bt_save_invocation_context(context, result, sender,
2915 function_name, (gpointer)addr);
2917 g_array_append_vals(*out_param1, &address,
2918 sizeof(bluetooth_device_address_t));
2923 case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS: {
2924 guint available_packets = 0;
2926 result = _bt_gatt_get_data_batching_available_packets(&available_packets);
2927 BT_DBG("LE batching available packets %u", available_packets);
2928 if (result == BLUETOOTH_ERROR_NONE) {
2929 g_array_append_vals(*out_param1, &available_packets,
2936 case BT_ENABLE_GATT_DATA_BATCHING: {
2937 bluetooth_device_address_t address = { {0} };
2938 int packet_threshold;
2941 __bt_service_get_parameters(in_param1,
2942 &address, sizeof(bluetooth_device_address_t));
2943 __bt_service_get_parameters(in_param2,
2944 &packet_threshold, sizeof(int));
2945 __bt_service_get_parameters(in_param3,
2946 &timeout, sizeof(int));
2947 result = _bt_gatt_enable_data_batching(&address, packet_threshold, timeout);
2952 case BT_DISABLE_GATT_DATA_BATCHING: {
2953 bluetooth_device_address_t address = { {0} };
2955 __bt_service_get_parameters(in_param1,
2956 &address, sizeof(bluetooth_device_address_t));
2957 result = _bt_gatt_disable_data_batching(&address);
2962 case BT_GATT_GET_PRIMARY_SERVICES: {
2965 sender = (char*)g_dbus_method_invocation_get_sender(context);
2966 bluetooth_device_address_t address = { {0} };
2968 __bt_service_get_parameters(in_param1, &address,
2969 sizeof(bluetooth_device_address_t));
2971 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
2972 _bt_convert_addr_type_to_string(addr, address.addr);
2974 result = _bt_gatt_get_primary_services(addr);
2975 if (BLUETOOTH_ERROR_NONE == result) {
2976 _bt_save_invocation_context(context, result, sender,
2977 function_name, (gpointer)addr);
2983 case BT_GATT_GET_SERVICE_PROPERTIES: {
2984 bluetooth_gatt_client_svc_prop_info_t param;
2986 sender = (char*)g_dbus_method_invocation_get_sender(context);
2987 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_svc_prop_info_t));
2989 __bt_service_get_parameters(in_param1, ¶m,
2990 sizeof(bluetooth_gatt_client_svc_prop_info_t));
2992 result = _bt_gatt_get_all_characteristic(¶m);
2993 if (BLUETOOTH_ERROR_NONE == result) {
2994 /* Save the informations to invocation */
2995 _bt_save_invocation_context(context, result, sender,
2997 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_svc_prop_info_t)));
3001 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: {
3002 bluetooth_gatt_client_char_prop_info_t param;
3004 sender = (char*)g_dbus_method_invocation_get_sender(context);
3005 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3007 __bt_service_get_parameters(in_param1, ¶m,
3008 sizeof(bluetooth_gatt_client_char_prop_info_t));
3010 result = _bt_gatt_get_all_characteristic_properties(¶m);
3011 if (BLUETOOTH_ERROR_NONE == result) {
3012 /* Save the informations to invocation */
3013 _bt_save_invocation_context(context, result, sender,
3015 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3019 /* Async: Remote Interaction */
3020 case BT_GATT_READ_CHARACTERISTIC: {
3021 bluetooth_gatt_client_char_prop_info_t param;
3023 sender = (char*)g_dbus_method_invocation_get_sender(context);
3024 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3026 __bt_service_get_parameters(in_param1, ¶m,
3027 sizeof(bluetooth_gatt_client_char_prop_info_t));
3029 result = _bt_gatt_read_characteristic_value(¶m);
3030 if (BLUETOOTH_ERROR_NONE == result) {
3031 /* Save the informations to invocation */
3032 _bt_save_invocation_context(context, result, sender,
3034 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3038 /* Async: Remote Interaction */
3039 case BT_GATT_READ_DESCRIPTOR_VALUE: {
3040 bluetooth_gatt_client_desc_prop_info_t param;
3042 sender = (char*)g_dbus_method_invocation_get_sender(context);
3043 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3045 __bt_service_get_parameters(in_param1, ¶m,
3046 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3048 result = _bt_gatt_read_descriptor_value(¶m);
3049 if (BLUETOOTH_ERROR_NONE == result) {
3050 /* Save the informations to invocation */
3051 _bt_save_invocation_context(context, result, sender,
3053 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3057 /* Async: Remote Interaction */
3058 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: {
3059 bluetooth_gatt_client_char_prop_info_t param;
3060 bluetooth_gatt_att_data_t data;
3061 bluetooth_gatt_write_type_e write_type;
3063 sender = (char*)g_dbus_method_invocation_get_sender(context);
3065 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3066 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3068 __bt_service_get_parameters(in_param1, ¶m,
3069 sizeof(bluetooth_gatt_client_char_prop_info_t));
3070 __bt_service_get_parameters(in_param2, &data,
3071 sizeof(bluetooth_gatt_att_data_t));
3072 __bt_service_get_parameters(in_param3, &write_type,
3073 sizeof(bluetooth_gatt_write_type_e));
3075 result = _bt_gatt_write_characteristic_value_by_type(¶m , &data, write_type);
3076 if (BLUETOOTH_ERROR_NONE == result) {
3077 /* Save the informations to invocation */
3078 _bt_save_invocation_context(context, result, sender,
3080 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3084 /* Async: Remote Interaction */
3085 case BT_GATT_WRITE_DESCRIPTOR_VALUE: {
3086 bluetooth_gatt_client_desc_prop_info_t param;
3087 bluetooth_gatt_att_data_t data;
3088 bluetooth_gatt_write_type_e write_type;
3090 sender = (char*)g_dbus_method_invocation_get_sender(context);
3091 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3092 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3094 __bt_service_get_parameters(in_param1, ¶m,
3095 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3096 __bt_service_get_parameters(in_param2, &data,
3097 sizeof(bluetooth_gatt_att_data_t));
3098 __bt_service_get_parameters(in_param3, &write_type,
3099 sizeof(bluetooth_gatt_write_type_e));
3101 result = _bt_gatt_write_descriptor_value_by_type(¶m, &data, write_type);
3102 if (BLUETOOTH_ERROR_NONE == result) {
3103 /* Save the informations to invocation */
3104 _bt_save_invocation_context(context, result, sender,
3106 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3111 case BT_GATT_WATCH_CHARACTERISTIC: {
3112 bluetooth_gatt_client_char_prop_info_t param;
3117 gboolean is_indicate;
3120 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3122 sender = (char*)g_dbus_method_invocation_get_sender(context);
3124 __bt_service_get_parameters(in_param1, ¶m,
3125 sizeof(bluetooth_gatt_client_char_prop_info_t));
3126 __bt_service_get_parameters(in_param2, &client_id,
3128 __bt_service_get_parameters(in_param3, &is_notify,
3130 __bt_service_get_parameters(in_param4, &is_indicate,
3133 #ifdef TIZEN_FEATURE_BT_GATT_CLIENT_FD_DISABLE
3137 if (is_indicate == false) {
3138 result = _bt_gatt_acquire_notify(¶m , &fd, &mtu);
3139 if (BLUETOOTH_ERROR_NONE == result && fd > -1) {
3140 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
3142 GUnixFDList *fd_list = NULL;
3143 GError *error = NULL;
3145 g_array_append_vals(*out_param1, &mtu, sizeof(int));
3146 /* Add socket fd to unix_fd_list */
3147 fd_list = g_unix_fd_list_new();
3148 g_unix_fd_list_append(fd_list, fd, &error);
3149 g_assert_no_error(error);
3151 _bt_service_method_return_with_unix_fd_list(
3152 context, *out_param1, result, fd_list);
3154 g_object_unref(fd_list);
3160 result = _bt_gatt_watch_characteristic(¶m , client_id, is_notify);
3161 if (BLUETOOTH_ERROR_NONE == result) {
3162 /* Save the informations to invocation */
3163 _bt_save_invocation_context(context, result, sender, function_name,
3164 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3169 case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: {
3170 gboolean is_enabled;
3171 bluetooth_device_address_t address;
3173 sender = (char*)g_dbus_method_invocation_get_sender(context);
3175 __bt_service_get_parameters(in_param1,
3176 &address, sizeof(bluetooth_device_address_t));
3177 __bt_service_get_parameters(in_param2, &is_enabled,
3179 result = _bt_gatt_watch_service_changed_indication(sender, &address, is_enabled);
3180 BT_INFO("Service changed indication from app [%s]", sender);
3184 case BT_LE_CONN_UPDATE: {
3185 char *sender = NULL;
3186 bluetooth_device_address_t local_address = { {0} };
3187 bluetooth_le_connection_param_t parameters = {0};
3189 sender = (char *)g_dbus_method_invocation_get_sender(context);
3191 __bt_service_get_parameters(in_param1, &local_address,
3192 sizeof(bluetooth_device_address_t));
3193 __bt_service_get_parameters(in_param2, ¶meters,
3194 sizeof(bluetooth_le_connection_param_t));
3196 result = _bt_le_connection_update(sender,
3198 parameters.interval_min,
3199 parameters.interval_max,
3201 parameters.timeout);
3204 case BT_START_LE_DISCOVERY: {
3208 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3210 sender = (char *)g_dbus_method_invocation_get_sender(context);
3212 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3213 BT_ERR("Fail to get the sender pid");
3215 result = _bt_start_le_scan(sender, uid, pid);
3216 if (result == BLUETOOTH_ERROR_NONE) {
3217 _bt_save_invocation_context(context, result, sender,
3218 function_name, NULL);
3220 BT_DBG("Remeber pid / uid for the scan operation");
3221 _bt_bm_add_scan_app(SCAN_LE, uid, pid);
3225 case BT_STOP_LE_DISCOVERY: {
3229 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3231 sender = (char *)g_dbus_method_invocation_get_sender(context);
3233 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3234 BT_ERR("Fail to get the sender pid");
3236 result = _bt_stop_le_scan(sender);
3237 if (result == BLUETOOTH_ERROR_NONE) {
3238 _bt_save_invocation_context(context, result, sender,
3239 function_name, NULL);
3242 BT_DBG("Remove pid / uid for the scan operation");
3243 _bt_bm_remove_scan_app(SCAN_LE, uid, pid);
3247 case BT_IS_LE_DISCOVERYING: {
3248 gboolean le_discovering = FALSE;
3250 le_discovering = _bt_is_le_scanning();
3251 g_array_append_vals(*out_param1,
3252 &le_discovering, sizeof(gboolean));
3255 case BT_SET_SCAN_PARAMETERS: {
3256 bluetooth_le_scan_params_t scan_params;
3258 __bt_service_get_parameters(in_param1, &scan_params,
3259 sizeof(bluetooth_le_scan_params_t));
3261 BT_DBG("bluetooth_le_scan_params_t [%f %f %d]",
3262 scan_params.interval, scan_params.window,
3265 result = _bt_prepare_scan_parameters(&scan_params, 0);
3268 case BT_SET_SCAN_TYPE: {
3270 __bt_service_get_parameters(in_param1, &scan_type, sizeof(int));
3272 BT_DBG("bluetooth_le_scan_type [%d]", scan_type);
3273 result = _bt_prepare_scan_parameters(NULL, scan_type);
3276 #ifdef TIZEN_FEATURE_BT_PAN_NAP
3277 case BT_NETWORK_ACTIVATE:
3278 BT_DBG("BT_NETWORK_ACTIVATE Request recieved Request Handler ");
3279 result = _bt_network_activate();
3281 case BT_NETWORK_DEACTIVATE:
3282 result = _bt_network_deactivate();
3284 case BT_NETWORK_CONNECT: {
3285 bluetooth_device_address_t address = { {0} };
3288 __bt_service_get_parameters(in_param1,
3289 &address, sizeof(bluetooth_device_address_t));
3290 __bt_service_get_parameters(in_param2,
3291 &role, sizeof(int));
3293 result = _bt_network_connect(request_id, role, &address);
3294 if (result != BLUETOOTH_ERROR_NONE) {
3295 g_array_append_vals(*out_param1, &address,
3296 sizeof(bluetooth_device_address_t));
3300 case BT_NETWORK_DISCONNECT: {
3301 bluetooth_device_address_t address = { {0} };
3303 __bt_service_get_parameters(in_param1,
3304 &address, sizeof(bluetooth_device_address_t));
3306 result = _bt_network_disconnect(request_id, &address);
3307 if (result != BLUETOOTH_ERROR_NONE) {
3308 g_array_append_vals(*out_param1, &address,
3309 sizeof(bluetooth_device_address_t));
3313 case BT_NETWORK_SERVER_DISCONNECT: {
3314 bluetooth_device_address_t address = { {0} };
3316 __bt_service_get_parameters(in_param1,
3317 &address, sizeof(bluetooth_device_address_t));
3319 result = _bt_network_server_disconnect(request_id, &address);
3320 if (result != BLUETOOTH_ERROR_NONE) {
3321 g_array_append_vals(*out_param1, &address,
3322 sizeof(bluetooth_device_address_t));
3328 #ifdef TIZEN_FEATURE_BT_IPSP
3329 case BT_LE_IPSP_INIT:
3330 result = _bt_initialize_ipsp();
3332 case BT_LE_IPSP_DEINIT:
3333 result = _bt_deinitialize_ipsp();
3335 case BT_LE_IPSP_CONNECT: {
3336 bluetooth_device_address_t address = { {0} };
3337 __bt_service_get_parameters(in_param1, &address,
3338 sizeof(bluetooth_device_address_t));
3339 result = _bt_connect_le_ipsp_device(&address);
3342 case BT_LE_IPSP_DISCONNECT: {
3343 bluetooth_device_address_t address = { {0} };
3344 __bt_service_get_parameters(in_param1, &address,
3345 sizeof(bluetooth_device_address_t));
3346 result = _bt_disconnect_le_ipsp_device(&address);
3350 case BT_IS_ADVERTISING: {
3351 gboolean advertising = FALSE;
3352 advertising = _bt_is_advertising();
3353 g_array_append_vals(*out_param1, &advertising,
3357 case BT_IS_LE_2M_PHY_SUPPORTED: {
3358 gboolean is_2m_phy_supported = FALSE;
3360 is_2m_phy_supported = _bt_is_le_2m_phy_supported();
3361 g_array_append_vals(*out_param1, &is_2m_phy_supported, sizeof(gboolean));
3364 case BT_IS_LE_CODED_PHY_SUPPORTED: {
3365 gboolean is_coded_phy_supported = FALSE;
3367 is_coded_phy_supported = _bt_is_le_coded_phy_supported();
3368 g_array_append_vals(*out_param1, &is_coded_phy_supported, sizeof(gboolean));
3371 case BT_DISCONNECT_DEVICE: {
3372 bluetooth_device_address_t address = { {0} };
3374 __bt_service_get_parameters(in_param1,
3375 &address, sizeof(bluetooth_device_address_t));
3377 result = _bt_disconnect_device(&address);
3380 case BT_REGISTER_SCAN_FILTER: {
3381 bluetooth_le_scan_filter_t scan_filter;
3383 sender = (char*)g_dbus_method_invocation_get_sender(context);
3384 __bt_service_get_parameters(in_param1, &scan_filter,
3385 sizeof(bluetooth_le_scan_filter_t));
3387 BT_DBG("bluetooth_le_scan_filter_t [features : 0x%.2x]",
3388 scan_filter.added_features);
3390 result = _bt_register_scan_filter(sender, &scan_filter);
3395 case BT_TDS_PROVIDER_REGISTER: {
3396 char *sender = NULL;
3398 sender = (char *)g_dbus_method_invocation_get_sender(context);
3399 result = _bt_tds_provider_register(sender);
3404 case BT_TDS_PROVIDER_UNREGISTER: {
3405 char *sender = NULL;
3407 sender = (char *)g_dbus_method_invocation_get_sender(context);
3408 result = _bt_tds_provider_unregister(sender);
3413 case BT_TDS_PROVIDER_SET_MANUF_DATA: {
3414 char *sender = NULL;
3415 unsigned int length = 0;
3416 bluetooth_advertising_data_t manuf_data;
3418 __bt_service_get_parameters(in_param1,
3419 &length, sizeof(unsigned int));
3420 __bt_service_get_parameters(in_param2,
3421 &manuf_data, sizeof(bluetooth_advertising_data_t));
3422 sender = (char *)g_dbus_method_invocation_get_sender(context);
3424 result = _bt_tds_provider_set_manuf_data(sender, manuf_data.data, length);
3428 case BT_TDS_PROVIDER_CREATE: {
3429 char *sender = NULL;
3430 unsigned int tds_handle = 0;
3433 __bt_service_get_parameters(in_param1,
3434 &tds_handle, sizeof(unsigned int));
3435 __bt_service_get_parameters(in_param2,
3436 &transport, sizeof(int));
3437 sender = (char *)g_dbus_method_invocation_get_sender(context);
3438 result = _bt_tds_provider_transport_create(sender, transport, tds_handle);
3443 case BT_TDS_PROVIDER_DESTROY: {
3444 char *sender = NULL;
3445 unsigned int tds_handle = 0;
3447 __bt_service_get_parameters(in_param1,
3448 &tds_handle, sizeof(unsigned int));
3449 sender = (char *)g_dbus_method_invocation_get_sender(context);
3450 result = _bt_tds_provider_transport_remove(sender, tds_handle);
3455 case BT_TDS_PROVIDER_SET_TRANSPORT_DATA: {
3456 char *sender = NULL;
3457 unsigned int tds_handle = 0;
3458 int transport_state = 0;
3459 bluetooth_tds_data_t tds_data;
3461 __bt_service_get_parameters(in_param1,
3462 &tds_handle, sizeof(unsigned int));
3463 __bt_service_get_parameters(in_param2,
3464 &transport_state, sizeof(int));
3465 __bt_service_get_parameters(in_param3,
3466 &tds_data, sizeof(bluetooth_tds_data_t));
3467 sender = (char *)g_dbus_method_invocation_get_sender(context);
3469 result = _bt_tds_provider_set_transport_data(sender, tds_handle,
3470 transport_state, tds_data.data, tds_data.length);
3474 case BT_TDS_SEND_ACTIVATION_RESPONSE: {
3475 bluetooth_device_address_t address = { {0} };
3476 bluetooth_tds_data_t tds_data;
3477 char *sender = NULL;
3478 unsigned int tds_handle = 0;
3481 __bt_service_get_parameters(in_param1,
3482 &tds_handle, sizeof(unsigned int));
3483 __bt_service_get_parameters(in_param2,
3484 &response, sizeof(int));
3485 __bt_service_get_parameters(in_param3, &address,
3486 sizeof(bluetooth_device_address_t));
3487 __bt_service_get_parameters(in_param4,
3488 &tds_data, sizeof(bluetooth_tds_data_t));
3489 sender = (char *)g_dbus_method_invocation_get_sender(context);
3491 result = _bt_tds_provider_send_activation_response(sender, tds_handle,
3492 &address, response, tds_data.data, tds_data.length);
3497 sender = (char*)g_dbus_method_invocation_get_sender(context);
3498 BT_INFO("Mesh: Init by [%s]", sender);
3499 result = _bt_mesh_init(sender);
3500 /* Save invocation */
3501 if (result == BLUETOOTH_ERROR_NONE) {
3502 BT_INFO("Mesh: Save Invoation");
3503 sender = (char*)g_dbus_method_invocation_get_sender(context);
3504 _bt_save_invocation_context(context,
3506 function_name, NULL);
3510 case BT_MESH_DEINIT:
3511 sender = (char*)g_dbus_method_invocation_get_sender(context);
3512 BT_INFO("Mesh: De-Init by [%s]", sender);
3513 result = _bt_mesh_deinit(sender);
3516 case BT_MESH_NETWORK_CREATE: {
3517 bluetooth_mesh_node_t node;
3518 GSList *model_list = NULL;
3519 int total_models = 0;
3522 const char *network_name = NULL;
3523 bluetooth_mesh_network_t *network;
3525 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
3526 sender = (char*)g_dbus_method_invocation_get_sender(context);
3528 __bt_service_get_parameters(in_param1,
3529 &node, sizeof(bluetooth_mesh_node_t));
3530 network_name = (const char *)g_variant_get_data(in_param2);
3532 BT_INFO("MESH: Network name [%s]", network_name);
3534 param3 = g_array_new(TRUE, TRUE, sizeof(gchar));
3535 __bt_fill_garray_from_variant(in_param3, param3);
3537 total_models = (param3->len) / sizeof(bluetooth_mesh_model_t);
3538 for (i = 0; i < total_models; i++) {
3539 bluetooth_mesh_model_t *info = NULL;
3540 bluetooth_mesh_model_t *mod = NULL;
3542 info = &g_array_index(param3,
3543 bluetooth_mesh_model_t, i);
3545 mod = g_memdup(info, sizeof(bluetooth_mesh_model_t));
3548 model_list = g_slist_append(model_list,
3551 result = _bt_mesh_network_create(requester_unique_creds,
3552 sender, network_name, &node, model_list);
3554 /* Save invocation */
3555 if (result == BLUETOOTH_ERROR_NONE) {
3556 BT_INFO("Mesh: Save Invoation");
3557 network = g_malloc0(sizeof(bluetooth_mesh_network_t));
3559 /* Save Network name & UUID, Token will be received in event */
3560 _bt_mesh_util_convert_hex_to_string(
3561 (uint8_t *) node.uuid, 16,
3563 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
3564 BT_INFO("Mesh: Mesh Netwok UUID [%s]", network->uuid);
3565 g_strlcpy(network->name.name, network_name,
3566 sizeof(network->name.name));
3567 g_strlcpy(network->app_cred,
3568 requester_unique_creds,
3569 sizeof(network->app_cred));
3570 sender = (char*)g_dbus_method_invocation_get_sender(context);
3571 BT_INFO("Mesh: Network Create by [%s]", sender);
3572 _bt_save_invocation_context(context,
3574 function_name, (gpointer)network);
3576 g_array_append_vals(*out_param1, &node, sizeof(bluetooth_mesh_node_t));
3577 BT_ERR("Mesh: Mesh Network creation schedule failed");
3578 g_slist_free_full(model_list, g_free);
3582 BT_INFO("Mesh: Cleanup");
3583 g_free((gpointer)requester_unique_creds);
3584 g_array_free(param3, TRUE);
3585 BT_INFO("Mesh: Cleanup Done");
3588 case BT_MESH_NETWORK_DESTROY: {
3589 bluetooth_mesh_network_t network;
3590 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3592 __bt_service_get_parameters(in_param1,
3593 &network, sizeof(bluetooth_mesh_network_t));
3595 BT_INFO("Mesh: Destroy Network");
3596 result = _bt_mesh_network_destroy(requester_unique_creds,
3599 if (result != BLUETOOTH_ERROR_NONE) {
3600 g_array_append_vals(*out_param1,
3601 &network, sizeof(bluetooth_mesh_network_t));
3603 BT_INFO("Mesh: Destroy Network scheduled: add invocation");
3604 bluetooth_mesh_network_t *net = \
3605 g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3607 sender = (char*)g_dbus_method_invocation_get_sender(context);
3608 _bt_save_invocation_context(context, result, sender,
3609 function_name, (gpointer)net);
3613 case BT_MESH_NETWORK_LOAD: {
3615 bluetooth_mesh_network_t *network;
3616 token = (char *)g_variant_get_data(in_param1);
3617 BT_INFO("MESH: Network Load: Token string [%s]", token);
3618 result = _bt_mesh_network_load(requester_unique_creds, sender, token);
3619 /* Save invocation */
3620 if (result == BLUETOOTH_ERROR_NONE) {
3621 network = g_malloc0(sizeof(bluetooth_mesh_network_t));
3622 g_strlcpy(network->token.token, token,
3623 BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
3624 g_strlcpy(network->app_cred, requester_unique_creds,
3625 sizeof(network->app_cred));
3627 sender = (char*)g_dbus_method_invocation_get_sender(context);
3628 _bt_save_invocation_context(context, result, sender,
3629 function_name, (gpointer)network);
3631 g_free((gpointer)requester_unique_creds);
3634 case BT_MESH_NETWORK_UNLOAD: {
3635 bluetooth_mesh_network_t network;
3636 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3638 __bt_service_get_parameters(in_param1,
3639 &network, sizeof(bluetooth_mesh_network_t));
3641 BT_INFO("MESH: Network Unload: Network UUID [%s]", network.uuid);
3642 result = _bt_mesh_network_unload(requester_unique_creds,
3646 case BT_MESH_NETWORK_JOIN: {
3647 bluetooth_mesh_node_t node;
3648 GSList *model_list = NULL;
3649 int total_models = 0;
3653 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
3654 sender = (char*)g_dbus_method_invocation_get_sender(context);
3656 __bt_service_get_parameters(in_param1,
3657 &node, sizeof(bluetooth_mesh_node_t));
3659 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
3660 __bt_fill_garray_from_variant(in_param2, param2);
3662 total_models = (param2->len) / sizeof(bluetooth_mesh_model_t);
3663 for (i = 0; i < total_models; i++) {
3664 bluetooth_mesh_model_t *info = NULL;
3665 bluetooth_mesh_model_t *mod = NULL;
3666 info = &g_array_index(param2,
3667 bluetooth_mesh_model_t, i);
3668 mod = g_memdup(info, sizeof(bluetooth_mesh_model_t));
3671 model_list = g_slist_append(model_list,
3675 BT_INFO("MESH: Network Join bt-service");
3676 //result = BLUETOOTH_ERROR_NONE;
3677 result = _bt_mesh_network_join(requester_unique_creds,
3678 sender, &node, model_list);
3679 if (result != BLUETOOTH_ERROR_NONE) {
3680 g_array_append_vals(*out_param1, &node, sizeof(bluetooth_mesh_node_t));
3681 BT_ERR("Mesh: Mesh Join Network schedule failed");
3682 g_slist_free_full(model_list, g_free);
3685 BT_INFO("return of _bt_mesh_network_join : [%d]", result);
3688 case BT_MESH_CANCEL_JOIN: {
3689 bluetooth_mesh_node_info_t node;
3690 memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t));
3692 __bt_service_get_parameters(in_param1,
3693 &node, sizeof(bluetooth_mesh_node_info_t));
3695 BT_INFO("Mesh: Cancel Join request");
3696 result = _bt_mesh_cancel_join(requester_unique_creds,
3698 if (result != BLUETOOTH_ERROR_NONE) {
3699 g_array_append_vals(*out_param1,
3700 &node, sizeof(bluetooth_mesh_node_t));
3704 case BT_MESH_NETWORK_SCAN: {
3705 bluetooth_mesh_network_t network;
3706 bluetooth_mesh_scan_param_t param;
3707 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3708 memset(¶m, 0x00, sizeof(bluetooth_mesh_scan_param_t));
3710 __bt_service_get_parameters(in_param1,
3711 &network, sizeof(bluetooth_mesh_network_t));
3713 __bt_service_get_parameters(in_param2,
3714 ¶m, sizeof(bluetooth_mesh_scan_param_t));
3716 result = _bt_mesh_network_scan(requester_unique_creds,
3717 sender, &network, ¶m);
3719 if (result != BLUETOOTH_ERROR_NONE) {
3720 g_array_append_vals(*out_param1,
3721 &network, sizeof(bluetooth_mesh_network_t));
3723 bluetooth_mesh_network_t *net = \
3724 g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3726 sender = (char*)g_dbus_method_invocation_get_sender(context);
3727 _bt_save_invocation_context(context, result, sender,
3728 function_name, (gpointer)net);
3732 case BT_MESH_NETWORK_CANCEL_SCAN: {
3733 bluetooth_mesh_network_t network;
3734 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3736 __bt_service_get_parameters(in_param1,
3737 &network, sizeof(bluetooth_mesh_network_t));
3739 result = _bt_mesh_network_scan_cancel(requester_unique_creds,
3742 if (result != BLUETOOTH_ERROR_NONE)
3743 g_array_append_vals(*out_param1,
3744 &network, sizeof(bluetooth_mesh_network_t));
3747 case BT_MESH_NETWORK_SET_CAPABILITIES: {
3748 bluetooth_mesh_network_t network;
3749 bluetooth_mesh_provisioner_caps_t caps;
3750 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3751 memset(&caps, 0x00, sizeof(bluetooth_mesh_provisioner_caps_t));
3753 __bt_service_get_parameters(in_param1,
3754 &network, sizeof(bluetooth_mesh_network_t));
3756 __bt_service_get_parameters(in_param2,
3757 &caps, sizeof(bluetooth_mesh_provisioner_caps_t));
3759 result = _bt_mesh_network_set_provisioner_caps(
3760 requester_unique_creds, sender, &network, &caps);
3764 case BT_MESH_NETWORK_PROVISION_DEVICE: {
3765 bluetooth_mesh_provisioning_request_t req;
3766 memset(&req, 0x00, sizeof(bluetooth_mesh_provisioning_request_t));
3768 __bt_service_get_parameters(in_param1,
3769 &req, sizeof(bluetooth_mesh_provisioning_request_t));
3771 BT_INFO("Mesh: Provision Device UUID [%s]", req.dev_uuid);
3772 BT_INFO("Mesh: Provision Device in network[%s]", req.net_uuid);
3774 result = _bt_mesh_network_provision_device(
3775 requester_unique_creds, sender, &req);
3777 /* Save invocation */
3778 if (result != BLUETOOTH_ERROR_NONE) {
3779 g_array_append_vals(*out_param1, &req,
3780 sizeof(bluetooth_mesh_provisioning_request_t));
3782 bluetooth_mesh_provisioning_request_t *param = \
3783 g_memdup(&req, sizeof(bluetooth_mesh_provisioning_request_t));
3785 sender = (char*)g_dbus_method_invocation_get_sender(context);
3786 _bt_save_invocation_context(context, result, sender,
3787 function_name, (gpointer)param);
3791 case BT_MESH_AUTHENTICATION_REPLY: {
3792 BT_INFO("Mesh: BT_MESH_AUTHENTICATION_REPLY");
3793 const char *auth_value = NULL;
3794 gboolean authentication_reply = FALSE;
3796 auth_value = g_variant_get_data(in_param2);
3797 __bt_service_get_parameters(in_param3,
3798 &authentication_reply, sizeof(gboolean));
3799 __bt_service_get_parameters(in_param1,
3800 &auth_type, sizeof(int));
3801 BT_INFO("Mesh: Auth Reply Type [%d]", auth_type);
3802 BT_INFO("Mesh: Auth Value [%s]", auth_value);
3803 BT_INFO("Mesh: Auth Accept [%d]", authentication_reply);
3804 result = _bt_mesh_authentication_reply(auth_type,
3805 auth_value, authentication_reply);
3808 case BT_MESH_NETWORK_SET_NAME: {
3809 bluetooth_mesh_network_t network;
3810 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3812 __bt_service_get_parameters(in_param1,
3813 &network, sizeof(bluetooth_mesh_network_t));
3815 result = _bt_mesh_network_set_name(requester_unique_creds, sender, &network);
3819 case BT_MESH_NETWORK_ADD_NETKEY: {
3820 bluetooth_mesh_network_t network;
3821 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3823 __bt_service_get_parameters(in_param1,
3824 &network, sizeof(bluetooth_mesh_network_t));
3826 result = _bt_mesh_network_add_netkey(requester_unique_creds,
3829 if (result != BLUETOOTH_ERROR_NONE) {
3830 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3832 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3834 sender = (char*)g_dbus_method_invocation_get_sender(context);
3835 _bt_save_invocation_context(context, result, sender,
3836 function_name, (gpointer)net);
3840 case BT_MESH_NETWORK_DELETE_NETKEY: {
3841 bluetooth_mesh_network_t network;
3844 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3846 __bt_service_get_parameters(in_param1,
3847 &network, sizeof(bluetooth_mesh_network_t));
3848 __bt_service_get_parameters(in_param2,
3849 &index, sizeof(guint16));
3851 result = _bt_mesh_network_delete_netkey(requester_unique_creds,
3852 sender, &network, index);
3854 if (result != BLUETOOTH_ERROR_NONE) {
3855 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3857 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3859 sender = (char*)g_dbus_method_invocation_get_sender(context);
3860 _bt_save_invocation_context(context, result, sender,
3861 function_name, (gpointer)net);
3865 case BT_MESH_NETWORK_UPDATE_NETKEY: {
3866 bluetooth_mesh_network_t network;
3869 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3871 __bt_service_get_parameters(in_param1,
3872 &network, sizeof(bluetooth_mesh_network_t));
3873 __bt_service_get_parameters(in_param2,
3874 &index, sizeof(guint16));
3876 result = _bt_mesh_network_update_netkey(requester_unique_creds,
3877 sender, &network, index);
3879 if (result != BLUETOOTH_ERROR_NONE) {
3880 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3882 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3884 sender = (char*)g_dbus_method_invocation_get_sender(context);
3885 _bt_save_invocation_context(context, result, sender,
3886 function_name, (gpointer)net);
3890 case BT_MESH_NETWORK_ADD_APPKEY: {
3891 bluetooth_mesh_network_t network;
3894 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3896 __bt_service_get_parameters(in_param1,
3897 &network, sizeof(bluetooth_mesh_network_t));
3898 __bt_service_get_parameters(in_param2,
3899 &net_idx, sizeof(guint16));
3901 result = _bt_mesh_network_add_appkey(requester_unique_creds,
3902 sender, &network, net_idx);
3904 if (result != BLUETOOTH_ERROR_NONE) {
3905 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3907 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3909 sender = (char*)g_dbus_method_invocation_get_sender(context);
3910 _bt_save_invocation_context(context, result, sender,
3911 function_name, (gpointer)net);
3915 case BT_MESH_NETWORK_UPDATE_APPKEY: {
3916 bluetooth_mesh_network_t network;
3920 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3922 __bt_service_get_parameters(in_param1,
3923 &network, sizeof(bluetooth_mesh_network_t));
3924 __bt_service_get_parameters(in_param2,
3925 &net_idx, sizeof(guint16));
3926 __bt_service_get_parameters(in_param3,
3927 &app_idx, sizeof(guint16));
3929 result = _bt_mesh_network_update_appkey(requester_unique_creds,
3930 sender, &network, net_idx, app_idx);
3932 if (result != BLUETOOTH_ERROR_NONE) {
3933 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3935 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3937 sender = (char*)g_dbus_method_invocation_get_sender(context);
3938 _bt_save_invocation_context(context, result, sender,
3939 function_name, (gpointer)net);
3943 case BT_MESH_NETWORK_DELETE_APPKEY: {
3944 bluetooth_mesh_network_t network;
3948 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3950 __bt_service_get_parameters(in_param1,
3951 &network, sizeof(bluetooth_mesh_network_t));
3952 __bt_service_get_parameters(in_param2,
3953 &net_idx, sizeof(guint16));
3954 __bt_service_get_parameters(in_param3,
3955 &app_idx, sizeof(guint16));
3957 result = _bt_mesh_network_delete_appkey(requester_unique_creds,
3958 sender, &network, net_idx, app_idx);
3960 if (result != BLUETOOTH_ERROR_NONE) {
3961 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3963 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3965 sender = (char*)g_dbus_method_invocation_get_sender(context);
3966 _bt_save_invocation_context(context, result, sender,
3967 function_name, (gpointer)net);
3971 case BT_MESH_NETWORK_GET_NETKEYS: {
3972 bluetooth_mesh_network_t network;
3973 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3974 __bt_service_get_parameters(in_param1,
3975 &network, sizeof(bluetooth_mesh_network_t));
3976 result = _bt_mesh_network_get_netkeys(requester_unique_creds,
3977 sender, &network, out_param1);
3980 case BT_MESH_NETWORK_GET_APPKEYS: {
3981 bluetooth_mesh_network_t network;
3984 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3985 __bt_service_get_parameters(in_param1,
3986 &network, sizeof(bluetooth_mesh_network_t));
3987 __bt_service_get_parameters(in_param2,
3988 &net_idx, sizeof(guint16));
3989 result = _bt_mesh_network_get_appkeys(
3990 requester_unique_creds, sender,
3991 &network, net_idx, out_param1);
3994 case BT_MESH_NETWORK_GET_NODES: {
3995 bluetooth_mesh_network_t network;
3996 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3997 __bt_service_get_parameters(in_param1,
3998 &network, sizeof(bluetooth_mesh_network_t));
3999 result = _bt_mesh_network_get_nodes(
4000 requester_unique_creds, sender,
4001 &network, out_param1);
4004 case BT_MESH_ELEMENT_GET_MODELS: {
4005 bluetooth_mesh_network_t network;
4009 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4010 __bt_service_get_parameters(in_param1,
4011 &network, sizeof(bluetooth_mesh_network_t));
4012 __bt_service_get_parameters(in_param2,
4013 &node_addr, sizeof(guint16));
4014 __bt_service_get_parameters(in_param3,
4015 &elem_idx, sizeof(int));
4016 result = _bt_mesh_element_get_models(requester_unique_creds, sender,
4017 &network, node_addr, elem_idx, out_param1);
4020 case BT_MESH_NODE_BROWSE: {
4021 bluetooth_mesh_node_discover_t req;
4022 memset(&req, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4024 __bt_service_get_parameters(in_param1,
4025 &req, sizeof(bluetooth_mesh_node_discover_t));
4027 result = _bt_mesh_browse_remote_node(
4028 requester_unique_creds, sender, &req);
4030 /* Save invocation */
4031 if (result != BLUETOOTH_ERROR_NONE) {
4032 g_array_append_vals(*out_param1, &req,
4033 sizeof(bluetooth_mesh_node_discover_t));
4035 bluetooth_mesh_node_discover_t *param = \
4036 g_memdup(&req, sizeof(bluetooth_mesh_node_discover_t));
4038 sender = (char*)g_dbus_method_invocation_get_sender(context);
4039 _bt_save_invocation_context(context, result, sender,
4040 function_name, (gpointer)param);
4044 case BT_MESH_NODE_GET_VENDOR_FEATURES: {
4045 bluetooth_mesh_node_features_t req;
4046 memset(&req, 0x00, sizeof(bluetooth_mesh_node_features_t));
4048 __bt_service_get_parameters(in_param1,
4049 &req, sizeof(bluetooth_mesh_node_features_t));
4051 result = _bt_mesh_node_discover_vendor_features(
4052 requester_unique_creds, sender, &req);
4054 /* Save invocation */
4055 if (result != BLUETOOTH_ERROR_NONE) {
4056 g_array_append_vals(*out_param1,
4057 &req, sizeof(bluetooth_mesh_node_features_t));
4059 bluetooth_mesh_node_features_t *param = \
4060 g_memdup(&req, sizeof(bluetooth_mesh_node_features_t));
4062 sender = (char*)g_dbus_method_invocation_get_sender(context);
4063 _bt_save_invocation_context(context, result, sender,
4064 function_name, (gpointer)param);
4068 case BT_MESH_NODE_CONFIGURE_KEY: {
4069 bluetooth_mesh_key_configure_t req;
4071 memset(&req, 0x00, sizeof(bluetooth_mesh_key_configure_t));
4073 __bt_service_get_parameters(in_param1,
4074 &req, sizeof(bluetooth_mesh_key_configure_t));
4076 result = _bt_mesh_node_configure_key(
4077 requester_unique_creds, sender, &req);
4079 /* Save invocation */
4080 if (result != BLUETOOTH_ERROR_NONE) {
4081 g_array_append_vals(*out_param1,
4082 &req, sizeof(bluetooth_mesh_key_configure_t));
4084 bluetooth_mesh_key_configure_t *param = \
4085 g_memdup(&req, sizeof(bluetooth_mesh_key_configure_t));
4087 sender = (char*)g_dbus_method_invocation_get_sender(context);
4088 _bt_save_invocation_context(context, result, sender,
4089 function_name, (gpointer)param);
4093 case BT_MESH_NODE_TTL_EXECUTE: {
4094 bluetooth_mesh_node_ttl_info_t req;
4096 memset(&req, 0x00, sizeof(bluetooth_mesh_node_ttl_info_t));
4098 __bt_service_get_parameters(in_param1,
4099 &req, sizeof(bluetooth_mesh_node_ttl_info_t));
4101 result = _bt_mesh_ttl_execute_remote_node(
4102 requester_unique_creds, sender, &req);
4104 /* Save invocation */
4105 if (result != BLUETOOTH_ERROR_NONE) {
4106 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_node_ttl_info_t));
4108 bluetooth_mesh_node_ttl_info_t *param = \
4109 g_memdup(&req, sizeof(bluetooth_mesh_node_ttl_info_t));
4111 sender = (char*)g_dbus_method_invocation_get_sender(context);
4112 _bt_save_invocation_context(context, result, sender,
4113 function_name, (gpointer)param);
4117 case BT_MESH_MODEL_CONFIGURE_APPKEY: {
4118 bluetooth_mesh_model_configure_t req;
4120 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4122 __bt_service_get_parameters(in_param1,
4123 &req, sizeof(bluetooth_mesh_model_configure_t));
4125 result = _bt_mesh_node_model_appkey_execute(
4126 requester_unique_creds, sender, &req);
4128 /* Save invocation */
4129 if (result != BLUETOOTH_ERROR_NONE) {
4130 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4132 bluetooth_mesh_model_configure_t *param = \
4133 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4135 sender = (char*)g_dbus_method_invocation_get_sender(context);
4136 _bt_save_invocation_context(context, result, sender,
4137 function_name, (gpointer)param);
4141 case BT_MESH_MODEL_EXECUTE_MSG: {
4142 bluetooth_mesh_model_msg_t req;
4144 memset(&req, 0x00, sizeof(bluetooth_mesh_model_msg_t));
4146 __bt_service_get_parameters(in_param1,
4147 &req, sizeof(bluetooth_mesh_model_msg_t));
4149 result = _bt_mesh_model_execute_msg(
4150 requester_unique_creds, sender, &req);
4152 /* Save invocation */
4153 if (result != BLUETOOTH_ERROR_NONE) {
4154 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_msg_t));
4156 bluetooth_mesh_model_msg_t *param = \
4157 g_memdup(&req, sizeof(bluetooth_mesh_model_msg_t));
4159 sender = (char*)g_dbus_method_invocation_get_sender(context);
4160 _bt_save_invocation_context(context, result, sender,
4161 function_name, (gpointer)param);
4165 case BT_MESH_NODE_GET_NETKEYS: {
4166 bluetooth_mesh_node_discover_t node;
4167 memset(&node, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4168 __bt_service_get_parameters(in_param1,
4169 &node, sizeof(bluetooth_mesh_node_discover_t));
4170 result = _bt_mesh_network_node_get_netkeys(
4171 requester_unique_creds, &node, out_param1);
4174 case BT_MESH_NODE_GET_APPKEYS: {
4175 bluetooth_mesh_node_discover_t node;
4176 memset(&node, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4177 __bt_service_get_parameters(in_param1,
4178 &node, sizeof(bluetooth_mesh_node_discover_t));
4179 result = _bt_mesh_network_node_get_appkeys(
4180 requester_unique_creds, sender, &node, out_param1);
4183 case BT_MESH_NODE_RESET: {
4184 bluetooth_mesh_node_info_t node;
4185 memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t));
4187 __bt_service_get_parameters(in_param1,
4188 &node, sizeof(bluetooth_mesh_node_info_t));
4190 BT_INFO("Mesh: Reset the Node");
4191 result = _bt_mesh_network_reset_node(requester_unique_creds,
4196 case BT_MESH_MODEL_GET_APPKEY_LIST: {
4197 bluetooth_mesh_model_configure_t req;
4199 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4201 __bt_service_get_parameters(in_param1,
4202 &req, sizeof(bluetooth_mesh_model_configure_t));
4204 result = _bt_mesh_node_model_get_appkey_list(
4205 requester_unique_creds, sender, &req);
4207 /* Save invocation */
4208 if (result != BLUETOOTH_ERROR_NONE) {
4209 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4211 bluetooth_mesh_model_configure_t *param = \
4212 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4214 sender = (char*)g_dbus_method_invocation_get_sender(context);
4215 _bt_save_invocation_context(context, result, sender,
4216 function_name, (gpointer)param);
4220 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST: {
4221 bluetooth_mesh_model_configure_t req;
4223 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4225 __bt_service_get_parameters(in_param1,
4226 &req, sizeof(bluetooth_mesh_model_configure_t));
4228 result = _bt_mesh_node_model_get_subscription_list(
4229 requester_unique_creds, sender, &req);
4231 /* Save invocation */
4232 if (result != BLUETOOTH_ERROR_NONE) {
4233 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4235 bluetooth_mesh_model_configure_t *param = \
4236 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4238 sender = (char*)g_dbus_method_invocation_get_sender(context);
4239 _bt_save_invocation_context(context, result, sender,
4240 function_name, (gpointer)param);
4245 case BT_MESH_NETWORK_CREATE_GROUP: {
4246 bluetooth_mesh_network_t net;
4247 bluetooth_mesh_network_group_info_t res;
4248 gboolean is_virtual;
4251 memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
4252 memset(&res, 0x00, sizeof(bluetooth_mesh_network_group_info_t));
4254 __bt_service_get_parameters(in_param1,
4255 &net, sizeof(bluetooth_mesh_network_t));
4256 __bt_service_get_parameters(in_param2,
4257 &is_virtual, sizeof(gboolean));
4258 __bt_service_get_parameters(in_param3,
4259 &grp_addr, sizeof(guint16));
4261 result = _bt_mesh_network_create_group(
4262 requester_unique_creds, sender, &net,
4263 is_virtual, grp_addr, &res);
4265 if (result == BLUETOOTH_ERROR_NONE)
4266 g_array_append_vals(*out_param1, &res,
4267 sizeof(bluetooth_mesh_network_group_info_t));
4270 case BT_MESH_NETWORK_REMOVE_GROUP: {
4271 bluetooth_mesh_network_t net;
4272 bluetooth_mesh_network_group_info_t req;
4274 memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
4275 memset(&req, 0x00, sizeof(bluetooth_mesh_network_group_info_t));
4277 __bt_service_get_parameters(in_param1,
4278 &net, sizeof(bluetooth_mesh_network_t));
4279 __bt_service_get_parameters(in_param2,
4280 &req, sizeof(bluetooth_mesh_network_group_info_t));
4282 result = _bt_mesh_network_remove_group(
4283 requester_unique_creds, sender, &net, &req);
4287 case BT_MESH_MODEL_CONFIG_GROUP_SUB: {
4288 bluetooth_mesh_model_configure_t req;
4290 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4292 __bt_service_get_parameters(in_param1,
4293 &req, sizeof(bluetooth_mesh_model_configure_t));
4295 result = _bt_mesh_model_configure_group_subscription(
4296 requester_unique_creds, sender, &req);
4298 /* Save invocation */
4299 if (result != BLUETOOTH_ERROR_NONE) {
4300 g_array_append_vals(*out_param1,
4301 &req, sizeof(bluetooth_mesh_model_configure_t));
4303 bluetooth_mesh_model_configure_t *param = \
4304 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4306 sender = (char*)g_dbus_method_invocation_get_sender(context);
4307 _bt_save_invocation_context(context, result, sender,
4308 function_name, (gpointer)param);
4312 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB: {
4313 bluetooth_mesh_model_configure_t req;
4315 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4317 __bt_service_get_parameters(in_param1,
4318 &req, sizeof(bluetooth_mesh_model_configure_t));
4320 result = _bt_mesh_model_configure_virtual_group_subscription(
4321 requester_unique_creds, sender, &req);
4323 /* Save invocation */
4324 if (result != BLUETOOTH_ERROR_NONE) {
4325 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4327 bluetooth_mesh_model_configure_t *param = \
4328 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4330 sender = (char*)g_dbus_method_invocation_get_sender(context);
4331 _bt_save_invocation_context(context, result, sender,
4332 function_name, (gpointer)param);
4336 case BT_MESH_MODEL_SET_PUBLICATION: {
4337 bluetooth_mesh_model_configure_t req;
4339 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4341 __bt_service_get_parameters(in_param1,
4342 &req, sizeof(bluetooth_mesh_model_configure_t));
4344 result = _bt_mesh_model_set_publication(
4345 requester_unique_creds, sender, &req);
4347 /* Save invocation */
4348 if (result != BLUETOOTH_ERROR_NONE) {
4349 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4351 bluetooth_mesh_model_configure_t *param = g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4353 sender = (char*)g_dbus_method_invocation_get_sender(context);
4354 _bt_save_invocation_context(context, result, sender,
4355 function_name, (gpointer)param);
4359 case BT_MESH_MODEL_GET_PUBLICATION: {
4360 bluetooth_mesh_model_configure_t req;
4362 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4364 __bt_service_get_parameters(in_param1,
4365 &req, sizeof(bluetooth_mesh_model_configure_t));
4367 result = _bt_mesh_model_get_publication(
4368 requester_unique_creds, sender, &req);
4370 /* Save invocation */
4371 if (result != BLUETOOTH_ERROR_NONE) {
4372 g_array_append_vals(*out_param1,
4373 &req, sizeof(bluetooth_mesh_model_configure_t));
4375 bluetooth_mesh_model_configure_t *param = \
4376 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4378 sender = (char*)g_dbus_method_invocation_get_sender(context);
4379 _bt_save_invocation_context(context, result, sender,
4380 function_name, (gpointer)param);
4384 case BT_MESH_NETWORK_GET_GROUPS: {
4385 bluetooth_mesh_network_t network;
4386 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4387 __bt_service_get_parameters(in_param1,
4388 &network, sizeof(bluetooth_mesh_network_t));
4389 BT_INFO("Mesh: Request:: Get Groups");
4390 result = _bt_mesh_network_get_groups(
4391 requester_unique_creds, sender, &network, out_param1);
4395 BT_INFO("UnSupported function [%d]", function_name);
4396 result = BLUETOOTH_ERROR_NOT_SUPPORT;
4402 #ifdef TIZEN_FEATURE_BT_OBEX
4403 /* Function definitions*/
4404 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
4409 size = g_variant_get_size(var);
4411 data = (char *)g_variant_get_data(var);
4413 param = g_array_append_vals(param, data, size);
4419 int __bt_obexd_request(int function_name,
4422 GDBusMethodInvocation *context,
4423 GVariant *in_param1,
4424 GVariant *in_param2,
4425 GVariant *in_param3,
4426 GVariant *in_param4,
4427 GArray **out_param1)
4431 int result = BLUETOOTH_ERROR_NONE;
4433 BT_DBG("function_name : %x", function_name);
4435 switch (function_name) {
4436 case BT_OPP_PUSH_FILES: {
4437 BT_DBG("BT_OPP_PUSH_FILES");
4439 bluetooth_device_address_t address = { {0} };
4440 bt_file_path_t *path;
4445 __bt_service_get_parameters(in_param1, &address,
4446 sizeof(bluetooth_device_address_t));
4447 __bt_service_get_parameters(in_param3, &file_count,
4450 file_path = g_new0(char *, file_count + 1);
4452 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
4453 __bt_fill_garray_from_variant(in_param2, param2);
4455 for (i = 0; i < file_count; i++) {
4456 path = &g_array_index(param2, bt_file_path_t, i);
4457 file_path[i] = g_strdup(path->path);
4459 BT_DBG("_bt_opp_client_push_files");
4460 result = _bt_opp_client_push_files(request_id, context,
4461 &address, file_path,
4464 for (i = 0; i < file_count; i++)
4465 g_free(file_path[i]);
4468 g_array_free(param2, TRUE);
4472 case BT_OPP_CANCEL_PUSH: {
4473 result = _bt_opp_client_cancel_push();
4477 case BT_OPP_IS_PUSHING_FILES: {
4478 gboolean is_sending = FALSE;
4480 result = _bt_opp_client_is_sending(&is_sending);
4482 g_array_append_vals(*out_param1, &is_sending,
4486 case BT_OPP_GET_TRANSFER_PROGRESS: {
4489 guint8 progress = 0;
4491 __bt_service_get_parameters(in_param1, &direction,
4493 __bt_service_get_parameters(in_param2, &transfer_id,
4496 result = _bt_opp_get_client_progress(&progress);
4498 result = _bt_opp_get_server_progress(transfer_id, &progress);
4500 g_array_append_vals(*out_param1, &progress,
4506 case BT_MAP_CREATE_SESSION: {
4507 BT_DBG("BT_MAP_CREATE_SESSION");
4508 char *address = (char *)g_variant_get_data(in_param1);
4509 char *session_id = NULL;
4510 result = _bt_create_session_sync(address, &session_id);
4511 if (result == BLUETOOTH_ERROR_NONE)
4512 g_array_append_vals(*out_param1, session_id, strlen(session_id)+1);
4516 case BT_MAP_DESTROY_SESSION: {
4517 BT_DBG("BT_MAP_DESTROY_SESSION");
4518 char* session_id = (char *)g_variant_get_data(in_param1);
4519 result = _bt_destroy_session_sync(session_id);
4520 if (result == BLUETOOTH_ERROR_NONE)
4521 BT_DBG("successfully destroyed session");
4525 case BT_MAP_SET_FOLDER: {
4526 BT_DBG("BT_MAP_SET_FOLDER");
4527 char *session_id = (char *)g_variant_get_data(in_param1);
4528 char *name = (char *)g_variant_get_data(in_param2);
4529 result = _bt_map_client_set_folder(session_id, name);
4533 case BT_MAP_LIST_FOLDERS: {
4534 BT_DBG("BT_MAP_LIST_FOLDERS");
4536 char* session_id = (char *)g_variant_get_data(in_param1);
4537 char* filter_serialized = (char*)g_variant_get_data(in_param2);
4539 result = _bt_map_client_list_folders(request_id, context, session_id, filter_serialized);
4540 if (result == BLUETOOTH_ERROR_NONE)
4541 BT_DBG("_bt_map_client_list_folders succeed");
4546 case BT_MAP_LIST_FILTER_FIELDS: {
4547 BT_DBG("BT_MAP_LIST_FILTER_FIELDS");
4549 char* session_id = (char *)g_variant_get_data(in_param1);
4551 result = _bt_map_client_list_filter_fields(request_id, context, session_id);
4552 if (result == BLUETOOTH_ERROR_NONE)
4553 BT_DBG("_bt_map_client_list_filter_fields succeed");
4558 case BT_MAP_LIST_MESSAGES: {
4559 BT_DBG("BT_MAP_LIST_MESSAGES");
4561 char* session_id = (char*)g_variant_get_data(in_param1);
4562 char* folder = (char*)g_variant_get_data(in_param2);
4563 char* filter_serialized = (char*)g_variant_get_data(in_param3);
4565 result = _bt_map_client_list_messages(request_id, context, session_id, folder, filter_serialized);
4566 if (result == BLUETOOTH_ERROR_NONE)
4567 BT_DBG("_bt_map_client_list_messages succeed");
4569 BT_DBG("_bt_map_client_list_messages failed");
4574 case BT_MAP_UPDATE_INBOX: {
4575 BT_DBG("BT_MAP_UPDATE_INBOX");
4576 char* session_id = (char *)g_variant_get_data(in_param1);
4577 result = _bt_map_client_update_inbox(session_id);
4581 case BT_MAP_PUSH_MESSAGE: {
4582 BT_DBG("BT_MAP_PUSH_MESSAGE");
4584 char* session_id = (char *)g_variant_get_data(in_param1);
4585 char* source_file = (char *)g_variant_get_data(in_param2);
4586 char* folder = (char *)g_variant_get_data(in_param3);
4587 char* args_serialized = (char *)g_variant_get_data(in_param4);
4589 result = _bt_map_client_push_message(
4590 request_id, context, session_id, source_file, folder, args_serialized);
4591 if (result == BLUETOOTH_ERROR_NONE)
4592 BT_DBG("_bt_map_client_push_message succeed");
4594 BT_ERR("_bt_map_client_push_message failed");
4599 case BT_MAP_GET_MESSAGE: {
4600 BT_DBG("BT_MAP_GET_MESSAGE");
4601 // TODO session currently is not used, but should be valid
4602 //char* session_id = (char *)g_variant_get_data(in_param1);
4603 char* message_object = (char *)g_variant_get_data(in_param2);
4604 char* target_file = (char *)g_variant_get_data(in_param3);
4605 bool attachment = false;
4606 __bt_service_get_parameters(in_param4, &attachment, sizeof(bool));
4608 result = _bt_map_client_get_message(request_id, context, message_object,
4609 target_file, attachment);
4610 if (result == BLUETOOTH_ERROR_NONE)
4611 BT_DBG("_bt_map_client_get_message succeed");
4616 case BT_OBEX_SERVER_ALLOCATE: {
4622 sender = (char *)g_dbus_method_invocation_get_sender(context);
4624 path = (char *)g_variant_get_data(in_param1);
4625 __bt_service_get_parameters(in_param2, &is_native,
4627 __bt_service_get_parameters(in_param3, &app_pid,
4630 result = _bt_obex_server_allocate(sender,
4631 path, app_pid, is_native);
4635 case BT_OBEX_SERVER_DEALLOCATE: {
4639 __bt_service_get_parameters(in_param1, &is_native,
4641 __bt_service_get_parameters(in_param2, &app_pid,
4644 result = _bt_obex_server_deallocate(app_pid, is_native);
4647 case BT_OBEX_SERVER_IS_ACTIVATED: {
4648 gboolean is_activated = FALSE;
4650 result = _bt_obex_server_is_activated(&is_activated);
4652 g_array_append_vals(*out_param1, &is_activated,
4657 case BT_OBEX_SERVER_ACCEPT_CONNECTION: {
4658 result = _bt_obex_server_accept_connection(request_id);
4662 case BT_OBEX_SERVER_REJECT_CONNECTION: {
4663 result = _bt_obex_server_reject_connection();
4667 case BT_OBEX_SERVER_ACCEPT_FILE: {
4670 file_name = (char *)g_variant_get_data(in_param1);
4672 result = _bt_obex_server_accept_authorize(file_name, TRUE);
4676 case BT_OBEX_SERVER_REJECT_FILE: {
4677 result = _bt_obex_server_reject_authorize();
4681 case BT_OBEX_SERVER_SET_PATH: {
4683 char *destination_path;
4685 destination_path = (char *)g_variant_get_data(in_param1);
4686 __bt_service_get_parameters(in_param2, &is_native,
4689 result = _bt_obex_server_set_destination_path(destination_path,
4694 case BT_OBEX_SERVER_SET_ROOT: {
4697 root = (char *)g_variant_get_data(in_param1);
4699 result = _bt_obex_server_set_root(root);
4703 case BT_OBEX_SERVER_CANCEL_TRANSFER: {
4706 __bt_service_get_parameters(in_param1, &transfer_id,
4709 result = _bt_obex_server_cancel_transfer(transfer_id);
4713 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS: {
4714 result = _bt_obex_server_cancel_all_transfers();
4718 case BT_OBEX_SERVER_IS_RECEIVING: {
4719 gboolean is_receiving = FALSE;
4721 result = _bt_obex_server_is_receiving(&is_receiving);
4723 g_array_append_vals(*out_param1, &is_receiving,
4727 case BT_PBAP_CONNECT: {
4728 bluetooth_device_address_t address = { {0} };
4730 __bt_service_get_parameters(in_param1, &address,
4731 sizeof(bluetooth_device_address_t));
4733 result = _bt_pbap_connect(&address);
4736 case BT_PBAP_DISCONNECT: {
4737 bluetooth_device_address_t address = { {0} };
4739 __bt_service_get_parameters(in_param1, &address,
4740 sizeof(bluetooth_device_address_t));
4742 result = _bt_pbap_disconnect(&address);
4745 case BT_PBAP_GET_PHONEBOOK_SIZE: {
4746 bluetooth_device_address_t address = { {0} };
4747 bt_pbap_folder_t folder = { 0, };
4749 __bt_service_get_parameters(in_param1, &address,
4750 sizeof(bluetooth_device_address_t));
4751 __bt_service_get_parameters(in_param2, &folder,
4752 sizeof(bt_pbap_folder_t));
4754 result = _bt_pbap_get_phonebook_size(&address,
4755 folder.addressbook, folder.folder_type);
4758 case BT_PBAP_GET_PHONEBOOK: {
4759 bluetooth_device_address_t address = { {0} };
4760 bt_pbap_folder_t folder = { 0, };
4761 bt_pbap_pull_parameters_t app_param = { 0, };
4763 __bt_service_get_parameters(in_param1, &address,
4764 sizeof(bluetooth_device_address_t));
4765 __bt_service_get_parameters(in_param2, &folder,
4766 sizeof(bt_pbap_folder_t));
4767 __bt_service_get_parameters(in_param3, &app_param,
4768 sizeof(bt_pbap_pull_parameters_t));
4770 result = _bt_pbap_get_phonebook(&address, folder.addressbook,
4771 folder.folder_type, &app_param);
4774 case BT_PBAP_GET_LIST: {
4775 bluetooth_device_address_t address = { {0} };
4776 bt_pbap_folder_t folder = { 0, };
4777 bt_pbap_list_parameters_t app_param = { 0, };
4779 __bt_service_get_parameters(in_param1, &address,
4780 sizeof(bluetooth_device_address_t));
4781 __bt_service_get_parameters(in_param2, &folder,
4782 sizeof(bt_pbap_folder_t));
4783 __bt_service_get_parameters(in_param3, &app_param,
4784 sizeof(bt_pbap_list_parameters_t));
4786 result = _bt_pbap_get_list(&address, folder.addressbook,
4787 folder.folder_type, &app_param);
4790 case BT_PBAP_PULL_VCARD: {
4791 bluetooth_device_address_t address = { {0} };
4792 bt_pbap_folder_t folder = { 0, };
4793 bt_pbap_pull_vcard_parameters_t app_param = { 0, };
4795 __bt_service_get_parameters(in_param1, &address,
4796 sizeof(bluetooth_device_address_t));
4797 __bt_service_get_parameters(in_param2, &folder,
4798 sizeof(bt_pbap_folder_t));
4799 __bt_service_get_parameters(in_param3, &app_param,
4800 sizeof(bt_pbap_pull_vcard_parameters_t));
4802 result = _bt_pbap_pull_vcard(&address, folder.addressbook,
4803 folder.folder_type, &app_param);
4806 case BT_PBAP_PHONEBOOK_SEARCH: {
4807 bluetooth_device_address_t address = { {0} };
4808 bt_pbap_folder_t folder = { 0, };
4809 bt_pbap_search_parameters_t app_param = { 0, };
4811 __bt_service_get_parameters(in_param1, &address,
4812 sizeof(bluetooth_device_address_t));
4813 __bt_service_get_parameters(in_param2, &folder,
4814 sizeof(bt_pbap_folder_t));
4815 __bt_service_get_parameters(in_param3, &app_param,
4816 sizeof(bt_pbap_search_parameters_t));
4818 result = _bt_pbap_phonebook_search(&address, folder.addressbook,
4819 folder.folder_type, &app_param);
4824 BT_ERR("Unknown function!");
4825 result = BLUETOOTH_ERROR_INTERNAL;
4834 int __bt_agent_request(int function_name,
4837 GDBusMethodInvocation *context,
4838 GVariant *in_param1,
4839 GVariant *in_param2,
4840 GVariant *in_param3,
4841 GVariant *in_param4,
4842 GArray **out_param1)
4845 switch (function_name) {
4846 case BT_SET_AUTHORIZATION: {
4853 sender = (char *)g_dbus_method_invocation_get_sender(context);
4854 __bt_service_get_parameters(in_param1, &type, sizeof(int));
4855 uuid = (char *)g_variant_get_data(in_param2);
4856 path = (char *)g_variant_get_data(in_param3);
4857 __bt_service_get_parameters(in_param4, &fd, sizeof(int));
4859 result = _bt_register_osp_server_in_agent(sender, type, uuid, path, fd);
4862 case BT_UNSET_AUTHORIZATION: {
4866 __bt_service_get_parameters(in_param1, &type, sizeof(int));
4867 uuid = (char *)g_variant_get_data(in_param2);
4869 result = _bt_unregister_osp_server_in_agent(type, uuid);
4873 BT_ERR("Unknown function!");
4874 result = BLUETOOTH_ERROR_INTERNAL;
4881 int __bt_core_request(int function_name,
4884 GDBusMethodInvocation *context,
4885 GVariant *in_param1)
4889 switch (function_name) {
4890 case BT_ENABLE_ADAPTER:
4893 _bt_set_adapter_request_state(TRUE);
4894 status = _bt_adapter_get_status();
4896 if (status == BT_ACTIVATING) {
4897 BT_DBG("Enabling in progress");
4898 result = BLUETOOTH_ERROR_IN_PROGRESS;
4899 } else if (status == BT_ACTIVATED) {
4900 BT_DBG("Already enabled");
4901 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
4903 _bt_adapter_set_status(BT_ACTIVATING);
4904 result = BLUETOOTH_ERROR_NONE;
4909 case BT_DISABLE_ADAPTER:
4913 status = _bt_adapter_get_status();
4914 if (status == BT_DEACTIVATING) {
4915 BT_DBG("Disabling in progress");
4916 result = BLUETOOTH_ERROR_IN_PROGRESS;
4917 } else if (status == BT_DEACTIVATED) {
4918 BT_DBG("Already disabled");
4919 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
4921 _bt_adapter_set_status(BT_DEACTIVATING);
4922 result = BLUETOOTH_ERROR_NONE;
4927 case BT_ENABLE_ADAPTER_LE:
4929 bt_le_status_t le_status;
4930 _bt_set_le_request_state(TRUE);
4931 le_status = _bt_adapter_get_le_status();
4932 if (le_status == BT_LE_ACTIVATING) {
4933 BT_DBG("Enabling in progress");
4934 result = BLUETOOTH_ERROR_IN_PROGRESS;
4935 } else if (le_status == BT_LE_ACTIVATED) {
4936 BT_DBG("Already enabled");
4937 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
4939 _bt_adapter_set_le_status(BT_LE_ACTIVATING);
4940 result = BLUETOOTH_ERROR_NONE;
4945 case BT_DISABLE_ADAPTER_LE:
4947 bt_le_status_t le_status;
4949 le_status = _bt_adapter_get_le_status();
4950 if (le_status == BT_LE_DEACTIVATING) {
4951 BT_DBG("Disabling in progress");
4952 result = BLUETOOTH_ERROR_IN_PROGRESS;
4953 } else if (le_status == BT_LE_DEACTIVATED) {
4954 BT_DBG("Already disabled");
4955 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
4957 _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
4958 result = BLUETOOTH_ERROR_NONE;
4964 BT_ERR("Unknown function!");
4965 result = BLUETOOTH_ERROR_INTERNAL;
4972 static int __bt_service_get_requester_app_id(const char *unique_name, char *app_id, int len)
4977 retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
4978 retv_if(unique_name == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
4980 ret = __bt_service_get_sender_pid(unique_name, &pid);
4981 if (ret != BLUETOOTH_ERROR_NONE) {
4982 BT_ERR("Fail to get the sender pid");
4986 ret = aul_app_get_appid_bypid(pid, app_id, len);
4987 if (ret != AUL_R_OK) {
4988 BT_ERR("app_id not found");
4989 return BLUETOOTH_ERROR_NOT_SUPPORT;
4991 BT_DBG("Sender app_id: %s", app_id);
4993 return BLUETOOTH_ERROR_NONE;
4996 gboolean __bt_service_check_privilege(int function_name,
4998 const char *unique_name)
5001 gboolean result = TRUE;
5002 char *client_creds = NULL;
5003 char *user_creds = NULL;
5004 char *client_session = "";
5005 enum cynara_client_creds client_creds_method = CLIENT_METHOD_SMACK;
5006 enum cynara_user_creds user_creds_method = USER_METHOD_UID;
5007 char err_msg[256] = {0, };
5009 retv_if(unique_name == NULL, FALSE);
5010 retv_if(bt_service_conn == NULL, FALSE);
5012 ret_val = cynara_creds_get_default_client_method(&client_creds_method);
5013 if (ret_val != CYNARA_API_SUCCESS) {
5014 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5015 BT_ERR("Fail to get default client method: %s", err_msg);
5019 ret_val = cynara_creds_get_default_user_method(&user_creds_method);
5020 if (ret_val != CYNARA_API_SUCCESS) {
5021 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5022 BT_ERR("Fail to get default user method: %s", err_msg);
5026 ret_val = cynara_creds_gdbus_get_client(bt_service_conn, unique_name, client_creds_method, &client_creds);
5027 if (ret_val != CYNARA_API_SUCCESS) {
5028 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5029 BT_ERR("Fail to get client credential: %s", err_msg);
5033 ret_val = cynara_creds_gdbus_get_user(bt_service_conn, unique_name, user_creds_method, &user_creds);
5034 if (ret_val != CYNARA_API_SUCCESS) {
5035 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5036 BT_ERR("Fail to get user credential: %s", err_msg);
5042 BT_DBG("%s, %s, %s", unique_name, client_creds, user_creds);
5044 switch (function_name) {
5045 case BT_SET_LOCAL_NAME:
5046 case BT_START_DISCOVERY:
5047 case BT_START_CUSTOM_DISCOVERY:
5048 case BT_CANCEL_DISCOVERY:
5049 case BT_OOB_ADD_REMOTE_DATA:
5050 case BT_OOB_REMOVE_REMOTE_DATA:
5051 case BT_OOB_READ_LOCAL_DATA:
5052 case BT_SET_ADVERTISING:
5053 case BT_SET_CUSTOM_ADVERTISING:
5054 case BT_SET_ADVERTISING_PARAMETERS:
5055 case BT_START_LE_DISCOVERY:
5056 case BT_STOP_LE_DISCOVERY:
5057 case BT_SET_SCAN_PARAMETERS:
5058 case BT_SET_SCAN_TYPE:
5059 case BT_UPDATE_LE_CONNECTION_MODE:
5061 case BT_BOND_DEVICE:
5062 case BT_CANCEL_BONDING:
5063 case BT_UNBOND_DEVICE:
5065 case BT_SET_AUTHORIZATION:
5066 case BT_UNSET_AUTHORIZATION:
5067 case BT_SEARCH_SERVICE:
5069 case BT_RFCOMM_CLIENT_CONNECT:
5070 if (function_name == BT_RFCOMM_CLIENT_CONNECT)
5071 BT_PERMANENT_LOG("Connect socket");
5072 case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
5073 case BT_RFCOMM_SOCKET_DISCONNECT:
5074 if (function_name == BT_RFCOMM_SOCKET_DISCONNECT)
5075 BT_PERMANENT_LOG("Disconnect socket");
5076 case BT_RFCOMM_SOCKET_WRITE:
5077 case BT_RFCOMM_CREATE_SOCKET:
5078 case BT_RFCOMM_REMOVE_SOCKET:
5079 case BT_RFCOMM_SEND_RX_DETAILS:
5080 case BT_RFCOMM_SEND_TX_DETAILS:
5081 case BT_RFCOMM_UPDATE_CONNECTION_INFO:
5083 case BT_OPP_PUSH_FILES:
5084 case BT_OPP_CANCEL_PUSH:
5085 /* TODO: MAP? MAP functions, see above */
5087 case BT_OBEX_SERVER_ACCEPT_CONNECTION:
5088 case BT_OBEX_SERVER_REJECT_CONNECTION:
5089 case BT_OBEX_SERVER_ACCEPT_FILE:
5090 case BT_OBEX_SERVER_REJECT_FILE:
5091 case BT_OBEX_SERVER_SET_PATH:
5092 case BT_OBEX_SERVER_SET_ROOT:
5093 case BT_OBEX_SERVER_CANCEL_TRANSFER:
5094 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS:
5096 case BT_AUDIO_SELECT_ROLE:
5097 case BT_AUDIO_CONNECT:
5098 case BT_AUDIO_DISCONNECT:
5100 case BT_AG_DISCONNECT:
5102 case BT_AV_DISCONNECT:
5103 case BT_AV_SOURCE_CONNECT:
5104 case BT_AV_SOURCE_DISCONNECT:
5105 case BT_AVRCP_TARGET_CONNECT:
5106 case BT_AVRCP_TARGET_DISCONNECT:
5107 case BT_AVRCP_CONTROL_CONNECT:
5108 case BT_AVRCP_CONTROL_DISCONNECT:
5109 case BT_AVRCP_HANDLE_CONTROL:
5110 case BT_AVRCP_SET_TRACK_INFO:
5111 case BT_AVRCP_SET_PROPERTY:
5112 case BT_AVRCP_SET_PROPERTIES:
5113 case BT_AVRCP_CONTROL_SET_PROPERTY:
5115 case BT_AUDIO_SET_ABSOLUTE_VOLUME:
5116 case BT_AUDIO_GET_ABSOLUTE_VOLUME:
5117 case BT_AUDIO_IS_AVC_ACTIVATED:
5120 case BT_HF_DISCONNECT:
5122 case BT_HID_CONNECT:
5123 case BT_HID_DISCONNECT:
5125 case BT_HID_DEVICE_ACTIVATE:
5126 case BT_HID_DEVICE_DEACTIVATE:
5127 case BT_HID_DEVICE_CONNECT:
5128 case BT_HID_DEVICE_DISCONNECT:
5129 case BT_HID_DEVICE_SEND_MOUSE_EVENT:
5130 case BT_HID_DEVICE_SEND_KEY_EVENT:
5131 case BT_HID_DEVICE_SEND_REPLY_TO_REPORT:
5132 case BT_HID_DEVICE_SEND_CUSTOM_EVENT:
5135 case BT_DISCONNECT_LE:
5137 case BT_SET_ADVERTISING_DATA:
5138 case BT_SET_SCAN_RESPONSE_DATA:
5140 case BT_HDP_CONNECT:
5141 case BT_HDP_DISCONNECT:
5142 case BT_HDP_SEND_DATA:
5143 case BT_HDP_REGISTER_SINK_APP:
5144 case BT_HDP_UNREGISTER_SINK_APP:
5147 case BT_DPM_SET_ALLOW_BT_MODE:
5148 case BT_DPM_GET_ALLOW_BT_MODE:
5149 case BT_DPM_SET_DEVICE_RESTRITION:
5150 case BT_DPM_GET_DEVICE_RESTRITION:
5151 case BT_DPM_SET_UUID_RESTRITION:
5152 case BT_DPM_GET_UUID_RESTRITION:
5153 case BT_DPM_ADD_DEVICES_BLACKLIST:
5154 case BT_DPM_ADD_DEVICES_WHITELIST:
5155 case BT_DPM_ADD_UUIDS_BLACKLIST:
5156 case BT_DPM_ADD_UUIDS_WHITELIST:
5157 case BT_DPM_CLEAR_DEVICES_BLACKLIST:
5158 case BT_DPM_CLEAR_DEVICES_WHITELIST:
5159 case BT_DPM_CLEAR_UUIDS_BLACKLIST:
5160 case BT_DPM_CLEAR_UUIDS_WHITELIST:
5161 case BT_DPM_REMOVE_DEVICE_BLACKLIST:
5162 case BT_DPM_REMOVE_DEVICE_WHITELIST:
5163 case BT_DPM_REMOVE_UUID_BLACKLIST:
5164 case BT_DPM_REMOVE_UUID_WHITELIST:
5165 case BT_DPM_GET_DEVICES_BLACKLIST:
5166 case BT_DPM_GET_DEVICES_WHITELIST:
5167 case BT_DPM_GET_UUIDS_BLACKLIST:
5168 case BT_DPM_GET_UUIDS_WHITELIST:
5169 case BT_DPM_SET_ALLOW_OUTGOING_CALL:
5170 case BT_DPM_GET_ALLOW_OUTGOING_CALL:
5171 case BT_DPM_SET_PAIRING_STATE:
5172 case BT_DPM_GET_PAIRING_STATE:
5173 case BT_DPM_SET_PROFILE_STATE:
5174 case BT_DPM_GET_PROFILE_STATE:
5175 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE:
5176 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE:
5177 case BT_DPM_SET_DISCOVERABLE_STATE:
5178 case BT_DPM_GET_DISCOVERABLE_STATE:
5179 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE:
5180 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE:
5181 case BT_DPM_SET_DATA_TRANSFER_STATE:
5182 case BT_DPM_GET_DATA_TRANSFER_STATE:
5184 case BT_NETWORK_ACTIVATE:
5185 case BT_NETWORK_DEACTIVATE:
5186 case BT_NETWORK_CONNECT:
5187 case BT_NETWORK_DISCONNECT:
5188 case BT_NETWORK_SERVER_DISCONNECT:
5190 case BT_GATT_GET_PRIMARY_SERVICES:
5191 case BT_GATT_GET_SERVICE_PROPERTIES: /* GATT Client */
5192 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: /* GATT Client */
5193 case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: /* GATT Client */
5194 case BT_GATT_DISCOVER_CHARACTERISTICS:
5195 case BT_GATT_SET_PROPERTY_REQUEST:
5196 case BT_GATT_READ_CHARACTERISTIC:
5197 case BT_GATT_READ_DESCRIPTOR_VALUE: /* GATT Client */
5198 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: /* GATT Client */
5199 case BT_GATT_ACQUIRE_WRITE:
5200 case BT_GATT_WRITE_DESCRIPTOR_VALUE: /* GATT Client */
5201 case BT_GATT_WATCH_CHARACTERISTIC: /* GATT Client */
5202 case BT_GATT_CLIENT_REGISTER: /* GATT Client */
5203 case BT_GATT_CLIENT_UNREGISTER: /* GATT Client */
5204 case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
5205 case BT_GATT_REGISTER_APPLICATION:
5206 case BT_GATT_REGISTER_SERVICE:
5207 case BT_GATT_SEND_RESPONSE:
5209 case BT_GATT_SERVER_REGISTER:
5210 case BT_GATT_SERVER_ADD_SERVICE:
5211 case BT_GATT_SERVER_ADD_CHARACTERISTIC:
5212 case BT_GATT_SERVER_ADD_DESCRIPTOR:
5213 case BT_GATT_SERVER_START_SERVICE:
5214 case BT_GATT_SERVER_STOP_SERVICE:
5215 case BT_GATT_SERVER_DELETE_SERVICE:
5216 case BT_GATT_SERVER_SEND_RESPONSE:
5217 case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE:
5218 case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE:
5219 case BT_GATT_SERVER_SEND_INDICATION:
5220 case BT_GATT_SERVER_UPDATE_VALUE:
5221 case BT_GATT_SERVER_DEREGISTER:
5223 case BT_REQ_ATT_MTU:
5224 case BT_PBAP_CONNECT:
5225 case BT_PBAP_DISCONNECT:
5226 case BT_PBAP_GET_PHONEBOOK_SIZE:
5227 case BT_PBAP_GET_PHONEBOOK:
5228 case BT_PBAP_GET_LIST:
5229 case BT_PBAP_PULL_VCARD:
5230 case BT_PBAP_PHONEBOOK_SEARCH:
5232 case BT_RFCOMM_LISTEN_AND_ACCEPT:
5234 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5235 BT_PRIVILEGE_PUBLIC);
5237 BT_INFO("Client Credentials [%s]", client_creds);
5238 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5239 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PUBLIC);
5243 /* Need to check mediastorage privilege */
5244 if (function_name == BT_PBAP_GET_PHONEBOOK ||
5245 function_name == BT_PBAP_PULL_VCARD) {
5246 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5247 MEDIASTORAGE_PRIVILEGE);
5249 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5250 BT_ERR("Fail to access: %s", MEDIASTORAGE_PRIVILEGE);
5256 case BT_ENABLE_ADAPTER:
5257 case BT_DISABLE_ADAPTER:
5258 case BT_RESET_ADAPTER:
5259 case BT_RECOVER_ADAPTER:
5260 case BT_BATTERY_READ_DATA:
5261 case BT_ENABLE_ADAPTER_LE:
5262 case BT_DISABLE_ADAPTER_LE:
5263 case BT_SET_CONNECTABLE:
5264 case BT_SET_DISCOVERABLE_MODE:
5265 case BT_ADD_WHITE_LIST:
5266 case BT_REMOVE_WHITE_LIST:
5267 case BT_CLEAR_WHITE_LIST:
5268 case BT_SET_MANUFACTURER_DATA:
5270 case BT_CANCEL_SEARCH_SERVICE:
5271 case BT_ENABLE_RSSI:
5272 case BT_DISCONNECT_DEVICE:
5274 case BT_RFCOMM_ACCEPT_CONNECTION:
5275 case BT_RFCOMM_REJECT_CONNECTION:
5276 case BT_RFCOMM_LISTEN:
5278 case BT_HID_ENABLE_BARCODE_FEATURE:
5280 case BT_AVRCP_TRANSPORT_SET_PROPERTY:
5281 case BT_AVRCP_HANDLE_CONTROL_TO_DEST:
5283 case BT_SET_CONTENT_PROTECT:
5284 case BT_BOND_DEVICE_BY_TYPE:
5285 case BT_SET_LE_PRIVACY:
5286 case BT_SET_LE_STATIC_RANDOM_ADDRESS:
5287 case BT_LE_CONN_UPDATE:
5288 case BT_GET_DEVICE_IDA:
5289 case BT_LE_READ_MAXIMUM_DATA_LENGTH:
5290 case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH:
5291 case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH:
5292 case BT_LE_SET_DATA_LENGTH:
5293 case BT_LE_OOB_READ_LOCAL_DATA:
5294 case BT_LE_OOB_ADD_REMOTE_DATA:
5296 case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS:
5297 case BT_ENABLE_GATT_DATA_BATCHING:
5298 case BT_DISABLE_GATT_DATA_BATCHING:
5300 case BT_LE_IPSP_INIT:
5301 case BT_LE_IPSP_DEINIT:
5302 case BT_LE_IPSP_CONNECT:
5303 case BT_LE_IPSP_DISCONNECT:
5304 case BT_PXP_MONITOR_SET_PROPERTY:
5305 case BT_PXP_MONITOR_GET_PROPERTY:
5306 case BT_PXP_MONITOR_GET_SUPPORTED_SERIVCES:
5307 case BT_PXP_REPORTER_REGISTER:
5308 case BT_PXP_REPORTER_UNREGISTER:
5309 case BT_PXP_REPORTER_GET_PROPERTY:
5312 case BT_TDS_PROVIDER_REGISTER:
5313 case BT_TDS_PROVIDER_UNREGISTER:
5314 case BT_TDS_PROVIDER_SET_MANUF_DATA:
5315 case BT_TDS_PROVIDER_CREATE:
5316 case BT_TDS_PROVIDER_DESTROY:
5317 case BT_TDS_PROVIDER_SET_TRANSPORT_DATA:
5318 case BT_TDS_SEND_ACTIVATION_RESPONSE:
5319 case BT_TDS_READ_TRANSPORT_DATA:
5320 case BT_TDS_ENABLE_CONTROL_POINT:
5321 case BT_TDS_ACTIVATE_CONTROL_POINT:
5324 case BT_OTP_SERVER_INIT:
5325 case BT_OTP_SERVER_DEINIT:
5326 case BT_OTP_READ_VALUE:
5327 case BT_OTP_ENABLE_NOTIFICATION:
5328 case BT_OTP_WRITE_VALUE:
5329 case BT_LE_OTC_CONNECT:
5330 case BT_LE_OTC_DISCONNECT:
5332 case BT_MAP_CREATE_SESSION:
5333 case BT_MAP_DESTROY_SESSION:
5334 case BT_MAP_SET_FOLDER:
5335 case BT_MAP_LIST_FOLDERS:
5336 case BT_MAP_LIST_FILTER_FIELDS:
5337 case BT_MAP_LIST_MESSAGES:
5338 case BT_MAP_UPDATE_INBOX:
5339 case BT_MAP_PUSH_MESSAGE:
5340 case BT_MAP_GET_MESSAGE:
5343 case BT_MESH_DEINIT:
5344 case BT_MESH_NETWORK_CREATE:
5345 case BT_MESH_NETWORK_DESTROY:
5346 case BT_MESH_NETWORK_LOAD:
5347 case BT_MESH_NETWORK_UNLOAD:
5348 case BT_MESH_NETWORK_JOIN:
5349 case BT_MESH_CANCEL_JOIN:
5350 case BT_MESH_NETWORK_SCAN:
5351 case BT_MESH_NETWORK_CANCEL_SCAN:
5352 case BT_MESH_NETWORK_SET_CAPABILITIES:
5353 case BT_MESH_NETWORK_PROVISION_DEVICE:
5354 case BT_MESH_AUTHENTICATION_REPLY:
5355 case BT_MESH_NETWORK_SET_NAME:
5356 case BT_MESH_NETWORK_ADD_NETKEY:
5357 case BT_MESH_NETWORK_DELETE_NETKEY:
5358 case BT_MESH_NETWORK_UPDATE_NETKEY:
5359 case BT_MESH_NETWORK_ADD_APPKEY:
5360 case BT_MESH_NETWORK_DELETE_APPKEY:
5361 case BT_MESH_NETWORK_UPDATE_APPKEY:
5362 case BT_MESH_NETWORK_GET_NETKEYS:
5363 case BT_MESH_NETWORK_GET_APPKEYS:
5364 case BT_MESH_NETWORK_GET_NODES:
5365 case BT_MESH_ELEMENT_GET_MODELS:
5366 case BT_MESH_NODE_BROWSE:
5367 case BT_MESH_NODE_GET_VENDOR_FEATURES:
5368 case BT_MESH_NODE_CONFIGURE_KEY:
5369 case BT_MESH_NODE_TTL_EXECUTE:
5370 case BT_MESH_NODE_GET_NETKEYS:
5371 case BT_MESH_NODE_GET_APPKEYS:
5372 case BT_MESH_NODE_RESET:
5373 case BT_MESH_MODEL_CONFIGURE_APPKEY:
5374 case BT_MESH_MODEL_GET_APPKEY_LIST:
5375 case BT_MESH_MODEL_EXECUTE_MSG:
5376 case BT_MESH_NETWORK_CREATE_GROUP:
5377 case BT_MESH_NETWORK_REMOVE_GROUP:
5378 case BT_MESH_MODEL_CONFIG_GROUP_SUB:
5379 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB:
5380 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST:
5381 case BT_MESH_MODEL_SET_PUBLICATION:
5382 case BT_MESH_MODEL_GET_PUBLICATION:
5383 case BT_MESH_NETWORK_GET_GROUPS:
5385 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5386 BT_PRIVILEGE_PLATFORM);
5388 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5389 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PLATFORM);
5394 case BT_CHECK_ADAPTER:
5397 case BT_GET_LOCAL_NAME:
5398 case BT_GET_LOCAL_ADDRESS:
5399 case BT_GET_LOCAL_VERSION:
5400 case BT_IS_SERVICE_USED:
5401 case BT_GET_DISCOVERABLE_MODE:
5402 case BT_GET_DISCOVERABLE_TIME:
5403 case BT_IS_DISCOVERYING:
5404 case BT_IS_LE_DISCOVERYING:
5405 case BT_IS_CONNECTABLE:
5406 case BT_GET_CONNECTABLE:
5407 case BT_GET_BONDED_DEVICES:
5408 case BT_GET_PROFILE_CONNECTED_DEVICES:
5409 case BT_GET_BONDED_DEVICE:
5410 case BT_PASSKEY_REPLY:
5411 case BT_PASSKEY_CONFIRMATION_REPLY:
5412 case BT_GET_IS_ALIAS_SET:
5413 case BT_IS_DEVICE_CONNECTED:
5414 case BT_GET_CONNECTED_LINK_TYPE:
5415 case BT_SET_PROFILE_TRUSTED:
5416 case BT_GET_PROFILE_TRUSTED:
5417 case BT_GET_SPEAKER_GAIN:
5418 case BT_SET_SPEAKER_GAIN:
5419 case BT_RFCOMM_CLIENT_IS_CONNECTED:
5420 case BT_RFCOMM_IS_UUID_AVAILABLE:
5421 case BT_GET_ADVERTISING_DATA:
5422 case BT_GET_SCAN_RESPONSE_DATA:
5423 case BT_IS_ADVERTISING:
5424 case BT_IS_LE_2M_PHY_SUPPORTED:
5425 case BT_IS_LE_CODED_PHY_SUPPORTED:
5426 case BT_REGISTER_SCAN_FILTER:
5427 case BT_IS_SCAN_FILTER_SUPPORTED:
5428 case BT_GET_ATT_MTU:
5430 case BT_OBEX_SERVER_ALLOCATE:
5431 case BT_OBEX_SERVER_DEALLOCATE:
5432 case BT_OBEX_SERVER_IS_ACTIVATED:
5433 case BT_OPP_GET_TRANSFER_PROGRESS:
5434 case BT_AVRCP_CONTROL_GET_PROPERTY:
5435 case BT_AVRCP_GET_TRACK_INFO:
5436 /* Non-privilege control */
5439 BT_ERR("Unknown function!");
5444 if (function_name >= BT_FUNC_MESH_BASE) {
5445 BT_INFO("MESH Function called");
5446 char app_id[256] = { 0, };
5448 if (BLUETOOTH_ERROR_NONE == __bt_service_get_requester_app_id(unique_name,
5449 app_id, sizeof(app_id))) {
5450 requester_unique_creds = g_strdup(app_id);
5452 BT_DBG("Requester app_id not found, use client creds");
5453 requester_unique_creds = g_strdup(client_creds);
5455 BT_DBG("Requester unique_creds: %s", requester_unique_creds);
5457 BT_INFO("Non MESH Function called client creds [%s]", client_creds);
5469 GDBusNodeInfo *__bt_service_create_method_node_info
5470 (const gchar *introspection_data)
5473 GDBusNodeInfo *node_info = NULL;
5475 if (introspection_data == NULL) {
5476 BT_ERR("Introspection XML not present");
5480 node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
5483 BT_ERR("Unable to create node: %s", err->message);
5484 g_clear_error(&err);
5489 int __bt_service_register_object(GDBusConnection *conn,
5490 GDBusNodeInfo *node_info, gboolean reg)
5492 static guint service_id = 0;
5493 GError *error = NULL;
5496 if (node_info == NULL)
5499 service_id = g_dbus_connection_register_object(conn,
5501 node_info->interfaces[0],
5503 NULL, NULL, &error);
5504 if (service_id == 0)
5507 if (service_id > 0) {
5508 g_dbus_connection_unregister_object(conn,
5517 static void __name_owner_changed(GDBusConnection *connection,
5518 const gchar *sender_name,
5519 const gchar *object_path,
5520 const gchar *interface_name,
5521 const gchar *signal_name,
5522 GVariant *parameters,
5525 const char *name = NULL;
5526 const char *old_owner = NULL;
5527 const char *new_owner = NULL;
5529 g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
5530 if (*new_owner != '\0')
5533 _bt_check_hdp_app_termination(name);
5535 /* Advertising App Termination */
5536 _bt_check_adv_app_termination(name);
5538 /* Check if le_scanning app is terminated */
5539 _bt_check_le_scanner_app_termination(name);
5541 /* Check if RFCOMM app is terminated */
5542 _bt_rfcomm_check_termination(name);
5544 /* Mesh App Termination */
5545 _bt_check_mesh_app_termination(name);
5547 /* Stop the Transport Discovery service */
5548 _bt_tds_stop_by_terminated_process(name);
5551 static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
5552 const gchar *name, gpointer user_data)
5554 GDBusNodeInfo *node_info = NULL;
5556 BT_INFO("bus acquired");
5558 ret_if(connection == NULL);
5560 node_info = __bt_service_create_method_node_info(
5561 bt_service_introspection_xml);
5562 ret_if(node_info == NULL);
5564 __bt_service_register_object(connection, node_info, TRUE);
5565 g_dbus_node_info_unref(node_info);
5567 bt_service_conn = connection;
5570 static void __bt_service_name_acquired_handler(GDBusConnection *connection,
5571 const gchar *name, gpointer user_data)
5573 BT_INFO("name acquired");
5574 name_acquired = TRUE;
5577 static void __bt_service_name_lost_handler(GDBusConnection *connection,
5578 const gchar *name, gpointer user_data)
5580 BT_INFO("name lost");
5581 name_acquired = FALSE;
5584 gboolean _is_name_acquired(void)
5586 return name_acquired;
5589 void _bt_service_unref_connection(void)
5593 if (bt_service_conn) {
5594 g_dbus_connection_flush_sync(bt_service_conn, NULL, NULL);
5595 g_object_unref(bt_service_conn);
5596 bt_service_conn = NULL;
5602 int _bt_service_register(void)
5604 GDBusConnection *conn;
5607 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
5608 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
5609 bt_service_conn = conn;
5611 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
5613 G_BUS_NAME_OWNER_FLAGS_NONE,
5614 __bt_service_bus_acquired_handler,
5615 __bt_service_name_acquired_handler,
5616 __bt_service_name_lost_handler,
5618 BT_DBG("owner_id is [%d]", owner_id);
5622 /* Subscribe for name owner changed signal */
5623 owner_sig_id = g_dbus_connection_signal_subscribe(conn,
5624 BT_FREEDESKTOP_SERVICE, BT_FREEDESKTOP_INTERFACE,
5625 BT_NAME_OWNER_CHANGED, NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
5626 __name_owner_changed, NULL, NULL);
5627 BT_INFO("owner_sig_id: %d", owner_sig_id);
5629 return BLUETOOTH_ERROR_NONE;
5632 if (bt_service_conn) {
5633 g_object_unref(bt_service_conn);
5634 bt_service_conn = NULL;
5637 return BLUETOOTH_ERROR_INTERNAL;
5640 void _bt_service_unregister(void)
5642 if (bt_service_conn) {
5643 sd_notify(0, "STOPPING=1");
5645 if (owner_sig_id > 0) {
5646 g_dbus_connection_signal_unsubscribe(
5647 bt_service_conn, owner_sig_id);
5652 g_bus_unown_name(owner_id);
5656 __bt_service_register_object(bt_service_conn, NULL, FALSE);
5660 int _bt_service_cynara_init(void)
5663 char err_msg[256] = {0, };
5665 retv_if(p_cynara != NULL, BLUETOOTH_ERROR_ALREADY_INITIALIZED);
5667 result = cynara_initialize(&p_cynara, conf);
5669 if (result != CYNARA_API_SUCCESS) {
5670 cynara_strerror(result, err_msg, sizeof(err_msg));
5671 BT_ERR("Fail to initialize cynara: [%s]", err_msg);
5672 return BLUETOOTH_ERROR_INTERNAL;
5675 return BLUETOOTH_ERROR_NONE;
5678 void _bt_service_cynara_deinit(void)
5681 char err_msg[256] = {0, };
5683 ret_if(p_cynara == NULL);
5685 result = cynara_finish(p_cynara);
5687 if (result != CYNARA_API_SUCCESS) {
5688 cynara_strerror(result, err_msg, sizeof(err_msg));
5689 BT_ERR("Fail to finish cynara: [%s]", err_msg);
5697 void _bt_service_method_return(GDBusMethodInvocation *invocation,
5698 GArray *out_param, int result)
5702 out_var = g_variant_new_from_data((const GVariantType *)"ay",
5703 out_param->data, out_param->len, TRUE, NULL, NULL);
5705 g_dbus_method_invocation_return_value(invocation,
5706 g_variant_new("(iv)", result, out_var));
5709 void _bt_service_method_return_with_unix_fd_list(GDBusMethodInvocation *invocation,
5710 GArray *out_param, int result, GUnixFDList *fd_list)
5714 out_var = g_variant_new_from_data((const GVariantType *)"ay",
5715 out_param->data, out_param->len, TRUE, NULL, NULL);
5717 g_dbus_method_invocation_return_value_with_unix_fd_list(invocation,
5718 g_variant_new("(iv)", result, out_var), fd_list);