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_connect(BT_AUDIO_A2DP, &address);
1626 if (result != BLUETOOTH_ERROR_NONE) {
1627 char addr[BT_ADDRESS_STRING_SIZE];
1628 _bt_convert_addr_type_to_string(addr, address.addr);
1629 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1631 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1632 _bt_convert_addr_type_to_string(addr, address.addr);
1633 sender = (char*)g_dbus_method_invocation_get_sender(context);
1634 _bt_save_invocation_context(context, result, sender,
1635 function_name, (gpointer)addr);
1639 case BT_AUDIO_CONNECT: {
1640 bluetooth_device_address_t address = { {0} };
1641 __bt_service_get_parameters(in_param1,
1642 &address, sizeof(bluetooth_device_address_t));
1644 result = _bt_audio_connect(BT_AUDIO_ALL, &address);
1646 if (result != BLUETOOTH_ERROR_NONE) {
1647 char addr[BT_ADDRESS_STRING_SIZE];
1648 _bt_convert_addr_type_to_string(addr, address.addr);
1649 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1651 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1652 _bt_convert_addr_type_to_string(addr, address.addr);
1653 sender = (char*)g_dbus_method_invocation_get_sender(context);
1654 _bt_save_invocation_context(context, result, sender,
1655 function_name, (gpointer)addr);
1659 case BT_AUDIO_DISCONNECT: {
1660 bluetooth_device_address_t address = { {0} };
1661 __bt_service_get_parameters(in_param1,
1662 &address, sizeof(bluetooth_device_address_t));
1664 result = _bt_audio_disconnect(BT_AUDIO_ALL, &address);
1666 if (result != BLUETOOTH_ERROR_NONE) {
1667 char addr[BT_ADDRESS_STRING_SIZE];
1668 _bt_convert_addr_type_to_string(addr, address.addr);
1669 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1671 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1672 _bt_convert_addr_type_to_string(addr, address.addr);
1673 sender = (char*)g_dbus_method_invocation_get_sender(context);
1674 _bt_save_invocation_context(context, result, sender,
1675 function_name, (gpointer)addr);
1679 case BT_AV_DISCONNECT: {
1680 bluetooth_device_address_t address = { {0} };
1681 __bt_service_get_parameters(in_param1,
1682 &address, sizeof(bluetooth_device_address_t));
1684 result = _bt_audio_disconnect(BT_AUDIO_A2DP, &address);
1686 if (result != BLUETOOTH_ERROR_NONE) {
1687 char addr[BT_ADDRESS_STRING_SIZE];
1688 _bt_convert_addr_type_to_string(addr, address.addr);
1689 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1691 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1692 _bt_convert_addr_type_to_string(addr, address.addr);
1693 sender = (char*)g_dbus_method_invocation_get_sender(context);
1694 _bt_save_invocation_context(context, result, sender,
1695 function_name, (gpointer)addr);
1699 case BT_AG_CONNECT: {
1700 bluetooth_device_address_t address = { {0} };
1701 __bt_service_get_parameters(in_param1,
1702 &address, sizeof(bluetooth_device_address_t));
1704 result = _bt_audio_connect(BT_AUDIO_HSP, &address);
1706 if (result != BLUETOOTH_ERROR_NONE) {
1707 char addr[BT_ADDRESS_STRING_SIZE];
1708 _bt_convert_addr_type_to_string(addr, address.addr);
1709 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1711 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1712 _bt_convert_addr_type_to_string(addr, address.addr);
1713 sender = (char*)g_dbus_method_invocation_get_sender(context);
1714 _bt_save_invocation_context(context, result, sender,
1715 function_name, (gpointer)addr);
1719 case BT_AG_DISCONNECT: {
1720 bluetooth_device_address_t address = { {0} };
1722 __bt_service_get_parameters(in_param1,
1723 &address, sizeof(bluetooth_device_address_t));
1725 result = _bt_audio_disconnect(BT_AUDIO_HSP, &address);
1727 if (result != BLUETOOTH_ERROR_NONE) {
1728 char addr[BT_ADDRESS_STRING_SIZE];
1729 _bt_convert_addr_type_to_string(addr, address.addr);
1730 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1732 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1733 _bt_convert_addr_type_to_string(addr, address.addr);
1734 sender = (char*)g_dbus_method_invocation_get_sender(context);
1735 _bt_save_invocation_context(context, result, sender,
1736 function_name, (gpointer)addr);
1740 case BT_AV_SOURCE_CONNECT: {
1741 bluetooth_device_address_t address = { {0} };
1743 __bt_service_get_parameters(in_param1,
1744 &address, sizeof(bluetooth_device_address_t));
1746 result = _bt_audio_connect(BT_AUDIO_A2DP_SOURCE, &address);
1747 if (result != BLUETOOTH_ERROR_NONE) {
1748 char addr[BT_ADDRESS_STRING_SIZE];
1749 _bt_convert_addr_type_to_string(addr, address.addr);
1750 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1752 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1753 _bt_convert_addr_type_to_string(addr, address.addr);
1754 sender = (char*)g_dbus_method_invocation_get_sender(context);
1755 _bt_save_invocation_context(context, result, sender,
1756 function_name, (gpointer)addr);
1760 case BT_AV_SOURCE_DISCONNECT: {
1761 bluetooth_device_address_t address = { {0} };
1763 __bt_service_get_parameters(in_param1,
1764 &address, sizeof(bluetooth_device_address_t));
1766 result = _bt_audio_disconnect(BT_AUDIO_A2DP_SOURCE, &address);
1767 if (result != BLUETOOTH_ERROR_NONE) {
1768 char addr[BT_ADDRESS_STRING_SIZE];
1769 _bt_convert_addr_type_to_string(addr, address.addr);
1770 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1772 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1773 _bt_convert_addr_type_to_string(addr, address.addr);
1774 sender = (char*)g_dbus_method_invocation_get_sender(context);
1775 _bt_save_invocation_context(context, result, sender,
1776 function_name, (gpointer)addr);
1780 case BT_HF_CONNECT: {
1781 bluetooth_device_address_t address = { {0} };
1783 __bt_service_get_parameters(in_param1,
1784 &address, sizeof(bluetooth_device_address_t));
1786 result = _bt_hf_connect(&address);
1787 if (result != BLUETOOTH_ERROR_NONE) {
1788 char addr[BT_ADDRESS_STRING_SIZE];
1789 _bt_convert_addr_type_to_string(addr, address.addr);
1790 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1792 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1793 _bt_convert_addr_type_to_string(addr, address.addr);
1794 sender = (char*)g_dbus_method_invocation_get_sender(context);
1795 _bt_save_invocation_context(context, result, sender,
1796 function_name, (gpointer)addr);
1800 case BT_HF_DISCONNECT: {
1801 bluetooth_device_address_t address = { {0} };
1803 __bt_service_get_parameters(in_param1,
1804 &address, sizeof(bluetooth_device_address_t));
1806 result = _bt_hf_disconnect(&address);
1807 if (result != BLUETOOTH_ERROR_NONE) {
1808 char addr[BT_ADDRESS_STRING_SIZE];
1809 _bt_convert_addr_type_to_string(addr, address.addr);
1810 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1812 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1813 _bt_convert_addr_type_to_string(addr, address.addr);
1814 sender = (char*)g_dbus_method_invocation_get_sender(context);
1815 _bt_save_invocation_context(context, result, sender,
1816 function_name, (gpointer)addr);
1820 case BT_AVRCP_TARGET_CONNECT: {
1821 bluetooth_device_address_t address = { {0} };
1823 __bt_service_get_parameters(in_param1,
1824 &address, sizeof(bluetooth_device_address_t));
1826 result = _bt_audio_connect(BT_AVRCP_TARGET, &address);
1827 if (result != BLUETOOTH_ERROR_NONE) {
1828 char addr[BT_ADDRESS_STRING_SIZE];
1829 _bt_convert_addr_type_to_string(addr, address.addr);
1830 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1832 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1833 _bt_convert_addr_type_to_string(addr, address.addr);
1834 sender = (char*)g_dbus_method_invocation_get_sender(context);
1835 _bt_save_invocation_context(context, result, sender,
1836 function_name, (gpointer)addr);
1840 case BT_AVRCP_TARGET_DISCONNECT: {
1841 bluetooth_device_address_t address = { {0} };
1843 __bt_service_get_parameters(in_param1,
1844 &address, sizeof(bluetooth_device_address_t));
1846 result = _bt_audio_disconnect(BT_AVRCP_TARGET, &address);
1847 if (result != BLUETOOTH_ERROR_NONE) {
1848 char addr[BT_ADDRESS_STRING_SIZE];
1849 _bt_convert_addr_type_to_string(addr, address.addr);
1850 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1852 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1853 _bt_convert_addr_type_to_string(addr, address.addr);
1854 sender = (char*)g_dbus_method_invocation_get_sender(context);
1855 _bt_save_invocation_context(context, result, sender,
1856 function_name, (gpointer)addr);
1860 case BT_AVRCP_CONTROL_CONNECT: {
1861 bluetooth_device_address_t address = { {0} };
1863 __bt_service_get_parameters(in_param1,
1864 &address, sizeof(bluetooth_device_address_t));
1866 result = _bt_audio_connect(BT_AVRCP, &address);
1867 if (result != BLUETOOTH_ERROR_NONE) {
1868 char addr[BT_ADDRESS_STRING_SIZE];
1869 _bt_convert_addr_type_to_string(addr, address.addr);
1870 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1872 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1873 _bt_convert_addr_type_to_string(addr, address.addr);
1874 sender = (char*)g_dbus_method_invocation_get_sender(context);
1875 _bt_save_invocation_context(context, result, sender,
1876 function_name, (gpointer)addr);
1880 case BT_AVRCP_CONTROL_DISCONNECT: {
1881 bluetooth_device_address_t address = { {0} };
1883 __bt_service_get_parameters(in_param1,
1884 &address, sizeof(bluetooth_device_address_t));
1886 result = _bt_audio_disconnect(BT_AVRCP, &address);
1887 if (result != BLUETOOTH_ERROR_NONE) {
1888 char addr[BT_ADDRESS_STRING_SIZE];
1889 _bt_convert_addr_type_to_string(addr, address.addr);
1890 g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1892 char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1893 _bt_convert_addr_type_to_string(addr, address.addr);
1894 sender = (char*)g_dbus_method_invocation_get_sender(context);
1895 _bt_save_invocation_context(context, result, sender,
1896 function_name, (gpointer)addr);
1900 case BT_AVRCP_HANDLE_CONTROL: {
1902 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1903 result = _bt_avrcp_control_cmd(key_code);
1906 case BT_AVRCP_HANDLE_CONTROL_TO_DEST: {
1908 bluetooth_device_address_t address = { { 0 } };
1910 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1911 __bt_service_get_parameters(in_param2,
1912 &address, sizeof(bluetooth_device_address_t));
1914 result = _bt_avrcp_control_cmd_to_dest(key_code, &address);
1917 case BT_AVRCP_CONTROL_SET_PROPERTY: {
1921 __bt_service_get_parameters(in_param1,
1922 &type, sizeof(int));
1923 __bt_service_get_parameters(in_param2,
1924 &value, sizeof(unsigned int));
1926 result = _bt_avrcp_control_set_property(type, value);
1929 case BT_AVRCP_TRANSPORT_SET_PROPERTY: {
1934 __bt_service_get_parameters(in_param1,
1935 &type, sizeof(int));
1936 __bt_service_get_parameters(in_param2,
1937 &value, sizeof(unsigned int));
1939 result = _bt_avrcp_transport_set_property(type, value);
1943 case BT_AVRCP_CONTROL_GET_PROPERTY: {
1946 __bt_service_get_parameters(in_param1, &type, sizeof(int));
1948 result = _bt_avrcp_control_get_property(type);
1949 /* Save invocation */
1950 if (result == BLUETOOTH_ERROR_NONE) {
1951 sender = (char*)g_dbus_method_invocation_get_sender(context);
1952 _bt_save_invocation_context(context, result, sender,
1953 function_name, g_memdup(&type, sizeof(int)));
1957 case BT_AVRCP_GET_TRACK_INFO: {
1958 result = _bt_avrcp_control_get_track_info();
1959 /* Save invocation */
1960 if (result == BLUETOOTH_ERROR_NONE) {
1961 sender = (char*)g_dbus_method_invocation_get_sender(context);
1962 _bt_save_invocation_context(context, result, sender,
1963 function_name, NULL);
1967 case BT_HDP_REGISTER_SINK_APP: {
1968 unsigned short data_type;
1969 bt_hdp_role_type_t role;
1970 bt_hdp_qos_type_t channel_type;
1971 int *app_id = g_new0(int, 1);
1973 __bt_service_get_parameters(in_param1,
1974 &data_type, sizeof(short));
1975 __bt_service_get_parameters(in_param2,
1976 &role, sizeof(bt_hdp_role_type_t));
1977 __bt_service_get_parameters(in_param3,
1978 &channel_type, sizeof(bt_hdp_qos_type_t));
1979 sender = (char*)g_dbus_method_invocation_get_sender(context);
1981 result = _bt_hdp_app_register(role,
1982 channel_type, data_type, sender, app_id);
1983 if (result != BLUETOOTH_ERROR_NONE) {
1984 g_array_append_vals(*out_param1, &app_id, sizeof(app_id));
1987 _bt_save_invocation_context(context, result, sender,
1988 function_name, (gpointer)app_id);
1992 case BT_HDP_UNREGISTER_SINK_APP: {
1994 int *app_id = g_new0(int, 1);
1996 app_handle = (char *)g_variant_get_data(in_param1);
1997 sscanf(app_handle, "health_app_%d", app_id);
1998 result = _bt_hdp_app_unregister(*app_id);
1999 if (result != BLUETOOTH_ERROR_NONE) {
2002 sender = (char*)g_dbus_method_invocation_get_sender(context);
2003 _bt_save_invocation_context(context, result, sender,
2004 function_name, (gpointer)app_id);
2008 case BT_HDP_CONNECT: {
2012 bt_hdp_connected_t *conn_info = NULL;
2014 conn_info = g_malloc0(sizeof(bt_hdp_connected_t));
2016 app_handle = (char *)g_variant_get_data(in_param1);
2017 conn_info->app_handle = app_handle;
2018 sscanf(app_handle, "health_app_%d", &app_id);
2020 __bt_service_get_parameters(in_param2,
2021 &(conn_info->type), sizeof(bt_hdp_qos_type_t));
2022 __bt_service_get_parameters(in_param3,
2023 &(conn_info->device_address),
2024 sizeof(bluetooth_device_address_t));
2026 result = _bt_hdp_connect(app_id, &(conn_info->device_address),
2027 conn_info->type, (int *)(&(conn_info->channel_id)));
2028 if (result != BLUETOOTH_ERROR_NONE) {
2029 g_array_append_vals(*out_param1, conn_info,
2030 sizeof(bt_hdp_connected_t));
2033 sender = (char*)g_dbus_method_invocation_get_sender(context);
2034 _bt_save_invocation_context(context, result, sender,
2035 function_name, (gpointer)conn_info);
2039 case BT_HDP_DISCONNECT: {
2040 bt_hdp_disconnected_t *hdp_disconn_info = NULL;
2042 hdp_disconn_info = g_malloc0(sizeof(bt_hdp_disconnected_t));
2044 __bt_service_get_parameters(in_param1,
2045 &(hdp_disconn_info->channel_id), sizeof(int));
2046 __bt_service_get_parameters(in_param2,
2047 &(hdp_disconn_info->device_address),
2048 sizeof(bluetooth_device_address_t));
2050 result = _bt_hdp_disconnect(hdp_disconn_info->channel_id);
2051 if (result != BLUETOOTH_ERROR_NONE) {
2052 g_array_append_vals(*out_param1, hdp_disconn_info,
2053 sizeof(bt_hdp_disconnected_t));
2054 g_free(hdp_disconn_info);
2056 sender = (char*)g_dbus_method_invocation_get_sender(context);
2057 _bt_save_invocation_context(context, result, sender,
2058 function_name, (gpointer)hdp_disconn_info);
2062 case BT_HDP_GET_FD: {
2063 int *channel_id = g_new0(int, 1);
2065 __bt_service_get_parameters(in_param1, channel_id, sizeof(int));
2067 result = _bt_hdp_get_fd(*channel_id);
2068 if (result != BLUETOOTH_ERROR_NONE) {
2071 sender = (char*)g_dbus_method_invocation_get_sender(context);
2072 _bt_save_invocation_context(context, result, sender,
2073 function_name, (gpointer)channel_id);
2077 case BT_HDP_SEND_DATA: {
2079 * This call to bt-service is only used for privilege check, so return
2080 * BLUETOOTH_ERROR_NONE from here.
2082 result = BLUETOOTH_ERROR_NONE;
2085 case BT_OOB_READ_LOCAL_DATA: { //208
2086 bt_oob_data_t local_oob_data;
2088 memset(&local_oob_data, 0x00, sizeof(bt_oob_data_t));
2089 result = _bt_oob_read_local_data(&local_oob_data);
2091 g_array_append_vals(*out_param1, &local_oob_data,
2092 sizeof(bt_oob_data_t));
2096 case BT_OOB_ADD_REMOTE_DATA: { //209
2097 bluetooth_device_address_t address = { {0} };
2098 unsigned short address_type;
2099 bt_oob_data_t remote_oob_data;
2101 __bt_service_get_parameters(in_param1,
2102 &address, sizeof(bluetooth_device_address_t));
2103 __bt_service_get_parameters(in_param2,
2104 &address_type, sizeof(unsigned short));
2105 __bt_service_get_parameters(in_param3,
2106 &remote_oob_data, sizeof(bt_oob_data_t));
2108 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2112 case BT_OOB_REMOVE_REMOTE_DATA: { //210
2113 bluetooth_device_address_t address = { {0} };
2115 __bt_service_get_parameters(in_param1,
2116 &address, sizeof(bluetooth_device_address_t));
2118 result = _bt_oob_remove_remote_data(&address);
2122 case BT_LE_OOB_READ_LOCAL_DATA: {
2123 bt_oob_data_t local_oob_data;
2124 bt_oob_data_t *local_oob_cache_data;
2126 local_oob_cache_data = _bt_le_oob_get_local_cache_data();
2127 if (local_oob_cache_data && local_oob_cache_data->eir_len) {
2128 g_array_append_vals(*out_param1, local_oob_cache_data,
2129 sizeof(bt_oob_data_t));
2130 return BLUETOOTH_ERROR_NONE;
2133 /* We should modify this logic in later */
2134 if (_bt_is_le_static_random_address_enabled() == false) {
2135 /* Seperate BT & LE address */
2136 _bt_set_le_static_random_address(TRUE);
2139 result = _bt_le_oob_read_local_data(&local_oob_data);
2140 _bt_le_oob_set_local_cache_data(&local_oob_data);
2142 g_array_append_vals(*out_param1, &local_oob_data,
2143 sizeof(bt_oob_data_t));
2147 case BT_LE_OOB_ADD_REMOTE_DATA: {
2148 bluetooth_device_address_t address = { {0} };
2149 unsigned short address_type;
2150 bt_oob_data_t remote_oob_data;
2152 __bt_service_get_parameters(in_param1,
2153 &address, sizeof(bluetooth_device_address_t));
2154 __bt_service_get_parameters(in_param2,
2155 &address_type, sizeof(unsigned short));
2156 __bt_service_get_parameters(in_param3,
2157 &remote_oob_data, sizeof(bt_oob_data_t));
2159 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2163 case BT_AVRCP_SET_TRACK_INFO: {
2164 media_metadata_t data;
2165 media_metadata_attributes_t meta_data;
2167 memset(&data, 0x00, sizeof(media_metadata_t));
2168 memset(&meta_data, 0x00, sizeof(media_metadata_attributes_t));
2170 __bt_service_get_parameters(in_param1,
2171 &data, sizeof(media_metadata_t));
2173 meta_data.title = g_strdup(data.title);
2174 meta_data.artist = g_strdup(data.artist);
2175 meta_data.album = g_strdup(data.album);
2176 meta_data.genre = g_strdup(data.genre);
2177 meta_data.total_tracks = data.total_tracks;
2178 meta_data.number = data.number;
2179 meta_data.duration = (int64_t) data.duration;
2181 result = _bt_avrcp_set_track_info(&meta_data);
2183 g_free((gpointer)meta_data.title);
2184 g_free((gpointer)meta_data.artist);
2185 g_free((gpointer)meta_data.album);
2186 g_free((gpointer)meta_data.genre);
2190 case BT_AVRCP_SET_PROPERTY: {
2194 sender = (char *)g_dbus_method_invocation_get_sender(context);
2196 __bt_service_get_parameters(in_param1,
2197 &type, sizeof(int));
2198 __bt_service_get_parameters(in_param2,
2199 &value, sizeof(unsigned int));
2201 if (value == STATUS_PLAYING) {
2202 if (current_sender_playing)
2203 g_free(current_sender_playing);
2204 current_sender_playing = g_strdup(sender);
2206 if (g_strcmp0(sender, current_sender_playing) == 0 ||
2207 current_sender_playing == NULL) {
2208 BT_INFO("Current Player Status %d type %d Sender %s", value, type, sender);
2210 BT_INFO("Current Player and this sender (%s) are different", sender);
2211 result = BLUETOOTH_ERROR_NONE;
2214 result = _bt_avrcp_set_property(type, value);
2218 case BT_AVRCP_SET_PROPERTIES: {
2219 media_player_settings_t properties;
2221 memset(&properties, 0x00, sizeof(media_player_settings_t));
2222 __bt_service_get_parameters(in_param1,
2223 &properties, sizeof(media_player_settings_t));
2225 result = _bt_avrcp_set_properties(&properties);
2229 case BT_SET_ADVERTISING_DATA: {
2232 bluetooth_advertising_data_t adv = { {0} };
2234 gboolean use_reserved_slot = FALSE;
2236 app = (char *)g_dbus_method_invocation_get_sender(context);
2237 adv_handle = g_malloc0(sizeof(int));
2239 __bt_service_get_parameters(in_param1,
2240 adv_handle, sizeof(int));
2241 __bt_service_get_parameters(in_param3,
2242 &length, sizeof(int));
2243 __bt_service_get_parameters(in_param2,
2245 __bt_service_get_parameters(in_param4,
2246 &use_reserved_slot, sizeof(gboolean));
2247 result = _bt_set_advertising_data(app, *adv_handle,
2248 &adv, length, use_reserved_slot);
2249 if (result != BLUETOOTH_ERROR_NONE) {
2250 BT_ERR("Set Advertising data failed!!");
2253 _bt_save_invocation_context(context, result, app,
2254 function_name, (gpointer)adv_handle);
2258 case BT_SET_SCAN_RESPONSE_DATA: {
2261 bluetooth_scan_resp_data_t rsp = { {0} };
2263 gboolean use_reserved_slot = FALSE;
2265 app = (char *)g_dbus_method_invocation_get_sender(context);
2266 adv_handle = g_malloc0(sizeof(int));
2268 __bt_service_get_parameters(in_param1,
2269 adv_handle, sizeof(int));
2270 __bt_service_get_parameters(in_param3,
2271 &length, sizeof(int));
2272 __bt_service_get_parameters(in_param2,
2274 __bt_service_get_parameters(in_param4,
2275 &use_reserved_slot, sizeof(gboolean));
2277 result = _bt_set_scan_response_data(app, *adv_handle,
2278 &rsp, length, use_reserved_slot);
2280 if (result != BLUETOOTH_ERROR_NONE) {
2281 BT_ERR("Set Scan Response Data failed!!");
2284 _bt_save_invocation_context(context, result, app,
2285 function_name, (gpointer)adv_handle);
2289 case BT_SET_ADVERTISING: {
2292 gboolean enable = FALSE;
2293 gboolean use_reserved_slot = FALSE;
2295 adv_handle = g_malloc0(sizeof(int));
2296 __bt_service_get_parameters(in_param1,
2297 adv_handle, sizeof(int));
2298 __bt_service_get_parameters(in_param2,
2299 &enable, sizeof(gboolean));
2300 __bt_service_get_parameters(in_param3,
2301 &use_reserved_slot, sizeof(gboolean));
2303 app = (char *)g_dbus_method_invocation_get_sender(context);
2305 result = _bt_set_advertising(app, *adv_handle,
2306 enable, use_reserved_slot);
2307 if (result != BLUETOOTH_ERROR_NONE) {
2308 BT_ERR("Start Advertising failed!!");
2311 _bt_save_invocation_context(context, result, app,
2312 function_name, (gpointer)adv_handle);
2316 case BT_SET_CUSTOM_ADVERTISING: {
2319 gboolean enable = FALSE;
2320 bluetooth_advertising_params_t adv_params;
2321 gboolean use_reserved_slot = FALSE;
2323 app = (char *)g_dbus_method_invocation_get_sender(context);
2324 adv_handle = g_malloc0(sizeof(int));
2326 __bt_service_get_parameters(in_param1, adv_handle,
2328 __bt_service_get_parameters(in_param2, &enable,
2330 __bt_service_get_parameters(in_param3, &adv_params,
2331 sizeof(bluetooth_advertising_params_t));
2332 __bt_service_get_parameters(in_param4, &use_reserved_slot,
2335 BT_DBG("bluetooth_advertising_params_t [%f %f %d %d %d]",
2336 adv_params.interval_min, adv_params.interval_max,
2337 adv_params.filter_policy, adv_params.type, adv_params.tx_power_level);
2338 result = _bt_set_custom_advertising(app, *adv_handle,
2339 enable, &adv_params, use_reserved_slot);
2340 if (result != BLUETOOTH_ERROR_NONE) {
2341 BT_ERR("Start Custom Advertising failed!!");
2344 _bt_save_invocation_context(context, result, app,
2345 function_name, (gpointer)adv_handle);
2349 case BT_GET_SCAN_RESPONSE_DATA: {
2350 bluetooth_scan_resp_data_t rsp = { {0} };
2354 app = (char *)g_dbus_method_invocation_get_sender(context);
2356 __bt_service_get_parameters(in_param1, &adv_handle,
2359 result = _bt_get_scan_response_data(app, adv_handle, &rsp, &length);
2360 if (result == BLUETOOTH_ERROR_NONE)
2361 g_array_append_vals(*out_param1, rsp.data, length);
2365 case BT_GET_ADVERTISING_DATA: {
2366 bluetooth_advertising_data_t adv = { {0} };
2370 app = (char *)g_dbus_method_invocation_get_sender(context);
2372 __bt_service_get_parameters(in_param1, &adv_handle,
2375 result = _bt_get_advertising_data(app, adv_handle, &adv, &length);
2376 if (result == BLUETOOTH_ERROR_NONE)
2377 g_array_append_vals(*out_param1, adv.data, length);
2381 case BT_GATT_REGISTER_APPLICATION: {
2382 BT_DBG("Register GATT application:Unhandled!!");
2385 case BT_GATT_SERVER_REGISTER: {
2386 BT_DBG("GATT Server instance initialization");
2389 app = (char *)g_dbus_method_invocation_get_sender(context);
2390 BT_DBG("GATT Server Unique Name [%s]", app);
2392 /* No ADV handle: Set 0 */
2393 result = _bt_register_server_instance(app, 0);
2395 if (result != BLUETOOTH_ERROR_NONE) {
2396 BT_ERR("GATT Server registration failed. result %d", result);
2398 _bt_save_invocation_context(context, result, app,
2399 function_name, NULL);
2403 case BT_GATT_SERVER_DEREGISTER: {
2405 app = (char*)g_dbus_method_invocation_get_sender(context);
2407 result = _bt_unregister_server_instance(app, 0/* Adv Handle*/);
2410 case BT_GATT_SERVER_ADD_SERVICE: {
2411 BT_DBG("GATT Server Add Service");
2417 int *tmp_inst_id = NULL;
2419 app = (char *)g_dbus_method_invocation_get_sender(context);
2421 __bt_service_get_parameters(in_param1, &service_type,
2423 __bt_service_get_parameters(in_param2, &num_handles,
2425 svc_uuid = (char *)g_variant_get_data(in_param3);
2426 __bt_service_get_parameters(in_param4, &instance_id,
2429 result = _bt_gatt_server_add_service(app, service_type, num_handles, svc_uuid, instance_id);
2430 if (result != BLUETOOTH_ERROR_NONE) {
2431 BT_ERR("GATT Server Add Service failed!!");
2433 tmp_inst_id = g_malloc0(sizeof(int));
2434 *tmp_inst_id = instance_id;
2435 _bt_save_invocation_context(context, result, app,
2436 function_name, (gpointer)tmp_inst_id);
2440 case BT_GATT_SERVER_ADD_CHARACTERISTIC: {
2441 BT_DBG("GATT Server Add Characteristic");
2444 int *tmp_inst_id = NULL;
2445 bluetooth_gatt_server_attribute_params_t param;
2446 memset(¶m, 0, sizeof(bluetooth_gatt_server_attribute_params_t));
2448 app = (char*)g_dbus_method_invocation_get_sender(context);
2450 __bt_service_get_parameters(in_param1, ¶m,
2451 sizeof(bluetooth_gatt_server_attribute_params_t));
2452 char_uuid = (char *)g_variant_get_data(in_param2);
2454 result = _bt_gatt_server_add_characteristic(app, char_uuid, ¶m);
2455 if (result != BLUETOOTH_ERROR_NONE) {
2456 BT_ERR("GATT Server Add Service failed!!");
2458 tmp_inst_id = g_malloc0(sizeof(int));
2459 *tmp_inst_id = param.instance_id;
2461 _bt_save_invocation_context(context, result, app,
2462 function_name, (gpointer)tmp_inst_id);
2466 case BT_GATT_SERVER_ADD_DESCRIPTOR: {
2467 BT_DBG("GATT Server Add Descriptor");
2471 bt_gatt_permission_t perm;
2473 int *tmp_inst_id = NULL;
2474 memset(&perm, 0, sizeof(bt_gatt_permission_t));
2476 app = (char *)g_dbus_method_invocation_get_sender(context);
2478 __bt_service_get_parameters(in_param1, &service_handle,
2480 __bt_service_get_parameters(in_param2, &instance_id,
2482 desc_uuid = (char *)g_variant_get_data(in_param4);
2483 __bt_service_get_parameters(in_param3, &perm,
2484 sizeof(bt_gatt_permission_t));
2486 result = _bt_gatt_server_add_descriptor(app, desc_uuid, &perm, service_handle, instance_id);
2487 if (result != BLUETOOTH_ERROR_NONE) {
2488 BT_ERR("GATT Server Add Service failed!!");
2490 tmp_inst_id = g_malloc0(sizeof(int));
2491 *tmp_inst_id = instance_id;
2492 _bt_save_invocation_context(context, result, app,
2493 function_name, (gpointer)tmp_inst_id);
2497 case BT_GATT_SERVER_START_SERVICE: {
2502 int *tmp_inst_id = NULL;
2503 app = (char*)g_dbus_method_invocation_get_sender(context);
2505 __bt_service_get_parameters(in_param1, &service_handle,
2507 __bt_service_get_parameters(in_param2, &instance_id,
2510 result = _bt_gatt_server_start_service(app, service_handle, instance_id);
2512 if (BLUETOOTH_ERROR_NONE == result) {
2513 tmp_inst_id = g_malloc0(sizeof(int));
2514 *tmp_inst_id = instance_id;
2515 _bt_save_invocation_context(context, result, app,
2516 function_name, (gpointer)tmp_inst_id);
2520 case BT_GATT_SERVER_STOP_SERVICE: {
2524 int *tmp_inst_id = NULL;
2525 app = (char*)g_dbus_method_invocation_get_sender(context);
2527 __bt_service_get_parameters(in_param1, &service_handle,
2529 __bt_service_get_parameters(in_param2, &instance_id,
2532 result = _bt_gatt_server_stop_service(app, service_handle, instance_id);
2534 if (BLUETOOTH_ERROR_NONE == result) {
2535 tmp_inst_id = g_malloc0(sizeof(int));
2536 *tmp_inst_id = instance_id;
2537 _bt_save_invocation_context(context, result, app,
2538 function_name, (gpointer)tmp_inst_id);
2542 case BT_GATT_SERVER_DELETE_SERVICE: {
2545 int *tmp_inst_id = NULL;
2547 app = (char*)g_dbus_method_invocation_get_sender(context);
2549 __bt_service_get_parameters(in_param1, &service_handle,
2551 __bt_service_get_parameters(in_param2, &instance_id,
2554 result = _bt_gatt_server_delete_service(app, service_handle, instance_id);
2556 if (BLUETOOTH_ERROR_NONE == result) {
2557 tmp_inst_id = g_malloc0(sizeof(int));
2558 *tmp_inst_id = instance_id;
2559 _bt_save_invocation_context(context, result, app,
2560 function_name, (gpointer)tmp_inst_id);
2564 case BT_GATT_SERVER_SEND_RESPONSE: {
2565 bluetooth_gatt_server_response_params_t param;
2566 bluetooth_gatt_att_data_t data;
2569 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_response_params_t));
2570 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2572 app = (char*)g_dbus_method_invocation_get_sender(context);
2574 __bt_service_get_parameters(in_param1, &data,
2575 sizeof(bluetooth_gatt_att_data_t));
2576 __bt_service_get_parameters(in_param2, ¶m,
2577 sizeof(bluetooth_gatt_server_response_params_t));
2579 result = _bt_gatt_server_send_response(app, &data, ¶m);
2583 case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE: {
2585 bluetooth_gatt_server_acquire_response_params_t param;
2588 msg = g_dbus_method_invocation_get_message(context);
2589 GUnixFDList *fd_list;
2594 fd_list = g_dbus_message_get_unix_fd_list(msg);
2596 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2598 app = (char*)g_dbus_method_invocation_get_sender(context);
2600 __bt_service_get_parameters(in_param1, ¶m,
2601 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2603 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2604 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2605 fd = fd_list_array[0];
2608 result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
2612 case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE: {
2614 bluetooth_gatt_server_acquire_response_params_t param;
2617 msg = g_dbus_method_invocation_get_message(context);
2618 GUnixFDList *fd_list;
2623 fd_list = g_dbus_message_get_unix_fd_list(msg);
2625 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2627 app = (char*)g_dbus_method_invocation_get_sender(context);
2629 __bt_service_get_parameters(in_param1, ¶m,
2630 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2632 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2633 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2634 fd = fd_list_array[0];
2637 result = _bt_gatt_server_acquire_send_response(app, ¶m, fd_list);
2641 case BT_GATT_SERVER_SEND_INDICATION: {
2642 bluetooth_gatt_server_indication_params_t param;
2643 bluetooth_gatt_att_data_t data;
2644 bluetooth_device_address_t address;
2647 app = (char*)g_dbus_method_invocation_get_sender(context);
2649 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_indication_params_t));
2650 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2651 memset(&address, 0x00, sizeof(bluetooth_device_address_t));
2653 __bt_service_get_parameters(in_param1, &data,
2654 sizeof(bluetooth_gatt_att_data_t));
2655 __bt_service_get_parameters(in_param2, ¶m,
2656 sizeof(bluetooth_gatt_server_indication_params_t));
2657 __bt_service_get_parameters(in_param3, &address,
2658 sizeof(bluetooth_device_address_t));
2660 result = _bt_gatt_server_send_indication(app, &address, &data, ¶m);
2664 case BT_GATT_SERVER_UPDATE_VALUE: {
2665 bluetooth_gatt_server_update_value_t param;
2669 memset(¶m, 0x00, sizeof(bluetooth_gatt_server_update_value_t));
2671 app = (char*)g_dbus_method_invocation_get_sender(context);
2673 __bt_service_get_parameters(in_param1, &instance_id,
2675 __bt_service_get_parameters(in_param2, ¶m,
2676 sizeof(bluetooth_gatt_server_update_value_t));
2678 result = _bt_gatt_server_update_attribute_value(app, instance_id, ¶m);
2681 case BT_GET_ATT_MTU: {
2682 bluetooth_device_address_t address = { {0} };
2683 unsigned int mtu = 0;
2685 __bt_service_get_parameters(in_param1,
2686 &address, sizeof(bluetooth_device_address_t));
2687 result = _bt_get_att_mtu(&address, &mtu);
2688 BT_DBG("MTU: %d", mtu);
2690 if (result == BLUETOOTH_ERROR_NONE) {
2691 g_array_append_vals(*out_param1, &mtu,
2692 sizeof(unsigned int));
2696 case BT_REQ_ATT_MTU: {
2697 bluetooth_device_address_t address = { {0} };
2701 sender = (char*)g_dbus_method_invocation_get_sender(context);
2703 __bt_service_get_parameters(in_param1,
2704 &address, sizeof(bluetooth_device_address_t));
2705 __bt_service_get_parameters(in_param2,
2706 &mtu, sizeof(unsigned int));
2707 BT_DBG("BT_REQ_ATT_MTU: %d", mtu);
2708 result = _bt_request_att_mtu(&address, mtu);
2709 if (BLUETOOTH_ERROR_NONE == result) {
2710 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2712 _bt_convert_addr_type_to_string(addr, address.addr);
2714 /* Save the informations to invocation */
2715 _bt_save_invocation_context(context, result, sender,
2716 function_name, (gpointer)addr);
2718 g_array_append_vals(*out_param1, &address,
2719 sizeof(bluetooth_device_address_t));
2723 case BT_GET_DEVICE_IDA: {
2724 bluetooth_device_address_t address = { {0} };
2725 bluetooth_device_address_t id_addr = { {0} };
2727 __bt_service_get_parameters(in_param1,
2728 &address, sizeof(bluetooth_device_address_t));
2730 result = _bt_device_get_ida(&address, &id_addr);
2732 if (result == BLUETOOTH_ERROR_NONE) {
2733 g_array_append_vals(*out_param1, &id_addr,
2734 sizeof(bluetooth_device_address_t));
2738 case BT_SET_LE_STATIC_RANDOM_ADDRESS: {
2741 __bt_service_get_parameters(in_param1, &is_enable,
2744 result = _bt_set_le_static_random_address(is_enable);
2749 case BT_GATT_CLIENT_REGISTER: {
2750 bluetooth_device_address_t address = { {0} };
2753 sender = (char*)g_dbus_method_invocation_get_sender(context);
2755 __bt_service_get_parameters(in_param1,
2756 &address, sizeof(bluetooth_device_address_t));
2758 result = _bt_register_gatt_client_instance(sender, &address);
2759 if (BLUETOOTH_ERROR_NONE == result) {
2760 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2762 _bt_convert_addr_type_to_string(addr, address.addr);
2764 /* Save the informations to invocation */
2765 _bt_save_invocation_context(context, result, sender,
2766 function_name, (gpointer)addr);
2771 case BT_GATT_CLIENT_UNREGISTER: {
2774 sender = (char*)g_dbus_method_invocation_get_sender(context);
2775 __bt_service_get_parameters(in_param1,
2776 &client_id, sizeof(int));
2778 result = _bt_unregister_gatt_client_instance(sender, client_id);
2782 /* Async: Remote Interaction */
2783 case BT_GATT_ACQUIRE_WRITE: {
2787 bluetooth_gatt_client_char_prop_info_t param;
2789 sender = (char*)g_dbus_method_invocation_get_sender(context);
2791 __bt_service_get_parameters(in_param1, ¶m,
2792 sizeof(bluetooth_gatt_client_char_prop_info_t));
2795 result = _bt_gatt_acquire_write(¶m , &fd, &mtu);
2797 g_array_append_vals(*out_param1, &mtu, sizeof(int));
2799 if (BLUETOOTH_ERROR_NONE == result)
2800 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
2802 BT_ERR("GATT Client: gatt acquire write failed");
2806 GUnixFDList *fd_list = NULL;
2807 GError *error = NULL;
2809 /* Add socket fd to unix_fd_list */
2810 fd_list = g_unix_fd_list_new();
2811 g_unix_fd_list_append(fd_list, fd, &error);
2812 g_assert_no_error(error);
2814 _bt_service_method_return_with_unix_fd_list(
2815 context, *out_param1, result, fd_list);
2818 g_object_unref(fd_list);
2822 /* Async: Remote Interaction */
2823 case BT_CONNECT_LE: {
2824 bluetooth_device_address_t address = { {0} };
2825 gboolean auto_connect;
2829 sender = (char*)g_dbus_method_invocation_get_sender(context);
2831 __bt_service_get_parameters(in_param1,
2832 &address, sizeof(bluetooth_device_address_t));
2833 __bt_service_get_parameters(in_param2,
2834 &auto_connect, sizeof(gboolean));
2835 __bt_service_get_parameters(in_param3,
2836 &client_id, sizeof(int));
2838 BT_DBG("GATT Client: client_id[%d]", client_id);
2839 result = _bt_connect_le_device(&address, auto_connect, client_id);
2840 if (BLUETOOTH_ERROR_NONE == result) {
2841 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2842 _bt_convert_addr_type_to_string(addr, address.addr);
2844 /* Save the informations to invocation */
2845 _bt_save_invocation_context(context, result, sender,
2846 function_name, (gpointer)addr);
2849 _bt_handle_invocation_context(function_name, (void *)addr);
2851 BT_ERR("GATT Client: gatt connect failed. client_id[%d]", client_id);
2852 g_array_append_vals(*out_param1, &address,
2853 sizeof(bluetooth_device_address_t));
2857 /* Async: Remote Interaction */
2858 case BT_DISCONNECT_LE: {
2859 bluetooth_device_address_t address = { {0} };
2863 sender = (char*)g_dbus_method_invocation_get_sender(context);
2865 __bt_service_get_parameters(in_param1,
2866 &address, sizeof(bluetooth_device_address_t));
2867 __bt_service_get_parameters(in_param2,
2868 &client_id, sizeof(int));
2870 BT_INFO("GATT Disconnect using client Interface [%d]", client_id);
2871 result = _bt_disconnect_le_device(&address, client_id);
2872 if (BLUETOOTH_ERROR_NONE == result) {
2873 addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2875 _bt_convert_addr_type_to_string(addr, address.addr);
2877 /* Save the informations to invocation */
2878 _bt_save_invocation_context(context, result, sender,
2879 function_name, (gpointer)addr);
2881 g_array_append_vals(*out_param1, &address,
2882 sizeof(bluetooth_device_address_t));
2887 case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS: {
2888 guint available_packets = 0;
2890 result = _bt_gatt_get_data_batching_available_packets(&available_packets);
2891 BT_DBG("LE batching available packets %u", available_packets);
2892 if (result == BLUETOOTH_ERROR_NONE) {
2893 g_array_append_vals(*out_param1, &available_packets,
2900 case BT_ENABLE_GATT_DATA_BATCHING: {
2901 bluetooth_device_address_t address = { {0} };
2902 int packet_threshold;
2905 __bt_service_get_parameters(in_param1,
2906 &address, sizeof(bluetooth_device_address_t));
2907 __bt_service_get_parameters(in_param2,
2908 &packet_threshold, sizeof(int));
2909 __bt_service_get_parameters(in_param3,
2910 &timeout, sizeof(int));
2911 result = _bt_gatt_enable_data_batching(&address, packet_threshold, timeout);
2916 case BT_DISABLE_GATT_DATA_BATCHING: {
2917 bluetooth_device_address_t address = { {0} };
2919 __bt_service_get_parameters(in_param1,
2920 &address, sizeof(bluetooth_device_address_t));
2921 result = _bt_gatt_disable_data_batching(&address);
2926 case BT_GATT_GET_PRIMARY_SERVICES: {
2929 sender = (char*)g_dbus_method_invocation_get_sender(context);
2930 bluetooth_device_address_t address = { {0} };
2932 __bt_service_get_parameters(in_param1, &address,
2933 sizeof(bluetooth_device_address_t));
2935 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
2936 _bt_convert_addr_type_to_string(addr, address.addr);
2938 result = _bt_gatt_get_primary_services(addr);
2939 if (BLUETOOTH_ERROR_NONE == result) {
2940 _bt_save_invocation_context(context, result, sender,
2941 function_name, (gpointer)addr);
2947 case BT_GATT_GET_SERVICE_PROPERTIES: {
2948 bluetooth_gatt_client_svc_prop_info_t param;
2950 sender = (char*)g_dbus_method_invocation_get_sender(context);
2951 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_svc_prop_info_t));
2953 __bt_service_get_parameters(in_param1, ¶m,
2954 sizeof(bluetooth_gatt_client_svc_prop_info_t));
2956 result = _bt_gatt_get_all_characteristic(¶m);
2957 if (BLUETOOTH_ERROR_NONE == result) {
2958 /* Save the informations to invocation */
2959 _bt_save_invocation_context(context, result, sender,
2961 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_svc_prop_info_t)));
2965 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: {
2966 bluetooth_gatt_client_char_prop_info_t param;
2968 sender = (char*)g_dbus_method_invocation_get_sender(context);
2969 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
2971 __bt_service_get_parameters(in_param1, ¶m,
2972 sizeof(bluetooth_gatt_client_char_prop_info_t));
2974 result = _bt_gatt_get_all_characteristic_properties(¶m);
2975 if (BLUETOOTH_ERROR_NONE == result) {
2976 /* Save the informations to invocation */
2977 _bt_save_invocation_context(context, result, sender,
2979 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
2983 /* Async: Remote Interaction */
2984 case BT_GATT_READ_CHARACTERISTIC: {
2985 bluetooth_gatt_client_char_prop_info_t param;
2987 sender = (char*)g_dbus_method_invocation_get_sender(context);
2988 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
2990 __bt_service_get_parameters(in_param1, ¶m,
2991 sizeof(bluetooth_gatt_client_char_prop_info_t));
2993 result = _bt_gatt_read_characteristic_value(¶m);
2994 if (BLUETOOTH_ERROR_NONE == result) {
2995 /* Save the informations to invocation */
2996 _bt_save_invocation_context(context, result, sender,
2998 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3002 /* Async: Remote Interaction */
3003 case BT_GATT_READ_DESCRIPTOR_VALUE: {
3004 bluetooth_gatt_client_desc_prop_info_t param;
3006 sender = (char*)g_dbus_method_invocation_get_sender(context);
3007 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3009 __bt_service_get_parameters(in_param1, ¶m,
3010 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3012 result = _bt_gatt_read_descriptor_value(¶m);
3013 if (BLUETOOTH_ERROR_NONE == result) {
3014 /* Save the informations to invocation */
3015 _bt_save_invocation_context(context, result, sender,
3017 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3021 /* Async: Remote Interaction */
3022 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: {
3023 bluetooth_gatt_client_char_prop_info_t param;
3024 bluetooth_gatt_att_data_t data;
3025 bluetooth_gatt_write_type_e write_type;
3027 sender = (char*)g_dbus_method_invocation_get_sender(context);
3029 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3030 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3032 __bt_service_get_parameters(in_param1, ¶m,
3033 sizeof(bluetooth_gatt_client_char_prop_info_t));
3034 __bt_service_get_parameters(in_param2, &data,
3035 sizeof(bluetooth_gatt_att_data_t));
3036 __bt_service_get_parameters(in_param3, &write_type,
3037 sizeof(bluetooth_gatt_write_type_e));
3039 result = _bt_gatt_write_characteristic_value_by_type(¶m , &data, write_type);
3040 if (BLUETOOTH_ERROR_NONE == result) {
3041 /* Save the informations to invocation */
3042 _bt_save_invocation_context(context, result, sender,
3044 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3048 /* Async: Remote Interaction */
3049 case BT_GATT_WRITE_DESCRIPTOR_VALUE: {
3050 bluetooth_gatt_client_desc_prop_info_t param;
3051 bluetooth_gatt_att_data_t data;
3052 bluetooth_gatt_write_type_e write_type;
3054 sender = (char*)g_dbus_method_invocation_get_sender(context);
3055 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3056 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3058 __bt_service_get_parameters(in_param1, ¶m,
3059 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3060 __bt_service_get_parameters(in_param2, &data,
3061 sizeof(bluetooth_gatt_att_data_t));
3062 __bt_service_get_parameters(in_param3, &write_type,
3063 sizeof(bluetooth_gatt_write_type_e));
3065 result = _bt_gatt_write_descriptor_value_by_type(¶m, &data, write_type);
3066 if (BLUETOOTH_ERROR_NONE == result) {
3067 /* Save the informations to invocation */
3068 _bt_save_invocation_context(context, result, sender,
3070 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3075 case BT_GATT_WATCH_CHARACTERISTIC: {
3076 bluetooth_gatt_client_char_prop_info_t param;
3081 gboolean is_indicate;
3084 memset(¶m, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3086 sender = (char*)g_dbus_method_invocation_get_sender(context);
3088 __bt_service_get_parameters(in_param1, ¶m,
3089 sizeof(bluetooth_gatt_client_char_prop_info_t));
3090 __bt_service_get_parameters(in_param2, &client_id,
3092 __bt_service_get_parameters(in_param3, &is_notify,
3094 __bt_service_get_parameters(in_param4, &is_indicate,
3097 #ifdef TIZEN_FEATURE_BT_GATT_CLIENT_FD_DISABLE
3101 if (is_indicate == false) {
3102 result = _bt_gatt_acquire_notify(¶m , &fd, &mtu);
3103 if (BLUETOOTH_ERROR_NONE == result && fd > -1) {
3104 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
3106 GUnixFDList *fd_list = NULL;
3107 GError *error = NULL;
3109 g_array_append_vals(*out_param1, &mtu, sizeof(int));
3110 /* Add socket fd to unix_fd_list */
3111 fd_list = g_unix_fd_list_new();
3112 g_unix_fd_list_append(fd_list, fd, &error);
3113 g_assert_no_error(error);
3115 _bt_service_method_return_with_unix_fd_list(
3116 context, *out_param1, result, fd_list);
3118 g_object_unref(fd_list);
3124 result = _bt_gatt_watch_characteristic(¶m , client_id, is_notify);
3125 if (BLUETOOTH_ERROR_NONE == result) {
3126 /* Save the informations to invocation */
3127 _bt_save_invocation_context(context, result, sender, function_name,
3128 (gpointer)g_memdup(¶m, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3133 case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: {
3134 gboolean is_enabled;
3135 bluetooth_device_address_t address;
3137 sender = (char*)g_dbus_method_invocation_get_sender(context);
3139 __bt_service_get_parameters(in_param1,
3140 &address, sizeof(bluetooth_device_address_t));
3141 __bt_service_get_parameters(in_param2, &is_enabled,
3143 result = _bt_gatt_watch_service_changed_indication(sender, &address, is_enabled);
3144 BT_INFO("Service changed indication from app [%s]", sender);
3148 case BT_LE_CONN_UPDATE: {
3149 char *sender = NULL;
3150 bluetooth_device_address_t local_address = { {0} };
3151 bluetooth_le_connection_param_t parameters = {0};
3153 sender = (char *)g_dbus_method_invocation_get_sender(context);
3155 __bt_service_get_parameters(in_param1, &local_address,
3156 sizeof(bluetooth_device_address_t));
3157 __bt_service_get_parameters(in_param2, ¶meters,
3158 sizeof(bluetooth_le_connection_param_t));
3160 result = _bt_le_connection_update(sender,
3162 parameters.interval_min,
3163 parameters.interval_max,
3165 parameters.timeout);
3168 case BT_START_LE_DISCOVERY: {
3172 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3174 sender = (char *)g_dbus_method_invocation_get_sender(context);
3176 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3177 BT_ERR("Fail to get the sender pid");
3179 result = _bt_start_le_scan(sender, uid, pid);
3180 if (result == BLUETOOTH_ERROR_NONE) {
3181 _bt_save_invocation_context(context, result, sender,
3182 function_name, NULL);
3184 BT_DBG("Remeber pid / uid for the scan operation");
3185 _bt_bm_add_scan_app(SCAN_LE, uid, pid);
3189 case BT_STOP_LE_DISCOVERY: {
3193 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3195 sender = (char *)g_dbus_method_invocation_get_sender(context);
3197 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3198 BT_ERR("Fail to get the sender pid");
3200 result = _bt_stop_le_scan(sender);
3201 if (result == BLUETOOTH_ERROR_NONE) {
3202 _bt_save_invocation_context(context, result, sender,
3203 function_name, NULL);
3206 BT_DBG("Remove pid / uid for the scan operation");
3207 _bt_bm_remove_scan_app(SCAN_LE, uid, pid);
3211 case BT_IS_LE_DISCOVERYING: {
3212 gboolean le_discovering = FALSE;
3214 le_discovering = _bt_is_le_scanning();
3215 g_array_append_vals(*out_param1,
3216 &le_discovering, sizeof(gboolean));
3219 case BT_SET_SCAN_PARAMETERS: {
3220 bluetooth_le_scan_params_t scan_params;
3222 __bt_service_get_parameters(in_param1, &scan_params,
3223 sizeof(bluetooth_le_scan_params_t));
3225 BT_DBG("bluetooth_le_scan_params_t [%f %f %d]",
3226 scan_params.interval, scan_params.window,
3229 result = _bt_prepare_scan_parameters(&scan_params, 0);
3232 case BT_SET_SCAN_TYPE: {
3234 __bt_service_get_parameters(in_param1, &scan_type, sizeof(int));
3236 BT_DBG("bluetooth_le_scan_type [%d]", scan_type);
3237 result = _bt_prepare_scan_parameters(NULL, scan_type);
3240 #ifdef TIZEN_FEATURE_BT_PAN_NAP
3241 case BT_NETWORK_ACTIVATE:
3242 BT_DBG("BT_NETWORK_ACTIVATE Request recieved Request Handler ");
3243 result = _bt_network_activate();
3245 case BT_NETWORK_DEACTIVATE:
3246 result = _bt_network_deactivate();
3248 case BT_NETWORK_CONNECT: {
3249 bluetooth_device_address_t address = { {0} };
3252 __bt_service_get_parameters(in_param1,
3253 &address, sizeof(bluetooth_device_address_t));
3254 __bt_service_get_parameters(in_param2,
3255 &role, sizeof(int));
3257 result = _bt_network_connect(request_id, role, &address);
3258 if (result != BLUETOOTH_ERROR_NONE) {
3259 g_array_append_vals(*out_param1, &address,
3260 sizeof(bluetooth_device_address_t));
3264 case BT_NETWORK_DISCONNECT: {
3265 bluetooth_device_address_t address = { {0} };
3267 __bt_service_get_parameters(in_param1,
3268 &address, sizeof(bluetooth_device_address_t));
3270 result = _bt_network_disconnect(request_id, &address);
3271 if (result != BLUETOOTH_ERROR_NONE) {
3272 g_array_append_vals(*out_param1, &address,
3273 sizeof(bluetooth_device_address_t));
3277 case BT_NETWORK_SERVER_DISCONNECT: {
3278 bluetooth_device_address_t address = { {0} };
3280 __bt_service_get_parameters(in_param1,
3281 &address, sizeof(bluetooth_device_address_t));
3283 result = _bt_network_server_disconnect(request_id, &address);
3284 if (result != BLUETOOTH_ERROR_NONE) {
3285 g_array_append_vals(*out_param1, &address,
3286 sizeof(bluetooth_device_address_t));
3292 #ifdef TIZEN_FEATURE_BT_IPSP
3293 case BT_LE_IPSP_INIT:
3294 result = _bt_initialize_ipsp();
3296 case BT_LE_IPSP_DEINIT:
3297 result = _bt_deinitialize_ipsp();
3299 case BT_LE_IPSP_CONNECT: {
3300 bluetooth_device_address_t address = { {0} };
3301 __bt_service_get_parameters(in_param1, &address,
3302 sizeof(bluetooth_device_address_t));
3303 result = _bt_connect_le_ipsp_device(&address);
3306 case BT_LE_IPSP_DISCONNECT: {
3307 bluetooth_device_address_t address = { {0} };
3308 __bt_service_get_parameters(in_param1, &address,
3309 sizeof(bluetooth_device_address_t));
3310 result = _bt_disconnect_le_ipsp_device(&address);
3314 case BT_IS_ADVERTISING: {
3315 gboolean advertising = FALSE;
3316 advertising = _bt_is_advertising();
3317 g_array_append_vals(*out_param1, &advertising,
3321 case BT_IS_LE_2M_PHY_SUPPORTED: {
3322 gboolean is_2m_phy_supported = FALSE;
3324 is_2m_phy_supported = _bt_is_le_2m_phy_supported();
3325 g_array_append_vals(*out_param1, &is_2m_phy_supported, sizeof(gboolean));
3328 case BT_IS_LE_CODED_PHY_SUPPORTED: {
3329 gboolean is_coded_phy_supported = FALSE;
3331 is_coded_phy_supported = _bt_is_le_coded_phy_supported();
3332 g_array_append_vals(*out_param1, &is_coded_phy_supported, sizeof(gboolean));
3335 case BT_DISCONNECT_DEVICE: {
3336 bluetooth_device_address_t address = { {0} };
3338 __bt_service_get_parameters(in_param1,
3339 &address, sizeof(bluetooth_device_address_t));
3341 result = _bt_disconnect_device(&address);
3344 case BT_REGISTER_SCAN_FILTER: {
3345 bluetooth_le_scan_filter_t scan_filter;
3347 sender = (char*)g_dbus_method_invocation_get_sender(context);
3348 __bt_service_get_parameters(in_param1, &scan_filter,
3349 sizeof(bluetooth_le_scan_filter_t));
3351 BT_DBG("bluetooth_le_scan_filter_t [features : 0x%.2x]",
3352 scan_filter.added_features);
3354 result = _bt_register_scan_filter(sender, &scan_filter);
3359 case BT_TDS_PROVIDER_REGISTER: {
3360 char *sender = NULL;
3362 sender = (char *)g_dbus_method_invocation_get_sender(context);
3363 result = _bt_tds_provider_register(sender);
3368 case BT_TDS_PROVIDER_UNREGISTER: {
3369 char *sender = NULL;
3371 sender = (char *)g_dbus_method_invocation_get_sender(context);
3372 result = _bt_tds_provider_unregister(sender);
3377 case BT_TDS_PROVIDER_SET_MANUF_DATA: {
3378 char *sender = NULL;
3379 unsigned int length = 0;
3380 bluetooth_advertising_data_t manuf_data;
3382 __bt_service_get_parameters(in_param1,
3383 &length, sizeof(unsigned int));
3384 __bt_service_get_parameters(in_param2,
3385 &manuf_data, sizeof(bluetooth_advertising_data_t));
3386 sender = (char *)g_dbus_method_invocation_get_sender(context);
3388 result = _bt_tds_provider_set_manuf_data(sender, manuf_data.data, length);
3392 case BT_TDS_PROVIDER_CREATE: {
3393 char *sender = NULL;
3394 unsigned int tds_handle = 0;
3397 __bt_service_get_parameters(in_param1,
3398 &tds_handle, sizeof(unsigned int));
3399 __bt_service_get_parameters(in_param2,
3400 &transport, sizeof(int));
3401 sender = (char *)g_dbus_method_invocation_get_sender(context);
3402 result = _bt_tds_provider_transport_create(sender, transport, tds_handle);
3407 case BT_TDS_PROVIDER_DESTROY: {
3408 char *sender = NULL;
3409 unsigned int tds_handle = 0;
3411 __bt_service_get_parameters(in_param1,
3412 &tds_handle, sizeof(unsigned int));
3413 sender = (char *)g_dbus_method_invocation_get_sender(context);
3414 result = _bt_tds_provider_transport_remove(sender, tds_handle);
3419 case BT_TDS_PROVIDER_SET_TRANSPORT_DATA: {
3420 char *sender = NULL;
3421 unsigned int tds_handle = 0;
3422 int transport_state = 0;
3423 bluetooth_tds_data_t tds_data;
3425 __bt_service_get_parameters(in_param1,
3426 &tds_handle, sizeof(unsigned int));
3427 __bt_service_get_parameters(in_param2,
3428 &transport_state, sizeof(int));
3429 __bt_service_get_parameters(in_param3,
3430 &tds_data, sizeof(bluetooth_tds_data_t));
3431 sender = (char *)g_dbus_method_invocation_get_sender(context);
3433 result = _bt_tds_provider_set_transport_data(sender, tds_handle,
3434 transport_state, tds_data.data, tds_data.length);
3438 case BT_TDS_SEND_ACTIVATION_RESPONSE: {
3439 bluetooth_device_address_t address = { {0} };
3440 bluetooth_tds_data_t tds_data;
3441 char *sender = NULL;
3442 unsigned int tds_handle = 0;
3445 __bt_service_get_parameters(in_param1,
3446 &tds_handle, sizeof(unsigned int));
3447 __bt_service_get_parameters(in_param2,
3448 &response, sizeof(int));
3449 __bt_service_get_parameters(in_param3, &address,
3450 sizeof(bluetooth_device_address_t));
3451 __bt_service_get_parameters(in_param4,
3452 &tds_data, sizeof(bluetooth_tds_data_t));
3453 sender = (char *)g_dbus_method_invocation_get_sender(context);
3455 result = _bt_tds_provider_send_activation_response(sender, tds_handle,
3456 &address, response, tds_data.data, tds_data.length);
3461 sender = (char*)g_dbus_method_invocation_get_sender(context);
3462 BT_INFO("Mesh: Init by [%s]", sender);
3463 result = _bt_mesh_init(sender);
3464 /* Save invocation */
3465 if (result == BLUETOOTH_ERROR_NONE) {
3466 BT_INFO("Mesh: Save Invoation");
3467 sender = (char*)g_dbus_method_invocation_get_sender(context);
3468 _bt_save_invocation_context(context,
3470 function_name, NULL);
3474 case BT_MESH_DEINIT:
3475 sender = (char*)g_dbus_method_invocation_get_sender(context);
3476 BT_INFO("Mesh: De-Init by [%s]", sender);
3477 result = _bt_mesh_deinit(sender);
3480 case BT_MESH_NETWORK_CREATE: {
3481 bluetooth_mesh_node_t node;
3482 GSList *model_list = NULL;
3483 int total_models = 0;
3486 const char *network_name = NULL;
3487 bluetooth_mesh_network_t *network;
3489 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
3490 sender = (char*)g_dbus_method_invocation_get_sender(context);
3492 __bt_service_get_parameters(in_param1,
3493 &node, sizeof(bluetooth_mesh_node_t));
3494 network_name = (const char *)g_variant_get_data(in_param2);
3496 BT_INFO("MESH: Network name [%s]", network_name);
3498 param3 = g_array_new(TRUE, TRUE, sizeof(gchar));
3499 __bt_fill_garray_from_variant(in_param3, param3);
3501 total_models = (param3->len) / sizeof(bluetooth_mesh_model_t);
3502 for (i = 0; i < total_models; i++) {
3503 bluetooth_mesh_model_t *info = NULL;
3504 bluetooth_mesh_model_t *mod = NULL;
3506 info = &g_array_index(param3,
3507 bluetooth_mesh_model_t, i);
3509 mod = g_memdup(info, sizeof(bluetooth_mesh_model_t));
3512 model_list = g_slist_append(model_list,
3515 result = _bt_mesh_network_create(requester_unique_creds,
3516 sender, network_name, &node, model_list);
3518 /* Save invocation */
3519 if (result == BLUETOOTH_ERROR_NONE) {
3520 BT_INFO("Mesh: Save Invoation");
3521 network = g_malloc0(sizeof(bluetooth_mesh_network_t));
3523 /* Save Network name & UUID, Token will be received in event */
3524 _bt_mesh_util_convert_hex_to_string(
3525 (uint8_t *) node.uuid, 16,
3527 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
3528 BT_INFO("Mesh: Mesh Netwok UUID [%s]", network->uuid);
3529 g_strlcpy(network->name.name, network_name,
3530 sizeof(network->name.name));
3531 g_strlcpy(network->app_cred,
3532 requester_unique_creds,
3533 sizeof(network->app_cred));
3534 sender = (char*)g_dbus_method_invocation_get_sender(context);
3535 BT_INFO("Mesh: Network Create by [%s]", sender);
3536 _bt_save_invocation_context(context,
3538 function_name, (gpointer)network);
3540 g_array_append_vals(*out_param1, &node, sizeof(bluetooth_mesh_node_t));
3541 BT_ERR("Mesh: Mesh Network creation schedule failed");
3542 g_slist_free_full(model_list, g_free);
3546 BT_INFO("Mesh: Cleanup");
3547 g_free((gpointer)requester_unique_creds);
3548 g_array_free(param3, TRUE);
3549 BT_INFO("Mesh: Cleanup Done");
3552 case BT_MESH_NETWORK_DESTROY: {
3553 bluetooth_mesh_network_t network;
3554 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3556 __bt_service_get_parameters(in_param1,
3557 &network, sizeof(bluetooth_mesh_network_t));
3559 BT_INFO("Mesh: Destroy Network");
3560 result = _bt_mesh_network_destroy(requester_unique_creds,
3563 if (result != BLUETOOTH_ERROR_NONE) {
3564 g_array_append_vals(*out_param1,
3565 &network, sizeof(bluetooth_mesh_network_t));
3567 BT_INFO("Mesh: Destroy Network scheduled: add invocation");
3568 bluetooth_mesh_network_t *net = \
3569 g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3571 sender = (char*)g_dbus_method_invocation_get_sender(context);
3572 _bt_save_invocation_context(context, result, sender,
3573 function_name, (gpointer)net);
3577 case BT_MESH_NETWORK_LOAD: {
3579 bluetooth_mesh_network_t *network;
3580 token = (char *)g_variant_get_data(in_param1);
3581 BT_INFO("MESH: Network Load: Token string [%s]", token);
3582 result = _bt_mesh_network_load(requester_unique_creds, sender, token);
3583 /* Save invocation */
3584 if (result == BLUETOOTH_ERROR_NONE) {
3585 network = g_malloc0(sizeof(bluetooth_mesh_network_t));
3586 g_strlcpy(network->token.token, token,
3587 BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
3588 g_strlcpy(network->app_cred, requester_unique_creds,
3589 sizeof(network->app_cred));
3591 sender = (char*)g_dbus_method_invocation_get_sender(context);
3592 _bt_save_invocation_context(context, result, sender,
3593 function_name, (gpointer)network);
3595 g_free((gpointer)requester_unique_creds);
3598 case BT_MESH_NETWORK_UNLOAD: {
3599 bluetooth_mesh_network_t network;
3600 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3602 __bt_service_get_parameters(in_param1,
3603 &network, sizeof(bluetooth_mesh_network_t));
3605 BT_INFO("MESH: Network Unload: Network UUID [%s]", network.uuid);
3606 result = _bt_mesh_network_unload(requester_unique_creds,
3610 case BT_MESH_NETWORK_SCAN: {
3611 bluetooth_mesh_network_t network;
3612 bluetooth_mesh_scan_param_t param;
3613 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3614 memset(¶m, 0x00, sizeof(bluetooth_mesh_scan_param_t));
3616 __bt_service_get_parameters(in_param1,
3617 &network, sizeof(bluetooth_mesh_network_t));
3619 __bt_service_get_parameters(in_param2,
3620 ¶m, sizeof(bluetooth_mesh_scan_param_t));
3622 result = _bt_mesh_network_scan(requester_unique_creds,
3623 sender, &network, ¶m);
3625 if (result != BLUETOOTH_ERROR_NONE) {
3626 g_array_append_vals(*out_param1,
3627 &network, sizeof(bluetooth_mesh_network_t));
3629 bluetooth_mesh_network_t *net = \
3630 g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3632 sender = (char*)g_dbus_method_invocation_get_sender(context);
3633 _bt_save_invocation_context(context, result, sender,
3634 function_name, (gpointer)net);
3638 case BT_MESH_NETWORK_CANCEL_SCAN: {
3639 bluetooth_mesh_network_t network;
3640 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3642 __bt_service_get_parameters(in_param1,
3643 &network, sizeof(bluetooth_mesh_network_t));
3645 result = _bt_mesh_network_scan_cancel(requester_unique_creds,
3648 if (result != BLUETOOTH_ERROR_NONE)
3649 g_array_append_vals(*out_param1,
3650 &network, sizeof(bluetooth_mesh_network_t));
3653 case BT_MESH_NETWORK_SET_CAPABILITIES: {
3654 bluetooth_mesh_network_t network;
3655 bluetooth_mesh_provisioner_caps_t caps;
3656 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3657 memset(&caps, 0x00, sizeof(bluetooth_mesh_provisioner_caps_t));
3659 __bt_service_get_parameters(in_param1,
3660 &network, sizeof(bluetooth_mesh_network_t));
3662 __bt_service_get_parameters(in_param2,
3663 &caps, sizeof(bluetooth_mesh_provisioner_caps_t));
3665 result = _bt_mesh_network_set_provisioner_caps(
3666 requester_unique_creds, sender, &network, &caps);
3670 case BT_MESH_NETWORK_PROVISION_DEVICE: {
3671 bluetooth_mesh_provisioning_request_t req;
3672 memset(&req, 0x00, sizeof(bluetooth_mesh_provisioning_request_t));
3674 __bt_service_get_parameters(in_param1,
3675 &req, sizeof(bluetooth_mesh_provisioning_request_t));
3677 BT_INFO("Mesh: Provision Device UUID [%s]", req.dev_uuid);
3678 BT_INFO("Mesh: Provision Device in network[%s]", req.net_uuid);
3680 result = _bt_mesh_network_provision_device(
3681 requester_unique_creds, sender, &req);
3683 /* Save invocation */
3684 if (result != BLUETOOTH_ERROR_NONE) {
3685 g_array_append_vals(*out_param1, &req,
3686 sizeof(bluetooth_mesh_provisioning_request_t));
3688 bluetooth_mesh_provisioning_request_t *param = \
3689 g_memdup(&req, sizeof(bluetooth_mesh_provisioning_request_t));
3691 sender = (char*)g_dbus_method_invocation_get_sender(context);
3692 _bt_save_invocation_context(context, result, sender,
3693 function_name, (gpointer)param);
3697 case BT_MESH_AUTHENTICATION_REPLY: {
3698 BT_INFO("Mesh: BT_MESH_AUTHENTICATION_REPLY");
3699 const char *auth_value = NULL;
3700 gboolean authentication_reply = FALSE;
3702 auth_value = g_variant_get_data(in_param2);
3703 __bt_service_get_parameters(in_param3,
3704 &authentication_reply, sizeof(gboolean));
3705 __bt_service_get_parameters(in_param1,
3706 &auth_type, sizeof(int));
3707 BT_INFO("Mesh: Auth Reply Type [%d]", auth_type);
3708 BT_INFO("Mesh: Auth Value [%s]", auth_value);
3709 BT_INFO("Mesh: Auth Accept [%d]", authentication_reply);
3710 result = _bt_mesh_authentication_reply(auth_type,
3711 auth_value, authentication_reply);
3714 case BT_MESH_NETWORK_SET_NAME: {
3715 bluetooth_mesh_network_t network;
3716 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3718 __bt_service_get_parameters(in_param1,
3719 &network, sizeof(bluetooth_mesh_network_t));
3721 result = _bt_mesh_network_set_name(requester_unique_creds, sender, &network);
3725 case BT_MESH_NETWORK_ADD_NETKEY: {
3726 bluetooth_mesh_network_t network;
3727 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3729 __bt_service_get_parameters(in_param1,
3730 &network, sizeof(bluetooth_mesh_network_t));
3732 result = _bt_mesh_network_add_netkey(requester_unique_creds,
3735 if (result != BLUETOOTH_ERROR_NONE) {
3736 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3738 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3740 sender = (char*)g_dbus_method_invocation_get_sender(context);
3741 _bt_save_invocation_context(context, result, sender,
3742 function_name, (gpointer)net);
3746 case BT_MESH_NETWORK_DELETE_NETKEY: {
3747 bluetooth_mesh_network_t network;
3750 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3752 __bt_service_get_parameters(in_param1,
3753 &network, sizeof(bluetooth_mesh_network_t));
3754 __bt_service_get_parameters(in_param2,
3755 &index, sizeof(guint16));
3757 result = _bt_mesh_network_delete_netkey(requester_unique_creds,
3758 sender, &network, index);
3760 if (result != BLUETOOTH_ERROR_NONE) {
3761 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3763 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3765 sender = (char*)g_dbus_method_invocation_get_sender(context);
3766 _bt_save_invocation_context(context, result, sender,
3767 function_name, (gpointer)net);
3771 case BT_MESH_NETWORK_UPDATE_NETKEY: {
3772 bluetooth_mesh_network_t network;
3775 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3777 __bt_service_get_parameters(in_param1,
3778 &network, sizeof(bluetooth_mesh_network_t));
3779 __bt_service_get_parameters(in_param2,
3780 &index, sizeof(guint16));
3782 result = _bt_mesh_network_update_netkey(requester_unique_creds,
3783 sender, &network, index);
3785 if (result != BLUETOOTH_ERROR_NONE) {
3786 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3788 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3790 sender = (char*)g_dbus_method_invocation_get_sender(context);
3791 _bt_save_invocation_context(context, result, sender,
3792 function_name, (gpointer)net);
3796 case BT_MESH_NETWORK_ADD_APPKEY: {
3797 bluetooth_mesh_network_t network;
3800 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3802 __bt_service_get_parameters(in_param1,
3803 &network, sizeof(bluetooth_mesh_network_t));
3804 __bt_service_get_parameters(in_param2,
3805 &net_idx, sizeof(guint16));
3807 result = _bt_mesh_network_add_appkey(requester_unique_creds,
3808 sender, &network, net_idx);
3810 if (result != BLUETOOTH_ERROR_NONE) {
3811 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3813 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3815 sender = (char*)g_dbus_method_invocation_get_sender(context);
3816 _bt_save_invocation_context(context, result, sender,
3817 function_name, (gpointer)net);
3821 case BT_MESH_NETWORK_UPDATE_APPKEY: {
3822 bluetooth_mesh_network_t network;
3826 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3828 __bt_service_get_parameters(in_param1,
3829 &network, sizeof(bluetooth_mesh_network_t));
3830 __bt_service_get_parameters(in_param2,
3831 &net_idx, sizeof(guint16));
3832 __bt_service_get_parameters(in_param3,
3833 &app_idx, sizeof(guint16));
3835 result = _bt_mesh_network_update_appkey(requester_unique_creds,
3836 sender, &network, net_idx, app_idx);
3838 if (result != BLUETOOTH_ERROR_NONE) {
3839 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3841 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3843 sender = (char*)g_dbus_method_invocation_get_sender(context);
3844 _bt_save_invocation_context(context, result, sender,
3845 function_name, (gpointer)net);
3849 case BT_MESH_NETWORK_DELETE_APPKEY: {
3850 bluetooth_mesh_network_t network;
3854 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3856 __bt_service_get_parameters(in_param1,
3857 &network, sizeof(bluetooth_mesh_network_t));
3858 __bt_service_get_parameters(in_param2,
3859 &net_idx, sizeof(guint16));
3860 __bt_service_get_parameters(in_param3,
3861 &app_idx, sizeof(guint16));
3863 result = _bt_mesh_network_delete_appkey(requester_unique_creds,
3864 sender, &network, net_idx, app_idx);
3866 if (result != BLUETOOTH_ERROR_NONE) {
3867 g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3869 bluetooth_mesh_network_t *net = g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3871 sender = (char*)g_dbus_method_invocation_get_sender(context);
3872 _bt_save_invocation_context(context, result, sender,
3873 function_name, (gpointer)net);
3877 case BT_MESH_NETWORK_GET_NETKEYS: {
3878 bluetooth_mesh_network_t network;
3879 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3880 __bt_service_get_parameters(in_param1,
3881 &network, sizeof(bluetooth_mesh_network_t));
3882 result = _bt_mesh_network_get_netkeys(requester_unique_creds,
3883 sender, &network, out_param1);
3886 case BT_MESH_NETWORK_GET_APPKEYS: {
3887 bluetooth_mesh_network_t network;
3890 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3891 __bt_service_get_parameters(in_param1,
3892 &network, sizeof(bluetooth_mesh_network_t));
3893 __bt_service_get_parameters(in_param2,
3894 &net_idx, sizeof(guint16));
3895 result = _bt_mesh_network_get_appkeys(
3896 requester_unique_creds, sender,
3897 &network, net_idx, out_param1);
3900 case BT_MESH_NETWORK_GET_NODES: {
3901 bluetooth_mesh_network_t network;
3902 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3903 __bt_service_get_parameters(in_param1,
3904 &network, sizeof(bluetooth_mesh_network_t));
3905 result = _bt_mesh_network_get_nodes(
3906 requester_unique_creds, sender,
3907 &network, out_param1);
3910 case BT_MESH_ELEMENT_GET_MODELS: {
3911 bluetooth_mesh_network_t network;
3915 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3916 __bt_service_get_parameters(in_param1,
3917 &network, sizeof(bluetooth_mesh_network_t));
3918 __bt_service_get_parameters(in_param2,
3919 &node_addr, sizeof(guint16));
3920 __bt_service_get_parameters(in_param3,
3921 &elem_idx, sizeof(int));
3922 result = _bt_mesh_element_get_models(requester_unique_creds, sender,
3923 &network, node_addr, elem_idx, out_param1);
3926 case BT_MESH_NODE_BROWSE: {
3927 bluetooth_mesh_node_discover_t req;
3928 memset(&req, 0x00, sizeof(bluetooth_mesh_node_discover_t));
3930 __bt_service_get_parameters(in_param1,
3931 &req, sizeof(bluetooth_mesh_node_discover_t));
3933 result = _bt_mesh_browse_remote_node(
3934 requester_unique_creds, sender, &req);
3936 /* Save invocation */
3937 if (result != BLUETOOTH_ERROR_NONE) {
3938 g_array_append_vals(*out_param1, &req,
3939 sizeof(bluetooth_mesh_node_discover_t));
3941 bluetooth_mesh_node_discover_t *param = \
3942 g_memdup(&req, sizeof(bluetooth_mesh_node_discover_t));
3944 sender = (char*)g_dbus_method_invocation_get_sender(context);
3945 _bt_save_invocation_context(context, result, sender,
3946 function_name, (gpointer)param);
3950 case BT_MESH_NODE_GET_VENDOR_FEATURES: {
3951 bluetooth_mesh_node_features_t req;
3952 memset(&req, 0x00, sizeof(bluetooth_mesh_node_features_t));
3954 __bt_service_get_parameters(in_param1,
3955 &req, sizeof(bluetooth_mesh_node_features_t));
3957 result = _bt_mesh_node_discover_vendor_features(
3958 requester_unique_creds, sender, &req);
3960 /* Save invocation */
3961 if (result != BLUETOOTH_ERROR_NONE) {
3962 g_array_append_vals(*out_param1,
3963 &req, sizeof(bluetooth_mesh_node_features_t));
3965 bluetooth_mesh_node_features_t *param = \
3966 g_memdup(&req, sizeof(bluetooth_mesh_node_features_t));
3968 sender = (char*)g_dbus_method_invocation_get_sender(context);
3969 _bt_save_invocation_context(context, result, sender,
3970 function_name, (gpointer)param);
3974 case BT_MESH_NODE_CONFIGURE_KEY: {
3975 bluetooth_mesh_key_configure_t req;
3977 memset(&req, 0x00, sizeof(bluetooth_mesh_key_configure_t));
3979 __bt_service_get_parameters(in_param1,
3980 &req, sizeof(bluetooth_mesh_key_configure_t));
3982 result = _bt_mesh_node_configure_key(
3983 requester_unique_creds, sender, &req);
3985 /* Save invocation */
3986 if (result != BLUETOOTH_ERROR_NONE) {
3987 g_array_append_vals(*out_param1,
3988 &req, sizeof(bluetooth_mesh_key_configure_t));
3990 bluetooth_mesh_key_configure_t *param = \
3991 g_memdup(&req, sizeof(bluetooth_mesh_key_configure_t));
3993 sender = (char*)g_dbus_method_invocation_get_sender(context);
3994 _bt_save_invocation_context(context, result, sender,
3995 function_name, (gpointer)param);
3999 case BT_MESH_NODE_TTL_EXECUTE: {
4000 bluetooth_mesh_node_ttl_info_t req;
4002 memset(&req, 0x00, sizeof(bluetooth_mesh_node_ttl_info_t));
4004 __bt_service_get_parameters(in_param1,
4005 &req, sizeof(bluetooth_mesh_node_ttl_info_t));
4007 result = _bt_mesh_ttl_execute_remote_node(
4008 requester_unique_creds, sender, &req);
4010 /* Save invocation */
4011 if (result != BLUETOOTH_ERROR_NONE) {
4012 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_node_ttl_info_t));
4014 bluetooth_mesh_node_ttl_info_t *param = \
4015 g_memdup(&req, sizeof(bluetooth_mesh_node_ttl_info_t));
4017 sender = (char*)g_dbus_method_invocation_get_sender(context);
4018 _bt_save_invocation_context(context, result, sender,
4019 function_name, (gpointer)param);
4023 case BT_MESH_MODEL_CONFIGURE_APPKEY: {
4024 bluetooth_mesh_model_configure_t req;
4026 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4028 __bt_service_get_parameters(in_param1,
4029 &req, sizeof(bluetooth_mesh_model_configure_t));
4031 result = _bt_mesh_node_model_appkey_execute(
4032 requester_unique_creds, sender, &req);
4034 /* Save invocation */
4035 if (result != BLUETOOTH_ERROR_NONE) {
4036 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4038 bluetooth_mesh_model_configure_t *param = \
4039 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4041 sender = (char*)g_dbus_method_invocation_get_sender(context);
4042 _bt_save_invocation_context(context, result, sender,
4043 function_name, (gpointer)param);
4047 case BT_MESH_MODEL_EXECUTE_MSG: {
4048 bluetooth_mesh_model_msg_t req;
4050 memset(&req, 0x00, sizeof(bluetooth_mesh_model_msg_t));
4052 __bt_service_get_parameters(in_param1,
4053 &req, sizeof(bluetooth_mesh_model_msg_t));
4055 result = _bt_mesh_model_execute_msg(
4056 requester_unique_creds, sender, &req);
4058 /* Save invocation */
4059 if (result != BLUETOOTH_ERROR_NONE) {
4060 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_msg_t));
4062 bluetooth_mesh_model_msg_t *param = \
4063 g_memdup(&req, sizeof(bluetooth_mesh_model_msg_t));
4065 sender = (char*)g_dbus_method_invocation_get_sender(context);
4066 _bt_save_invocation_context(context, result, sender,
4067 function_name, (gpointer)param);
4071 case BT_MESH_NODE_GET_NETKEYS: {
4072 bluetooth_mesh_node_discover_t node;
4073 memset(&node, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4074 __bt_service_get_parameters(in_param1,
4075 &node, sizeof(bluetooth_mesh_node_discover_t));
4076 result = _bt_mesh_network_node_get_netkeys(
4077 requester_unique_creds, &node, out_param1);
4080 case BT_MESH_NODE_GET_APPKEYS: {
4081 bluetooth_mesh_node_discover_t node;
4082 memset(&node, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4083 __bt_service_get_parameters(in_param1,
4084 &node, sizeof(bluetooth_mesh_node_discover_t));
4085 result = _bt_mesh_network_node_get_appkeys(
4086 requester_unique_creds, sender, &node, out_param1);
4089 case BT_MESH_NODE_RESET: {
4090 bluetooth_mesh_node_info_t node;
4091 memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t));
4093 __bt_service_get_parameters(in_param1,
4094 &node, sizeof(bluetooth_mesh_node_info_t));
4096 BT_INFO("Mesh: Reset the Node");
4097 result = _bt_mesh_network_reset_node(requester_unique_creds,
4102 case BT_MESH_MODEL_GET_APPKEY_LIST: {
4103 bluetooth_mesh_model_configure_t req;
4105 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4107 __bt_service_get_parameters(in_param1,
4108 &req, sizeof(bluetooth_mesh_model_configure_t));
4110 result = _bt_mesh_node_model_get_appkey_list(
4111 requester_unique_creds, sender, &req);
4113 /* Save invocation */
4114 if (result != BLUETOOTH_ERROR_NONE) {
4115 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4117 bluetooth_mesh_model_configure_t *param = \
4118 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4120 sender = (char*)g_dbus_method_invocation_get_sender(context);
4121 _bt_save_invocation_context(context, result, sender,
4122 function_name, (gpointer)param);
4126 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST: {
4127 bluetooth_mesh_model_configure_t req;
4129 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4131 __bt_service_get_parameters(in_param1,
4132 &req, sizeof(bluetooth_mesh_model_configure_t));
4134 result = _bt_mesh_node_model_get_subscription_list(
4135 requester_unique_creds, sender, &req);
4137 /* Save invocation */
4138 if (result != BLUETOOTH_ERROR_NONE) {
4139 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4141 bluetooth_mesh_model_configure_t *param = \
4142 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4144 sender = (char*)g_dbus_method_invocation_get_sender(context);
4145 _bt_save_invocation_context(context, result, sender,
4146 function_name, (gpointer)param);
4151 case BT_MESH_NETWORK_CREATE_GROUP: {
4152 bluetooth_mesh_network_t net;
4153 bluetooth_mesh_network_group_info_t res;
4154 gboolean is_virtual;
4157 memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
4158 memset(&res, 0x00, sizeof(bluetooth_mesh_network_group_info_t));
4160 __bt_service_get_parameters(in_param1,
4161 &net, sizeof(bluetooth_mesh_network_t));
4162 __bt_service_get_parameters(in_param2,
4163 &is_virtual, sizeof(gboolean));
4164 __bt_service_get_parameters(in_param3,
4165 &grp_addr, sizeof(guint16));
4167 result = _bt_mesh_network_create_group(
4168 requester_unique_creds, sender, &net,
4169 is_virtual, grp_addr, &res);
4171 if (result == BLUETOOTH_ERROR_NONE)
4172 g_array_append_vals(*out_param1, &res,
4173 sizeof(bluetooth_mesh_network_group_info_t));
4176 case BT_MESH_NETWORK_REMOVE_GROUP: {
4177 bluetooth_mesh_network_t net;
4178 bluetooth_mesh_network_group_info_t req;
4180 memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
4181 memset(&req, 0x00, sizeof(bluetooth_mesh_network_group_info_t));
4183 __bt_service_get_parameters(in_param1,
4184 &net, sizeof(bluetooth_mesh_network_t));
4185 __bt_service_get_parameters(in_param2,
4186 &req, sizeof(bluetooth_mesh_network_group_info_t));
4188 result = _bt_mesh_network_remove_group(
4189 requester_unique_creds, sender, &net, &req);
4193 case BT_MESH_MODEL_CONFIG_GROUP_SUB: {
4194 bluetooth_mesh_model_configure_t req;
4196 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4198 __bt_service_get_parameters(in_param1,
4199 &req, sizeof(bluetooth_mesh_model_configure_t));
4201 result = _bt_mesh_model_configure_group_subscription(
4202 requester_unique_creds, sender, &req);
4204 /* Save invocation */
4205 if (result != BLUETOOTH_ERROR_NONE) {
4206 g_array_append_vals(*out_param1,
4207 &req, sizeof(bluetooth_mesh_model_configure_t));
4209 bluetooth_mesh_model_configure_t *param = \
4210 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4212 sender = (char*)g_dbus_method_invocation_get_sender(context);
4213 _bt_save_invocation_context(context, result, sender,
4214 function_name, (gpointer)param);
4218 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB: {
4219 bluetooth_mesh_model_configure_t req;
4221 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4223 __bt_service_get_parameters(in_param1,
4224 &req, sizeof(bluetooth_mesh_model_configure_t));
4226 result = _bt_mesh_model_configure_virtual_group_subscription(
4227 requester_unique_creds, sender, &req);
4229 /* Save invocation */
4230 if (result != BLUETOOTH_ERROR_NONE) {
4231 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4233 bluetooth_mesh_model_configure_t *param = \
4234 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4236 sender = (char*)g_dbus_method_invocation_get_sender(context);
4237 _bt_save_invocation_context(context, result, sender,
4238 function_name, (gpointer)param);
4242 case BT_MESH_MODEL_SET_PUBLICATION: {
4243 bluetooth_mesh_model_configure_t req;
4245 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4247 __bt_service_get_parameters(in_param1,
4248 &req, sizeof(bluetooth_mesh_model_configure_t));
4250 result = _bt_mesh_model_set_publication(
4251 requester_unique_creds, sender, &req);
4253 /* Save invocation */
4254 if (result != BLUETOOTH_ERROR_NONE) {
4255 g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4257 bluetooth_mesh_model_configure_t *param = g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4259 sender = (char*)g_dbus_method_invocation_get_sender(context);
4260 _bt_save_invocation_context(context, result, sender,
4261 function_name, (gpointer)param);
4265 case BT_MESH_MODEL_GET_PUBLICATION: {
4266 bluetooth_mesh_model_configure_t req;
4268 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4270 __bt_service_get_parameters(in_param1,
4271 &req, sizeof(bluetooth_mesh_model_configure_t));
4273 result = _bt_mesh_model_get_publication(
4274 requester_unique_creds, sender, &req);
4276 /* Save invocation */
4277 if (result != BLUETOOTH_ERROR_NONE) {
4278 g_array_append_vals(*out_param1,
4279 &req, sizeof(bluetooth_mesh_model_configure_t));
4281 bluetooth_mesh_model_configure_t *param = \
4282 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4284 sender = (char*)g_dbus_method_invocation_get_sender(context);
4285 _bt_save_invocation_context(context, result, sender,
4286 function_name, (gpointer)param);
4290 case BT_MESH_NETWORK_GET_GROUPS: {
4291 bluetooth_mesh_network_t network;
4292 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4293 __bt_service_get_parameters(in_param1,
4294 &network, sizeof(bluetooth_mesh_network_t));
4295 BT_INFO("Mesh: Request:: Get Groups");
4296 result = _bt_mesh_network_get_groups(
4297 requester_unique_creds, sender, &network, out_param1);
4301 BT_INFO("UnSupported function [%d]", function_name);
4302 result = BLUETOOTH_ERROR_NOT_SUPPORT;
4308 #ifdef TIZEN_FEATURE_BT_OBEX
4309 /* Function definitions*/
4310 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
4315 size = g_variant_get_size(var);
4317 data = (char *)g_variant_get_data(var);
4319 param = g_array_append_vals(param, data, size);
4325 int __bt_obexd_request(int function_name,
4328 GDBusMethodInvocation *context,
4329 GVariant *in_param1,
4330 GVariant *in_param2,
4331 GVariant *in_param3,
4332 GVariant *in_param4,
4333 GArray **out_param1)
4337 int result = BLUETOOTH_ERROR_NONE;
4339 BT_DBG("function_name : %x", function_name);
4341 switch (function_name) {
4342 case BT_OPP_PUSH_FILES: {
4343 BT_DBG("BT_OPP_PUSH_FILES");
4345 bluetooth_device_address_t address = { {0} };
4346 bt_file_path_t *path;
4351 __bt_service_get_parameters(in_param1, &address,
4352 sizeof(bluetooth_device_address_t));
4353 __bt_service_get_parameters(in_param3, &file_count,
4356 file_path = g_new0(char *, file_count + 1);
4358 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
4359 __bt_fill_garray_from_variant(in_param2, param2);
4361 for (i = 0; i < file_count; i++) {
4362 path = &g_array_index(param2, bt_file_path_t, i);
4363 file_path[i] = g_strdup(path->path);
4365 BT_DBG("_bt_opp_client_push_files");
4366 result = _bt_opp_client_push_files(request_id, context,
4367 &address, file_path,
4370 for (i = 0; i < file_count; i++)
4371 g_free(file_path[i]);
4374 g_array_free(param2, TRUE);
4378 case BT_OPP_CANCEL_PUSH: {
4379 result = _bt_opp_client_cancel_push();
4383 case BT_OPP_IS_PUSHING_FILES: {
4384 gboolean is_sending = FALSE;
4386 result = _bt_opp_client_is_sending(&is_sending);
4388 g_array_append_vals(*out_param1, &is_sending,
4392 case BT_OPP_GET_TRANSFER_PROGRESS: {
4395 guint8 progress = 0;
4397 __bt_service_get_parameters(in_param1, &direction,
4399 __bt_service_get_parameters(in_param2, &transfer_id,
4402 result = _bt_opp_get_client_progress(&progress);
4404 result = _bt_opp_get_server_progress(transfer_id, &progress);
4406 g_array_append_vals(*out_param1, &progress,
4412 case BT_MAP_CREATE_SESSION: {
4413 BT_DBG("BT_MAP_CREATE_SESSION");
4414 char *address = (char *)g_variant_get_data(in_param1);
4415 char *session_id = NULL;
4416 result = _bt_create_session_sync(address, &session_id);
4417 if (result == BLUETOOTH_ERROR_NONE)
4418 g_array_append_vals(*out_param1, session_id, strlen(session_id)+1);
4422 case BT_MAP_DESTROY_SESSION: {
4423 BT_DBG("BT_MAP_DESTROY_SESSION");
4424 char* session_id = (char *)g_variant_get_data(in_param1);
4425 result = _bt_destroy_session_sync(session_id);
4426 if (result == BLUETOOTH_ERROR_NONE)
4427 BT_DBG("successfully destroyed session");
4431 case BT_MAP_SET_FOLDER: {
4432 BT_DBG("BT_MAP_SET_FOLDER");
4433 char *session_id = (char *)g_variant_get_data(in_param1);
4434 char *name = (char *)g_variant_get_data(in_param2);
4435 result = _bt_map_client_set_folder(session_id, name);
4439 case BT_MAP_LIST_FOLDERS: {
4440 BT_DBG("BT_MAP_LIST_FOLDERS");
4442 char* session_id = (char *)g_variant_get_data(in_param1);
4443 char* filter_serialized = (char*)g_variant_get_data(in_param2);
4445 result = _bt_map_client_list_folders(request_id, context, session_id, filter_serialized);
4446 if (result == BLUETOOTH_ERROR_NONE)
4447 BT_DBG("_bt_map_client_list_folders succeed");
4452 case BT_MAP_LIST_FILTER_FIELDS: {
4453 BT_DBG("BT_MAP_LIST_FILTER_FIELDS");
4455 char* session_id = (char *)g_variant_get_data(in_param1);
4457 result = _bt_map_client_list_filter_fields(request_id, context, session_id);
4458 if (result == BLUETOOTH_ERROR_NONE)
4459 BT_DBG("_bt_map_client_list_filter_fields succeed");
4464 case BT_MAP_LIST_MESSAGES: {
4465 BT_DBG("BT_MAP_LIST_MESSAGES");
4467 char* session_id = (char*)g_variant_get_data(in_param1);
4468 char* folder = (char*)g_variant_get_data(in_param2);
4469 char* filter_serialized = (char*)g_variant_get_data(in_param3);
4471 result = _bt_map_client_list_messages(request_id, context, session_id, folder, filter_serialized);
4472 if (result == BLUETOOTH_ERROR_NONE)
4473 BT_DBG("_bt_map_client_list_messages succeed");
4475 BT_DBG("_bt_map_client_list_messages failed");
4480 case BT_MAP_UPDATE_INBOX: {
4481 BT_DBG("BT_MAP_UPDATE_INBOX");
4482 char* session_id = (char *)g_variant_get_data(in_param1);
4483 result = _bt_map_client_update_inbox(session_id);
4487 case BT_MAP_PUSH_MESSAGE: {
4488 BT_DBG("BT_MAP_PUSH_MESSAGE");
4490 char* session_id = (char *)g_variant_get_data(in_param1);
4491 char* source_file = (char *)g_variant_get_data(in_param2);
4492 char* folder = (char *)g_variant_get_data(in_param3);
4493 char* args_serialized = (char *)g_variant_get_data(in_param4);
4495 result = _bt_map_client_push_message(
4496 request_id, context, session_id, source_file, folder, args_serialized);
4497 if (result == BLUETOOTH_ERROR_NONE)
4498 BT_DBG("_bt_map_client_push_message succeed");
4500 BT_ERR("_bt_map_client_push_message failed");
4505 case BT_MAP_GET_MESSAGE: {
4506 BT_DBG("BT_MAP_GET_MESSAGE");
4507 // TODO session currently is not used, but should be valid
4508 //char* session_id = (char *)g_variant_get_data(in_param1);
4509 char* message_object = (char *)g_variant_get_data(in_param2);
4510 char* target_file = (char *)g_variant_get_data(in_param3);
4511 bool attachment = false;
4512 __bt_service_get_parameters(in_param4, &attachment, sizeof(bool));
4514 result = _bt_map_client_get_message(request_id, context, message_object,
4515 target_file, attachment);
4516 if (result == BLUETOOTH_ERROR_NONE)
4517 BT_DBG("_bt_map_client_get_message succeed");
4522 case BT_OBEX_SERVER_ALLOCATE: {
4528 sender = (char *)g_dbus_method_invocation_get_sender(context);
4530 path = (char *)g_variant_get_data(in_param1);
4531 __bt_service_get_parameters(in_param2, &is_native,
4533 __bt_service_get_parameters(in_param3, &app_pid,
4536 result = _bt_obex_server_allocate(sender,
4537 path, app_pid, is_native);
4541 case BT_OBEX_SERVER_DEALLOCATE: {
4545 __bt_service_get_parameters(in_param1, &is_native,
4547 __bt_service_get_parameters(in_param2, &app_pid,
4550 result = _bt_obex_server_deallocate(app_pid, is_native);
4553 case BT_OBEX_SERVER_IS_ACTIVATED: {
4554 gboolean is_activated = FALSE;
4556 result = _bt_obex_server_is_activated(&is_activated);
4558 g_array_append_vals(*out_param1, &is_activated,
4563 case BT_OBEX_SERVER_ACCEPT_CONNECTION: {
4564 result = _bt_obex_server_accept_connection(request_id);
4568 case BT_OBEX_SERVER_REJECT_CONNECTION: {
4569 result = _bt_obex_server_reject_connection();
4573 case BT_OBEX_SERVER_ACCEPT_FILE: {
4576 file_name = (char *)g_variant_get_data(in_param1);
4578 result = _bt_obex_server_accept_authorize(file_name, TRUE);
4582 case BT_OBEX_SERVER_REJECT_FILE: {
4583 result = _bt_obex_server_reject_authorize();
4587 case BT_OBEX_SERVER_SET_PATH: {
4589 char *destination_path;
4591 destination_path = (char *)g_variant_get_data(in_param1);
4592 __bt_service_get_parameters(in_param2, &is_native,
4595 result = _bt_obex_server_set_destination_path(destination_path,
4600 case BT_OBEX_SERVER_SET_ROOT: {
4603 root = (char *)g_variant_get_data(in_param1);
4605 result = _bt_obex_server_set_root(root);
4609 case BT_OBEX_SERVER_CANCEL_TRANSFER: {
4612 __bt_service_get_parameters(in_param1, &transfer_id,
4615 result = _bt_obex_server_cancel_transfer(transfer_id);
4619 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS: {
4620 result = _bt_obex_server_cancel_all_transfers();
4624 case BT_OBEX_SERVER_IS_RECEIVING: {
4625 gboolean is_receiving = FALSE;
4627 result = _bt_obex_server_is_receiving(&is_receiving);
4629 g_array_append_vals(*out_param1, &is_receiving,
4633 case BT_PBAP_CONNECT: {
4634 bluetooth_device_address_t address = { {0} };
4636 __bt_service_get_parameters(in_param1, &address,
4637 sizeof(bluetooth_device_address_t));
4639 result = _bt_pbap_connect(&address);
4642 case BT_PBAP_DISCONNECT: {
4643 bluetooth_device_address_t address = { {0} };
4645 __bt_service_get_parameters(in_param1, &address,
4646 sizeof(bluetooth_device_address_t));
4648 result = _bt_pbap_disconnect(&address);
4651 case BT_PBAP_GET_PHONEBOOK_SIZE: {
4652 bluetooth_device_address_t address = { {0} };
4653 bt_pbap_folder_t folder = { 0, };
4655 __bt_service_get_parameters(in_param1, &address,
4656 sizeof(bluetooth_device_address_t));
4657 __bt_service_get_parameters(in_param2, &folder,
4658 sizeof(bt_pbap_folder_t));
4660 result = _bt_pbap_get_phonebook_size(&address,
4661 folder.addressbook, folder.folder_type);
4664 case BT_PBAP_GET_PHONEBOOK: {
4665 bluetooth_device_address_t address = { {0} };
4666 bt_pbap_folder_t folder = { 0, };
4667 bt_pbap_pull_parameters_t app_param = { 0, };
4669 __bt_service_get_parameters(in_param1, &address,
4670 sizeof(bluetooth_device_address_t));
4671 __bt_service_get_parameters(in_param2, &folder,
4672 sizeof(bt_pbap_folder_t));
4673 __bt_service_get_parameters(in_param3, &app_param,
4674 sizeof(bt_pbap_pull_parameters_t));
4676 result = _bt_pbap_get_phonebook(&address, folder.addressbook,
4677 folder.folder_type, &app_param);
4680 case BT_PBAP_GET_LIST: {
4681 bluetooth_device_address_t address = { {0} };
4682 bt_pbap_folder_t folder = { 0, };
4683 bt_pbap_list_parameters_t app_param = { 0, };
4685 __bt_service_get_parameters(in_param1, &address,
4686 sizeof(bluetooth_device_address_t));
4687 __bt_service_get_parameters(in_param2, &folder,
4688 sizeof(bt_pbap_folder_t));
4689 __bt_service_get_parameters(in_param3, &app_param,
4690 sizeof(bt_pbap_list_parameters_t));
4692 result = _bt_pbap_get_list(&address, folder.addressbook,
4693 folder.folder_type, &app_param);
4696 case BT_PBAP_PULL_VCARD: {
4697 bluetooth_device_address_t address = { {0} };
4698 bt_pbap_folder_t folder = { 0, };
4699 bt_pbap_pull_vcard_parameters_t app_param = { 0, };
4701 __bt_service_get_parameters(in_param1, &address,
4702 sizeof(bluetooth_device_address_t));
4703 __bt_service_get_parameters(in_param2, &folder,
4704 sizeof(bt_pbap_folder_t));
4705 __bt_service_get_parameters(in_param3, &app_param,
4706 sizeof(bt_pbap_pull_vcard_parameters_t));
4708 result = _bt_pbap_pull_vcard(&address, folder.addressbook,
4709 folder.folder_type, &app_param);
4712 case BT_PBAP_PHONEBOOK_SEARCH: {
4713 bluetooth_device_address_t address = { {0} };
4714 bt_pbap_folder_t folder = { 0, };
4715 bt_pbap_search_parameters_t app_param = { 0, };
4717 __bt_service_get_parameters(in_param1, &address,
4718 sizeof(bluetooth_device_address_t));
4719 __bt_service_get_parameters(in_param2, &folder,
4720 sizeof(bt_pbap_folder_t));
4721 __bt_service_get_parameters(in_param3, &app_param,
4722 sizeof(bt_pbap_search_parameters_t));
4724 result = _bt_pbap_phonebook_search(&address, folder.addressbook,
4725 folder.folder_type, &app_param);
4730 BT_ERR("Unknown function!");
4731 result = BLUETOOTH_ERROR_INTERNAL;
4740 int __bt_agent_request(int function_name,
4743 GDBusMethodInvocation *context,
4744 GVariant *in_param1,
4745 GVariant *in_param2,
4746 GVariant *in_param3,
4747 GVariant *in_param4,
4748 GArray **out_param1)
4751 switch (function_name) {
4752 case BT_SET_AUTHORIZATION: {
4759 sender = (char *)g_dbus_method_invocation_get_sender(context);
4760 __bt_service_get_parameters(in_param1, &type, sizeof(int));
4761 uuid = (char *)g_variant_get_data(in_param2);
4762 path = (char *)g_variant_get_data(in_param3);
4763 __bt_service_get_parameters(in_param4, &fd, sizeof(int));
4765 result = _bt_register_osp_server_in_agent(sender, type, uuid, path, fd);
4768 case BT_UNSET_AUTHORIZATION: {
4772 __bt_service_get_parameters(in_param1, &type, sizeof(int));
4773 uuid = (char *)g_variant_get_data(in_param2);
4775 result = _bt_unregister_osp_server_in_agent(type, uuid);
4779 BT_ERR("Unknown function!");
4780 result = BLUETOOTH_ERROR_INTERNAL;
4787 int __bt_core_request(int function_name,
4790 GDBusMethodInvocation *context,
4791 GVariant *in_param1)
4795 switch (function_name) {
4796 case BT_ENABLE_ADAPTER:
4799 _bt_set_adapter_request_state(TRUE);
4800 status = _bt_adapter_get_status();
4802 if (status == BT_ACTIVATING) {
4803 BT_DBG("Enabling in progress");
4804 result = BLUETOOTH_ERROR_IN_PROGRESS;
4805 } else if (status == BT_ACTIVATED) {
4806 BT_DBG("Already enabled");
4807 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
4809 _bt_adapter_set_status(BT_ACTIVATING);
4810 result = BLUETOOTH_ERROR_NONE;
4815 case BT_DISABLE_ADAPTER:
4819 status = _bt_adapter_get_status();
4820 if (status == BT_DEACTIVATING) {
4821 BT_DBG("Disabling in progress");
4822 result = BLUETOOTH_ERROR_IN_PROGRESS;
4823 } else if (status == BT_DEACTIVATED) {
4824 BT_DBG("Already disabled");
4825 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
4827 _bt_adapter_set_status(BT_DEACTIVATING);
4828 result = BLUETOOTH_ERROR_NONE;
4833 case BT_ENABLE_ADAPTER_LE:
4835 bt_le_status_t le_status;
4836 _bt_set_le_request_state(TRUE);
4837 le_status = _bt_adapter_get_le_status();
4838 if (le_status == BT_LE_ACTIVATING) {
4839 BT_DBG("Enabling in progress");
4840 result = BLUETOOTH_ERROR_IN_PROGRESS;
4841 } else if (le_status == BT_LE_ACTIVATED) {
4842 BT_DBG("Already enabled");
4843 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
4845 _bt_adapter_set_le_status(BT_LE_ACTIVATING);
4846 result = BLUETOOTH_ERROR_NONE;
4851 case BT_DISABLE_ADAPTER_LE:
4853 bt_le_status_t le_status;
4855 le_status = _bt_adapter_get_le_status();
4856 if (le_status == BT_LE_DEACTIVATING) {
4857 BT_DBG("Disabling in progress");
4858 result = BLUETOOTH_ERROR_IN_PROGRESS;
4859 } else if (le_status == BT_LE_DEACTIVATED) {
4860 BT_DBG("Already disabled");
4861 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
4863 _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
4864 result = BLUETOOTH_ERROR_NONE;
4870 BT_ERR("Unknown function!");
4871 result = BLUETOOTH_ERROR_INTERNAL;
4878 static int __bt_service_get_requester_app_id(const char *unique_name, char *app_id, int len)
4883 retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
4884 retv_if(unique_name == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
4886 ret = __bt_service_get_sender_pid(unique_name, &pid);
4887 if (ret != BLUETOOTH_ERROR_NONE) {
4888 BT_ERR("Fail to get the sender pid");
4892 ret = aul_app_get_appid_bypid(pid, app_id, len);
4893 if (ret != AUL_R_OK) {
4894 BT_ERR("app_id not found");
4895 return BLUETOOTH_ERROR_NOT_SUPPORT;
4897 BT_DBG("Sender app_id: %s", app_id);
4899 return BLUETOOTH_ERROR_NONE;
4902 gboolean __bt_service_check_privilege(int function_name,
4904 const char *unique_name)
4907 gboolean result = TRUE;
4908 char *client_creds = NULL;
4909 char *user_creds = NULL;
4910 char *client_session = "";
4911 enum cynara_client_creds client_creds_method = CLIENT_METHOD_SMACK;
4912 enum cynara_user_creds user_creds_method = USER_METHOD_UID;
4913 char err_msg[256] = {0, };
4915 retv_if(unique_name == NULL, FALSE);
4916 retv_if(bt_service_conn == NULL, FALSE);
4918 ret_val = cynara_creds_get_default_client_method(&client_creds_method);
4919 if (ret_val != CYNARA_API_SUCCESS) {
4920 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
4921 BT_ERR("Fail to get default client method: %s", err_msg);
4925 ret_val = cynara_creds_get_default_user_method(&user_creds_method);
4926 if (ret_val != CYNARA_API_SUCCESS) {
4927 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
4928 BT_ERR("Fail to get default user method: %s", err_msg);
4932 ret_val = cynara_creds_gdbus_get_client(bt_service_conn, unique_name, client_creds_method, &client_creds);
4933 if (ret_val != CYNARA_API_SUCCESS) {
4934 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
4935 BT_ERR("Fail to get client credential: %s", err_msg);
4939 ret_val = cynara_creds_gdbus_get_user(bt_service_conn, unique_name, user_creds_method, &user_creds);
4940 if (ret_val != CYNARA_API_SUCCESS) {
4941 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
4942 BT_ERR("Fail to get user credential: %s", err_msg);
4948 BT_DBG("%s, %s, %s", unique_name, client_creds, user_creds);
4950 switch (function_name) {
4951 case BT_SET_LOCAL_NAME:
4952 case BT_START_DISCOVERY:
4953 case BT_START_CUSTOM_DISCOVERY:
4954 case BT_CANCEL_DISCOVERY:
4955 case BT_OOB_ADD_REMOTE_DATA:
4956 case BT_OOB_REMOVE_REMOTE_DATA:
4957 case BT_OOB_READ_LOCAL_DATA:
4958 case BT_SET_ADVERTISING:
4959 case BT_SET_CUSTOM_ADVERTISING:
4960 case BT_SET_ADVERTISING_PARAMETERS:
4961 case BT_START_LE_DISCOVERY:
4962 case BT_STOP_LE_DISCOVERY:
4963 case BT_SET_SCAN_PARAMETERS:
4964 case BT_SET_SCAN_TYPE:
4966 case BT_BOND_DEVICE:
4967 case BT_CANCEL_BONDING:
4968 case BT_UNBOND_DEVICE:
4970 case BT_SET_AUTHORIZATION:
4971 case BT_UNSET_AUTHORIZATION:
4972 case BT_SEARCH_SERVICE:
4974 case BT_RFCOMM_CLIENT_CONNECT:
4975 if (function_name == BT_RFCOMM_CLIENT_CONNECT)
4976 BT_PERMANENT_LOG("Connect socket");
4977 case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
4978 case BT_RFCOMM_SOCKET_DISCONNECT:
4979 if (function_name == BT_RFCOMM_SOCKET_DISCONNECT)
4980 BT_PERMANENT_LOG("Disconnect socket");
4981 case BT_RFCOMM_SOCKET_WRITE:
4982 case BT_RFCOMM_CREATE_SOCKET:
4983 case BT_RFCOMM_REMOVE_SOCKET:
4984 case BT_RFCOMM_SEND_RX_DETAILS:
4985 case BT_RFCOMM_SEND_TX_DETAILS:
4986 case BT_RFCOMM_UPDATE_CONNECTION_INFO:
4988 case BT_OPP_PUSH_FILES:
4989 case BT_OPP_CANCEL_PUSH:
4990 /* TODO: MAP? MAP functions, see above */
4992 case BT_OBEX_SERVER_ACCEPT_CONNECTION:
4993 case BT_OBEX_SERVER_REJECT_CONNECTION:
4994 case BT_OBEX_SERVER_ACCEPT_FILE:
4995 case BT_OBEX_SERVER_REJECT_FILE:
4996 case BT_OBEX_SERVER_SET_PATH:
4997 case BT_OBEX_SERVER_SET_ROOT:
4998 case BT_OBEX_SERVER_CANCEL_TRANSFER:
4999 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS:
5001 case BT_AUDIO_SELECT_ROLE:
5002 case BT_AUDIO_CONNECT:
5003 case BT_AUDIO_DISCONNECT:
5005 case BT_AG_DISCONNECT:
5007 case BT_AV_DISCONNECT:
5008 case BT_AV_SOURCE_CONNECT:
5009 case BT_AV_SOURCE_DISCONNECT:
5010 case BT_AVRCP_TARGET_CONNECT:
5011 case BT_AVRCP_TARGET_DISCONNECT:
5012 case BT_AVRCP_CONTROL_CONNECT:
5013 case BT_AVRCP_CONTROL_DISCONNECT:
5014 case BT_AVRCP_HANDLE_CONTROL:
5015 case BT_AVRCP_SET_TRACK_INFO:
5016 case BT_AVRCP_SET_PROPERTY:
5017 case BT_AVRCP_SET_PROPERTIES:
5018 case BT_AVRCP_CONTROL_SET_PROPERTY:
5020 case BT_AUDIO_SET_ABSOLUTE_VOLUME:
5021 case BT_AUDIO_GET_ABSOLUTE_VOLUME:
5022 case BT_AUDIO_IS_AVC_ACTIVATED:
5025 case BT_HF_DISCONNECT:
5027 case BT_HID_CONNECT:
5028 case BT_HID_DISCONNECT:
5030 case BT_HID_DEVICE_ACTIVATE:
5031 case BT_HID_DEVICE_DEACTIVATE:
5032 case BT_HID_DEVICE_CONNECT:
5033 case BT_HID_DEVICE_DISCONNECT:
5034 case BT_HID_DEVICE_SEND_MOUSE_EVENT:
5035 case BT_HID_DEVICE_SEND_KEY_EVENT:
5036 case BT_HID_DEVICE_SEND_REPLY_TO_REPORT:
5037 case BT_HID_DEVICE_SEND_CUSTOM_EVENT:
5040 case BT_DISCONNECT_LE:
5042 case BT_SET_ADVERTISING_DATA:
5043 case BT_SET_SCAN_RESPONSE_DATA:
5045 case BT_HDP_CONNECT:
5046 case BT_HDP_DISCONNECT:
5047 case BT_HDP_SEND_DATA:
5048 case BT_HDP_REGISTER_SINK_APP:
5049 case BT_HDP_UNREGISTER_SINK_APP:
5052 case BT_DPM_SET_ALLOW_BT_MODE:
5053 case BT_DPM_GET_ALLOW_BT_MODE:
5054 case BT_DPM_SET_DEVICE_RESTRITION:
5055 case BT_DPM_GET_DEVICE_RESTRITION:
5056 case BT_DPM_SET_UUID_RESTRITION:
5057 case BT_DPM_GET_UUID_RESTRITION:
5058 case BT_DPM_ADD_DEVICES_BLACKLIST:
5059 case BT_DPM_ADD_DEVICES_WHITELIST:
5060 case BT_DPM_ADD_UUIDS_BLACKLIST:
5061 case BT_DPM_ADD_UUIDS_WHITELIST:
5062 case BT_DPM_CLEAR_DEVICES_BLACKLIST:
5063 case BT_DPM_CLEAR_DEVICES_WHITELIST:
5064 case BT_DPM_CLEAR_UUIDS_BLACKLIST:
5065 case BT_DPM_CLEAR_UUIDS_WHITELIST:
5066 case BT_DPM_REMOVE_DEVICE_BLACKLIST:
5067 case BT_DPM_REMOVE_DEVICE_WHITELIST:
5068 case BT_DPM_REMOVE_UUID_BLACKLIST:
5069 case BT_DPM_REMOVE_UUID_WHITELIST:
5070 case BT_DPM_GET_DEVICES_BLACKLIST:
5071 case BT_DPM_GET_DEVICES_WHITELIST:
5072 case BT_DPM_GET_UUIDS_BLACKLIST:
5073 case BT_DPM_GET_UUIDS_WHITELIST:
5074 case BT_DPM_SET_ALLOW_OUTGOING_CALL:
5075 case BT_DPM_GET_ALLOW_OUTGOING_CALL:
5076 case BT_DPM_SET_PAIRING_STATE:
5077 case BT_DPM_GET_PAIRING_STATE:
5078 case BT_DPM_SET_PROFILE_STATE:
5079 case BT_DPM_GET_PROFILE_STATE:
5080 case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE:
5081 case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE:
5082 case BT_DPM_SET_DISCOVERABLE_STATE:
5083 case BT_DPM_GET_DISCOVERABLE_STATE:
5084 case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE:
5085 case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE:
5086 case BT_DPM_SET_DATA_TRANSFER_STATE:
5087 case BT_DPM_GET_DATA_TRANSFER_STATE:
5089 case BT_NETWORK_ACTIVATE:
5090 case BT_NETWORK_DEACTIVATE:
5091 case BT_NETWORK_CONNECT:
5092 case BT_NETWORK_DISCONNECT:
5093 case BT_NETWORK_SERVER_DISCONNECT:
5095 case BT_GATT_GET_PRIMARY_SERVICES:
5096 case BT_GATT_GET_SERVICE_PROPERTIES: /* GATT Client */
5097 case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: /* GATT Client */
5098 case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: /* GATT Client */
5099 case BT_GATT_DISCOVER_CHARACTERISTICS:
5100 case BT_GATT_SET_PROPERTY_REQUEST:
5101 case BT_GATT_READ_CHARACTERISTIC:
5102 case BT_GATT_READ_DESCRIPTOR_VALUE: /* GATT Client */
5103 case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: /* GATT Client */
5104 case BT_GATT_ACQUIRE_WRITE:
5105 case BT_GATT_WRITE_DESCRIPTOR_VALUE: /* GATT Client */
5106 case BT_GATT_WATCH_CHARACTERISTIC: /* GATT Client */
5107 case BT_GATT_CLIENT_REGISTER: /* GATT Client */
5108 case BT_GATT_CLIENT_UNREGISTER: /* GATT Client */
5109 case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
5110 case BT_GATT_REGISTER_APPLICATION:
5111 case BT_GATT_REGISTER_SERVICE:
5112 case BT_GATT_SEND_RESPONSE:
5114 case BT_GATT_SERVER_REGISTER:
5115 case BT_GATT_SERVER_ADD_SERVICE:
5116 case BT_GATT_SERVER_ADD_CHARACTERISTIC:
5117 case BT_GATT_SERVER_ADD_DESCRIPTOR:
5118 case BT_GATT_SERVER_START_SERVICE:
5119 case BT_GATT_SERVER_STOP_SERVICE:
5120 case BT_GATT_SERVER_DELETE_SERVICE:
5121 case BT_GATT_SERVER_SEND_RESPONSE:
5122 case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE:
5123 case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE:
5124 case BT_GATT_SERVER_SEND_INDICATION:
5125 case BT_GATT_SERVER_UPDATE_VALUE:
5126 case BT_GATT_SERVER_DEREGISTER:
5128 case BT_REQ_ATT_MTU:
5129 case BT_PBAP_CONNECT:
5130 case BT_PBAP_DISCONNECT:
5131 case BT_PBAP_GET_PHONEBOOK_SIZE:
5132 case BT_PBAP_GET_PHONEBOOK:
5133 case BT_PBAP_GET_LIST:
5134 case BT_PBAP_PULL_VCARD:
5135 case BT_PBAP_PHONEBOOK_SEARCH:
5137 case BT_RFCOMM_LISTEN_AND_ACCEPT:
5139 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5140 BT_PRIVILEGE_PUBLIC);
5142 BT_INFO("Client Credentials [%s]", client_creds);
5143 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5144 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PUBLIC);
5148 /* Need to check mediastorage privilege */
5149 if (function_name == BT_PBAP_GET_PHONEBOOK ||
5150 function_name == BT_PBAP_PULL_VCARD) {
5151 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5152 MEDIASTORAGE_PRIVILEGE);
5154 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5155 BT_ERR("Fail to access: %s", MEDIASTORAGE_PRIVILEGE);
5161 case BT_ENABLE_ADAPTER:
5162 case BT_DISABLE_ADAPTER:
5163 case BT_RESET_ADAPTER:
5164 case BT_RECOVER_ADAPTER:
5165 case BT_BATTERY_READ_DATA:
5166 case BT_ENABLE_ADAPTER_LE:
5167 case BT_DISABLE_ADAPTER_LE:
5168 case BT_SET_CONNECTABLE:
5169 case BT_SET_DISCOVERABLE_MODE:
5170 case BT_ADD_WHITE_LIST:
5171 case BT_REMOVE_WHITE_LIST:
5172 case BT_CLEAR_WHITE_LIST:
5173 case BT_SET_MANUFACTURER_DATA:
5175 case BT_CANCEL_SEARCH_SERVICE:
5176 case BT_ENABLE_RSSI:
5177 case BT_DISCONNECT_DEVICE:
5179 case BT_RFCOMM_ACCEPT_CONNECTION:
5180 case BT_RFCOMM_REJECT_CONNECTION:
5181 case BT_RFCOMM_LISTEN:
5183 case BT_HID_ENABLE_BARCODE_FEATURE:
5185 case BT_AVRCP_TRANSPORT_SET_PROPERTY:
5186 case BT_AVRCP_HANDLE_CONTROL_TO_DEST:
5188 case BT_SET_CONTENT_PROTECT:
5189 case BT_BOND_DEVICE_BY_TYPE:
5190 case BT_SET_LE_PRIVACY:
5191 case BT_SET_LE_STATIC_RANDOM_ADDRESS:
5192 case BT_LE_CONN_UPDATE:
5193 case BT_UPDATE_LE_CONNECTION_MODE:
5194 case BT_GET_DEVICE_IDA:
5195 case BT_LE_READ_MAXIMUM_DATA_LENGTH:
5196 case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH:
5197 case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH:
5198 case BT_LE_SET_DATA_LENGTH:
5199 case BT_LE_OOB_READ_LOCAL_DATA:
5200 case BT_LE_OOB_ADD_REMOTE_DATA:
5202 case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS:
5203 case BT_ENABLE_GATT_DATA_BATCHING:
5204 case BT_DISABLE_GATT_DATA_BATCHING:
5206 case BT_LE_IPSP_INIT:
5207 case BT_LE_IPSP_DEINIT:
5208 case BT_LE_IPSP_CONNECT:
5209 case BT_LE_IPSP_DISCONNECT:
5210 case BT_PXP_MONITOR_SET_PROPERTY:
5211 case BT_PXP_MONITOR_GET_PROPERTY:
5212 case BT_PXP_MONITOR_GET_SUPPORTED_SERIVCES:
5213 case BT_PXP_REPORTER_REGISTER:
5214 case BT_PXP_REPORTER_UNREGISTER:
5215 case BT_PXP_REPORTER_GET_PROPERTY:
5218 case BT_TDS_PROVIDER_REGISTER:
5219 case BT_TDS_PROVIDER_UNREGISTER:
5220 case BT_TDS_PROVIDER_SET_MANUF_DATA:
5221 case BT_TDS_PROVIDER_CREATE:
5222 case BT_TDS_PROVIDER_DESTROY:
5223 case BT_TDS_PROVIDER_SET_TRANSPORT_DATA:
5224 case BT_TDS_SEND_ACTIVATION_RESPONSE:
5225 case BT_TDS_READ_TRANSPORT_DATA:
5226 case BT_TDS_ENABLE_CONTROL_POINT:
5227 case BT_TDS_ACTIVATE_CONTROL_POINT:
5230 case BT_OTP_SERVER_INIT:
5231 case BT_OTP_SERVER_DEINIT:
5232 case BT_OTP_READ_VALUE:
5233 case BT_OTP_ENABLE_NOTIFICATION:
5234 case BT_OTP_WRITE_VALUE:
5235 case BT_LE_OTC_CONNECT:
5236 case BT_LE_OTC_DISCONNECT:
5238 case BT_MAP_CREATE_SESSION:
5239 case BT_MAP_DESTROY_SESSION:
5240 case BT_MAP_SET_FOLDER:
5241 case BT_MAP_LIST_FOLDERS:
5242 case BT_MAP_LIST_FILTER_FIELDS:
5243 case BT_MAP_LIST_MESSAGES:
5244 case BT_MAP_UPDATE_INBOX:
5245 case BT_MAP_PUSH_MESSAGE:
5246 case BT_MAP_GET_MESSAGE:
5249 case BT_MESH_DEINIT:
5250 case BT_MESH_NETWORK_CREATE:
5251 case BT_MESH_NETWORK_DESTROY:
5252 case BT_MESH_NETWORK_LOAD:
5253 case BT_MESH_NETWORK_UNLOAD:
5254 case BT_MESH_NETWORK_SCAN:
5255 case BT_MESH_NETWORK_CANCEL_SCAN:
5256 case BT_MESH_NETWORK_SET_CAPABILITIES:
5257 case BT_MESH_NETWORK_PROVISION_DEVICE:
5258 case BT_MESH_AUTHENTICATION_REPLY:
5259 case BT_MESH_NETWORK_SET_NAME:
5260 case BT_MESH_NETWORK_ADD_NETKEY:
5261 case BT_MESH_NETWORK_DELETE_NETKEY:
5262 case BT_MESH_NETWORK_UPDATE_NETKEY:
5263 case BT_MESH_NETWORK_ADD_APPKEY:
5264 case BT_MESH_NETWORK_DELETE_APPKEY:
5265 case BT_MESH_NETWORK_UPDATE_APPKEY:
5266 case BT_MESH_NETWORK_GET_NETKEYS:
5267 case BT_MESH_NETWORK_GET_APPKEYS:
5268 case BT_MESH_NETWORK_GET_NODES:
5269 case BT_MESH_ELEMENT_GET_MODELS:
5270 case BT_MESH_NODE_BROWSE:
5271 case BT_MESH_NODE_GET_VENDOR_FEATURES:
5272 case BT_MESH_NODE_CONFIGURE_KEY:
5273 case BT_MESH_NODE_TTL_EXECUTE:
5274 case BT_MESH_NODE_GET_NETKEYS:
5275 case BT_MESH_NODE_GET_APPKEYS:
5276 case BT_MESH_NODE_RESET:
5277 case BT_MESH_MODEL_CONFIGURE_APPKEY:
5278 case BT_MESH_MODEL_GET_APPKEY_LIST:
5279 case BT_MESH_MODEL_EXECUTE_MSG:
5280 case BT_MESH_NETWORK_CREATE_GROUP:
5281 case BT_MESH_NETWORK_REMOVE_GROUP:
5282 case BT_MESH_MODEL_CONFIG_GROUP_SUB:
5283 case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB:
5284 case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST:
5285 case BT_MESH_MODEL_SET_PUBLICATION:
5286 case BT_MESH_MODEL_GET_PUBLICATION:
5287 case BT_MESH_NETWORK_GET_GROUPS:
5289 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5290 BT_PRIVILEGE_PLATFORM);
5292 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5293 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PLATFORM);
5298 case BT_CHECK_ADAPTER:
5301 case BT_GET_LOCAL_NAME:
5302 case BT_GET_LOCAL_ADDRESS:
5303 case BT_GET_LOCAL_VERSION:
5304 case BT_IS_SERVICE_USED:
5305 case BT_GET_DISCOVERABLE_MODE:
5306 case BT_GET_DISCOVERABLE_TIME:
5307 case BT_IS_DISCOVERYING:
5308 case BT_IS_LE_DISCOVERYING:
5309 case BT_IS_CONNECTABLE:
5310 case BT_GET_CONNECTABLE:
5311 case BT_GET_BONDED_DEVICES:
5312 case BT_GET_PROFILE_CONNECTED_DEVICES:
5313 case BT_GET_BONDED_DEVICE:
5314 case BT_PASSKEY_REPLY:
5315 case BT_PASSKEY_CONFIRMATION_REPLY:
5316 case BT_GET_IS_ALIAS_SET:
5317 case BT_IS_DEVICE_CONNECTED:
5318 case BT_GET_CONNECTED_LINK_TYPE:
5319 case BT_SET_PROFILE_TRUSTED:
5320 case BT_GET_PROFILE_TRUSTED:
5321 case BT_GET_SPEAKER_GAIN:
5322 case BT_SET_SPEAKER_GAIN:
5323 case BT_RFCOMM_CLIENT_IS_CONNECTED:
5324 case BT_RFCOMM_IS_UUID_AVAILABLE:
5325 case BT_GET_ADVERTISING_DATA:
5326 case BT_GET_SCAN_RESPONSE_DATA:
5327 case BT_IS_ADVERTISING:
5328 case BT_IS_LE_2M_PHY_SUPPORTED:
5329 case BT_IS_LE_CODED_PHY_SUPPORTED:
5330 case BT_REGISTER_SCAN_FILTER:
5331 case BT_IS_SCAN_FILTER_SUPPORTED:
5332 case BT_GET_ATT_MTU:
5334 case BT_OBEX_SERVER_ALLOCATE:
5335 case BT_OBEX_SERVER_DEALLOCATE:
5336 case BT_OBEX_SERVER_IS_ACTIVATED:
5337 case BT_OPP_GET_TRANSFER_PROGRESS:
5338 case BT_AVRCP_CONTROL_GET_PROPERTY:
5339 case BT_AVRCP_GET_TRACK_INFO:
5340 /* Non-privilege control */
5343 BT_ERR("Unknown function!");
5348 if (function_name >= BT_FUNC_MESH_BASE) {
5349 BT_INFO("MESH Function called");
5350 char app_id[256] = { 0, };
5352 if (BLUETOOTH_ERROR_NONE == __bt_service_get_requester_app_id(unique_name,
5353 app_id, sizeof(app_id))) {
5354 requester_unique_creds = g_strdup(app_id);
5356 BT_DBG("Requester app_id not found, use client creds");
5357 requester_unique_creds = g_strdup(client_creds);
5359 BT_DBG("Requester unique_creds: %s", requester_unique_creds);
5361 BT_INFO("Non MESH Function called client creds [%s]", client_creds);
5373 GDBusNodeInfo *__bt_service_create_method_node_info
5374 (const gchar *introspection_data)
5377 GDBusNodeInfo *node_info = NULL;
5379 if (introspection_data == NULL) {
5380 BT_ERR("Introspection XML not present");
5384 node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
5387 BT_ERR("Unable to create node: %s", err->message);
5388 g_clear_error(&err);
5393 int __bt_service_register_object(GDBusConnection *conn,
5394 GDBusNodeInfo *node_info, gboolean reg)
5396 static guint service_id = 0;
5397 GError *error = NULL;
5400 if (node_info == NULL)
5403 service_id = g_dbus_connection_register_object(conn,
5405 node_info->interfaces[0],
5407 NULL, NULL, &error);
5408 if (service_id == 0)
5411 if (service_id > 0) {
5412 g_dbus_connection_unregister_object(conn,
5421 static void __name_owner_changed(GDBusConnection *connection,
5422 const gchar *sender_name,
5423 const gchar *object_path,
5424 const gchar *interface_name,
5425 const gchar *signal_name,
5426 GVariant *parameters,
5429 const char *name = NULL;
5430 const char *old_owner = NULL;
5431 const char *new_owner = NULL;
5433 g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
5434 if (*new_owner != '\0')
5437 _bt_check_hdp_app_termination(name);
5439 /* Advertising App Termination */
5440 _bt_check_adv_app_termination(name);
5442 /* Check if le_scanning app is terminated */
5443 _bt_check_le_scanner_app_termination(name);
5445 /* Check if RFCOMM app is terminated */
5446 _bt_rfcomm_check_termination(name);
5448 /* Mesh App Termination */
5449 _bt_check_mesh_app_termination(name);
5451 /* Stop the Transport Discovery service */
5452 _bt_tds_stop_by_terminated_process(name);
5455 static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
5456 const gchar *name, gpointer user_data)
5458 GDBusNodeInfo *node_info = NULL;
5460 BT_INFO("bus acquired");
5462 ret_if(connection == NULL);
5464 node_info = __bt_service_create_method_node_info(
5465 bt_service_introspection_xml);
5466 ret_if(node_info == NULL);
5468 __bt_service_register_object(connection, node_info, TRUE);
5469 g_dbus_node_info_unref(node_info);
5471 bt_service_conn = connection;
5474 static void __bt_service_name_acquired_handler(GDBusConnection *connection,
5475 const gchar *name, gpointer user_data)
5477 BT_INFO("name acquired");
5478 name_acquired = TRUE;
5481 static void __bt_service_name_lost_handler(GDBusConnection *connection,
5482 const gchar *name, gpointer user_data)
5484 BT_INFO("name lost");
5485 name_acquired = FALSE;
5488 gboolean _is_name_acquired(void)
5490 return name_acquired;
5493 void _bt_service_unref_connection(void)
5497 if (bt_service_conn) {
5498 g_dbus_connection_flush_sync(bt_service_conn, NULL, NULL);
5499 g_object_unref(bt_service_conn);
5500 bt_service_conn = NULL;
5506 int _bt_service_register(void)
5508 GDBusConnection *conn;
5511 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
5512 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
5513 bt_service_conn = conn;
5515 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
5517 G_BUS_NAME_OWNER_FLAGS_NONE,
5518 __bt_service_bus_acquired_handler,
5519 __bt_service_name_acquired_handler,
5520 __bt_service_name_lost_handler,
5522 BT_DBG("owner_id is [%d]", owner_id);
5526 /* Subscribe for name owner changed signal */
5527 owner_sig_id = g_dbus_connection_signal_subscribe(conn,
5528 BT_FREEDESKTOP_SERVICE, BT_FREEDESKTOP_INTERFACE,
5529 BT_NAME_OWNER_CHANGED, NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
5530 __name_owner_changed, NULL, NULL);
5531 BT_INFO("owner_sig_id: %d", owner_sig_id);
5533 return BLUETOOTH_ERROR_NONE;
5536 if (bt_service_conn) {
5537 g_object_unref(bt_service_conn);
5538 bt_service_conn = NULL;
5541 return BLUETOOTH_ERROR_INTERNAL;
5544 void _bt_service_unregister(void)
5546 if (bt_service_conn) {
5547 sd_notify(0, "STOPPING=1");
5549 if (owner_sig_id > 0) {
5550 g_dbus_connection_signal_unsubscribe(
5551 bt_service_conn, owner_sig_id);
5556 g_bus_unown_name(owner_id);
5560 __bt_service_register_object(bt_service_conn, NULL, FALSE);
5564 int _bt_service_cynara_init(void)
5567 char err_msg[256] = {0, };
5569 retv_if(p_cynara != NULL, BLUETOOTH_ERROR_ALREADY_INITIALIZED);
5571 result = cynara_initialize(&p_cynara, conf);
5573 if (result != CYNARA_API_SUCCESS) {
5574 cynara_strerror(result, err_msg, sizeof(err_msg));
5575 BT_ERR("Fail to initialize cynara: [%s]", err_msg);
5576 return BLUETOOTH_ERROR_INTERNAL;
5579 return BLUETOOTH_ERROR_NONE;
5582 void _bt_service_cynara_deinit(void)
5585 char err_msg[256] = {0, };
5587 ret_if(p_cynara == NULL);
5589 result = cynara_finish(p_cynara);
5591 if (result != CYNARA_API_SUCCESS) {
5592 cynara_strerror(result, err_msg, sizeof(err_msg));
5593 BT_ERR("Fail to finish cynara: [%s]", err_msg);
5601 void _bt_service_method_return(GDBusMethodInvocation *invocation,
5602 GArray *out_param, int result)
5606 out_var = g_variant_new_from_data((const GVariantType *)"ay",
5607 out_param->data, out_param->len, TRUE, NULL, NULL);
5609 g_dbus_method_invocation_return_value(invocation,
5610 g_variant_new("(iv)", result, out_var));
5613 void _bt_service_method_return_with_unix_fd_list(GDBusMethodInvocation *invocation,
5614 GArray *out_param, int result, GUnixFDList *fd_list)
5618 out_var = g_variant_new_from_data((const GVariantType *)"ay",
5619 out_param->data, out_param->len, TRUE, NULL, NULL);
5621 g_dbus_method_invocation_return_value_with_unix_fd_list(invocation,
5622 g_variant_new("(iv)", result, out_var), fd_list);