4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
25 #include <dbus/dbus-glib.h>
26 #include <dbus/dbus-glib-bindings.h>
27 #include <dbus/dbus-glib-lowlevel.h>
30 #include <security-server.h>
32 #include "bluetooth-api.h"
33 #include "bt-service-common.h"
34 #include "bt-service-util.h"
35 #include "bt-service-event.h"
36 #include "bt-service-adapter.h"
37 #include "bt-service-adapter-le.h"
38 #include "bt-service-device.h"
39 #include "bt-service-hid.h"
40 #include "bt-service-network.h"
41 #include "bt-service-audio.h"
42 #include "bt-service-oob.h"
43 #include "bt-service-avrcp.h"
44 #include "bt-service-opp-client.h"
45 #include "bt-service-obex-server.h"
46 #include "bt-service-rfcomm-client.h"
47 #include "bt-service-rfcomm-server.h"
48 #include "bt-request-handler.h"
49 #include "bt-service-pbap.h"
51 /* auto generated header by bt-request-service.xml*/
52 #include "bt-service-method.h"
54 DBusGConnection *bt_service_conn;
55 BtService *service_object;
57 GType bt_service_get_type(void);
59 G_DEFINE_TYPE(BtService, bt_service, G_TYPE_OBJECT);
61 /*This is part of platform provided code skeleton for client server model*/
62 static void bt_service_class_init(BtServiceClass *service_class)
64 dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(service_class),
65 &dbus_glib_bt_object_info);
68 /*This is part of platform provided code skeleton for client server model*/
69 static void bt_service_init(BtService *service)
73 static int __bt_bluez_request(int function_name,
76 DBusGMethodInvocation *context,
83 int result = BLUETOOTH_ERROR_NONE;
85 switch (function_name) {
86 case BT_ENABLE_ADAPTER:
87 result = _bt_enable_adapter();
89 case BT_DISABLE_ADAPTER:
90 result = _bt_disable_adapter();
92 case BT_RECOVER_ADAPTER:
93 result = _bt_recover_adapter();
95 case BT_ENABLE_ADAPTER_LE:
96 result = _bt_enable_adapter_le();
98 case BT_DISABLE_ADAPTER_LE:
99 result = _bt_disable_adapter_le();
101 case BT_RESET_ADAPTER:
102 result = _bt_reset_adapter();
104 case BT_CHECK_ADAPTER: {
105 int enabled = BT_ADAPTER_DISABLED;
107 result = _bt_check_adapter(&enabled);
109 g_array_append_vals(*out_param1, &enabled,
113 case BT_GET_LOCAL_ADDRESS: {
114 bluetooth_device_address_t local_address = { {0} };
115 result = _bt_get_local_address(&local_address);
117 g_array_append_vals(*out_param1, &local_address,
118 sizeof(bluetooth_device_address_t));
121 case BT_GET_LOCAL_VERSION: {
122 bluetooth_version_t ver = { {0} };
123 result = _bt_get_local_version(&ver);
125 g_array_append_vals(*out_param1, &ver,
126 sizeof(bluetooth_version_t));
129 case BT_GET_LOCAL_NAME: {
130 bluetooth_device_name_t local_name = { {0} };
131 result = _bt_get_local_name(&local_name);
133 g_array_append_vals(*out_param1, &local_name,
134 sizeof(bluetooth_device_name_t));
138 case BT_SET_LOCAL_NAME: {
139 bluetooth_device_name_t local_name = { {0} };
141 local_name = g_array_index(in_param1,
142 bluetooth_device_name_t, 0);
144 result = _bt_set_local_name(local_name.name);
148 case BT_IS_SERVICE_USED: {
150 gboolean used = FALSE;
152 uuid = &g_array_index(in_param1, char, 0);
154 result = _bt_is_service_used(uuid, &used);
156 if (result == BLUETOOTH_ERROR_NONE) {
157 g_array_append_vals(*out_param1, &used,
162 case BT_GET_DISCOVERABLE_MODE: {
163 int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
165 result = _bt_get_discoverable_mode(&mode);
167 g_array_append_vals(*out_param1, &mode, sizeof(int));
170 case BT_SET_DISCOVERABLE_MODE: {
171 int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
174 mode = g_array_index(in_param1, int, 0);
175 time = g_array_index(in_param2, int, 0);
177 result = _bt_set_discoverable_mode(mode, time);
180 case BT_GET_DISCOVERABLE_TIME: {
183 result = _bt_get_timeout_value(&timeout);
185 g_array_append_vals(*out_param1, &timeout, sizeof(int));
188 case BT_START_DISCOVERY:
189 result = _bt_start_discovery();
192 case BT_START_CUSTOM_DISCOVERY: {
193 bt_discovery_role_type_t role;
194 role = g_array_index(in_param1, bt_discovery_role_type_t, 0);
196 result = _bt_start_custom_discovery(role);
199 case BT_CANCEL_DISCOVERY:
200 result = _bt_cancel_discovery();
202 case BT_START_LE_DISCOVERY:
203 result = _bt_start_le_discovery();
205 case BT_STOP_LE_DISCOVERY:
206 result = _bt_stop_le_discovery();
208 case BT_IS_DISCOVERYING: {
209 gboolean discovering = FALSE;
210 discovering = _bt_is_discovering();
211 g_array_append_vals(*out_param1, &discovering, sizeof(gboolean));
214 case BT_IS_LE_DISCOVERYING: {
215 gboolean le_discovering = FALSE;
216 le_discovering = _bt_is_le_discovering();
217 g_array_append_vals(*out_param1, &le_discovering, sizeof(gboolean));
220 case BT_ENABLE_RSSI: {
221 bluetooth_device_address_t bd_addr;
223 bt_rssi_threshold_t rssi_threshold;
225 int in_range_threshold;
227 BT_DBG("Enable RSSI");
229 bd_addr = g_array_index(in_param1, bluetooth_device_address_t, 0);
230 link_type = g_array_index(in_param2, int, 0);
231 rssi_threshold = g_array_index(in_param3, bt_rssi_threshold_t, 0);
233 low_threshold = rssi_threshold.low_threshold;
234 in_range_threshold = rssi_threshold.in_range_threshold;
235 high_threshold = rssi_threshold.high_threshold;
237 result = _bt_enable_rssi(&bd_addr, link_type ,low_threshold,
238 in_range_threshold, high_threshold);
243 bluetooth_device_address_t bd_addr;
245 BT_DBG("Get RSSI Strength");
247 bd_addr = g_array_index(in_param1, bluetooth_device_address_t, 0);
248 link_type = g_array_index(in_param2, int, 0);
249 result = _bt_get_rssi_strength(&bd_addr, link_type);
252 case BT_IS_CONNECTABLE: {
253 gboolean is_connectable;
255 is_connectable = _bt_is_connectable();
256 g_array_append_vals(*out_param1, &is_connectable, sizeof(gboolean));
259 case BT_SET_CONNECTABLE: {
260 gboolean is_connectable;
262 is_connectable = g_array_index(in_param1, gboolean, 0);
264 result = _bt_set_connectable(is_connectable);
267 case BT_SET_ADVERTISING: {
268 gboolean enable = FALSE;
270 gboolean use_reserved_slot = FALSE;
272 enable = g_array_index(in_param1, gboolean, 0);
273 use_reserved_slot = g_array_index(in_param2, gboolean, 0);
274 sender = dbus_g_method_get_sender(context);
275 result = _bt_set_advertising(enable, sender, use_reserved_slot);
279 case BT_SET_CUSTOM_ADVERTISING: {
280 gboolean enable = FALSE;
281 bluetooth_advertising_params_t adv_params;
283 gboolean use_reserved_slot = FALSE;
285 enable = g_array_index(in_param1, gboolean, 0);
286 adv_params = g_array_index(in_param2,
287 bluetooth_advertising_params_t, 0);
288 use_reserved_slot = g_array_index(in_param3, gboolean, 0);
289 sender = dbus_g_method_get_sender(context);
291 BT_DBG("bluetooth_advertising_params_t [%f %f %d %d]",
292 adv_params.interval_min, adv_params.interval_max,
293 adv_params.filter_policy, adv_params.type);
294 result = _bt_set_custom_advertising(enable, &adv_params, sender, use_reserved_slot);
298 case BT_GET_ADVERTISING_DATA: {
299 bluetooth_advertising_data_t adv = { {0} };
302 result = _bt_get_advertising_data(&adv, &length);
303 if (result == BLUETOOTH_ERROR_NONE) {
304 g_array_append_vals(*out_param1, adv.data, length);
309 case BT_SET_ADVERTISING_DATA: {
310 bluetooth_advertising_data_t adv = { {0} };
313 gboolean use_reserved_slot = FALSE;
315 sender = dbus_g_method_get_sender(context);
317 adv = g_array_index(in_param1,
318 bluetooth_advertising_data_t, 0);
319 length = g_array_index(in_param2, int, 0);
320 use_reserved_slot = g_array_index(in_param3, gboolean, 0);
322 result = _bt_set_advertising_data(&adv, length, sender, use_reserved_slot);
327 case BT_GET_SCAN_RESPONSE_DATA: {
328 bluetooth_scan_resp_data_t rsp = { {0} };
331 result = _bt_get_scan_response_data(&rsp, &length);
332 if (result == BLUETOOTH_ERROR_NONE) {
333 g_array_append_vals(*out_param1, rsp.data, length);
338 case BT_SET_SCAN_RESPONSE_DATA: {
339 bluetooth_scan_resp_data_t rsp = { {0} };
342 gboolean use_reserved_slot = FALSE;
344 sender = dbus_g_method_get_sender(context);
346 rsp = g_array_index(in_param1,
347 bluetooth_scan_resp_data_t, 0);
348 length = g_array_index(in_param2, int, 0);
349 use_reserved_slot = g_array_index(in_param3, gboolean, 0);
351 result = _bt_set_scan_response_data(&rsp, length, sender, use_reserved_slot);
356 case BT_SET_MANUFACTURER_DATA: {
357 bluetooth_manufacturer_data_t m_data = { 0 };
359 m_data = g_array_index(in_param1,
360 bluetooth_manufacturer_data_t, 0);
362 result = _bt_set_manufacturer_data(&m_data);
365 case BT_SET_SCAN_PARAMETERS: {
366 bluetooth_le_scan_params_t scan_params;
368 scan_params = g_array_index(in_param1,
369 bluetooth_le_scan_params_t, 0);
371 BT_DBG("bluetooth_le_scan_params_t [%f %f %d]",
372 scan_params.interval, scan_params.window,
375 result = _bt_set_scan_parameters(&scan_params);
378 case BT_LE_CONN_UPDATE: {
379 bluetooth_device_address_t local_address = { {0} };
380 bluetooth_le_conn_update_t parameters = {0};
382 local_address = g_array_index(in_param1,
383 bluetooth_device_address_t, 0);
384 parameters = g_array_index(in_param2,
385 bluetooth_le_conn_update_t, 0);
387 result = _bt_le_conn_update(local_address.addr,
388 parameters.interval_min,
389 parameters.interval_max,
391 parameters.time_out);
394 case BT_IS_ADVERTISING: {
395 gboolean advertising = FALSE;
396 advertising = _bt_is_advertising();
398 g_array_append_vals(*out_param1, &advertising, sizeof(gboolean));
401 case BT_ADD_WHITE_LIST: {
402 bluetooth_device_address_t address = { {0} };
405 address = g_array_index(in_param1,
406 bluetooth_device_address_t, 0);
407 addr_type = g_array_index(in_param2, int, 0);
409 result = _bt_add_white_list(&address, addr_type);
412 case BT_REMOVE_WHITE_LIST: {
413 bluetooth_device_address_t address = { {0} };
416 address = g_array_index(in_param1,
417 bluetooth_device_address_t, 0);
418 addr_type = g_array_index(in_param2, int, 0);
420 result = _bt_remove_white_list(&address, addr_type);
423 case BT_CLEAR_WHITE_LIST: {
424 result = _bt_clear_white_list();
427 case BT_GET_BONDED_DEVICES:
428 result = _bt_get_bonded_devices(out_param1);
431 case BT_GET_BONDED_DEVICE: {
432 bluetooth_device_address_t address = { {0} };
433 bluetooth_device_info_t dev_info;
435 address = g_array_index(in_param1,
436 bluetooth_device_address_t, 0);
438 memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
439 result = _bt_get_bonded_device_info(&address, &dev_info);
441 if (result == BLUETOOTH_ERROR_NONE) {
442 g_array_append_vals(*out_param1, &dev_info,
443 sizeof(bluetooth_device_info_t));
447 case BT_BOND_DEVICE: {
448 bluetooth_device_address_t address = { {0} };
450 address = g_array_index(in_param1,
451 bluetooth_device_address_t, 0);
453 result = _bt_bond_device(request_id, &address,
454 BLUETOOTH_DEV_CONN_DEFAULT, out_param1);
457 case BT_BOND_DEVICE_BY_TYPE: {
458 bluetooth_device_address_t address = { {0} };
459 unsigned short conn_type = 0;
461 address = g_array_index(in_param1,
462 bluetooth_device_address_t, 0);
464 conn_type = g_array_index(in_param2,
467 result = _bt_bond_device(request_id, &address,
468 conn_type, out_param1);
471 case BT_CANCEL_BONDING: {
472 result = _bt_cancel_bonding();
475 case BT_UNBOND_DEVICE: {
476 bluetooth_device_address_t address = { {0} };
478 address = g_array_index(in_param1,
479 bluetooth_device_address_t, 0);
481 result = _bt_unbond_device(request_id, &address, out_param1);
486 bluetooth_device_address_t address = { {0} };
487 const char *local_name;
489 address = g_array_index(in_param1,
490 bluetooth_device_address_t, 0);
492 local_name = &g_array_index(in_param2, char, 0);
494 result = _bt_set_alias(&address, local_name);
497 case BT_SEARCH_SERVICE: {
498 bluetooth_device_address_t address = { {0} };
500 address = g_array_index(in_param1,
501 bluetooth_device_address_t, 0);
503 result = _bt_search_device(request_id, &address);
504 if (result != BLUETOOTH_ERROR_NONE) {
505 g_array_append_vals(*out_param1, &address,
506 sizeof(bluetooth_device_address_t));
510 case BT_CANCEL_SEARCH_SERVICE: {
511 result = _bt_cancel_search_device();
514 case BT_SET_AUTHORIZATION: {
515 bluetooth_device_address_t address = { {0} };
518 address = g_array_index(in_param1,
519 bluetooth_device_address_t, 0);
521 authorize = g_array_index(in_param2, gboolean, 0);
523 result = _bt_set_authorization(&address, authorize);
526 case BT_IS_DEVICE_CONNECTED: {
527 bluetooth_device_address_t address = { {0} };
529 gboolean connected = FALSE;
531 address = g_array_index(in_param1,
532 bluetooth_device_address_t, 0);
534 type = g_array_index(in_param2, int, 0);
536 result = _bt_is_device_connected(&address, type, &connected);
538 if (result == BLUETOOTH_ERROR_NONE) {
539 g_array_append_vals(*out_param1, &connected,
545 case BT_HID_CONNECT: {
546 bluetooth_device_address_t address = { {0} };
548 address = g_array_index(in_param1,
549 bluetooth_device_address_t, 0);
551 result = _bt_hid_connect(request_id, &address);
552 if (result != BLUETOOTH_ERROR_NONE) {
553 g_array_append_vals(*out_param1, &address,
554 sizeof(bluetooth_device_address_t));
558 case BT_HID_DISCONNECT: {
559 bluetooth_device_address_t address = { {0} };
561 address = g_array_index(in_param1,
562 bluetooth_device_address_t, 0);
564 result = _bt_hid_disconnect(request_id, &address);
565 if (result != BLUETOOTH_ERROR_NONE) {
566 g_array_append_vals(*out_param1, &address,
567 sizeof(bluetooth_device_address_t));
571 case BT_NETWORK_ACTIVATE:
572 result = _bt_network_activate();
574 case BT_NETWORK_DEACTIVATE:
575 result = _bt_network_deactivate();
577 case BT_NETWORK_CONNECT: {
578 bluetooth_device_address_t address = { {0} };
581 address = g_array_index(in_param1,
582 bluetooth_device_address_t, 0);
584 role = g_array_index(in_param2, int, 0);
586 result = _bt_network_connect(request_id, role, &address);
587 if (result != BLUETOOTH_ERROR_NONE) {
588 g_array_append_vals(*out_param1, &address,
589 sizeof(bluetooth_device_address_t));
593 case BT_NETWORK_DISCONNECT: {
594 bluetooth_device_address_t address = { {0} };
596 address = g_array_index(in_param1,
597 bluetooth_device_address_t, 0);
599 result = _bt_network_disconnect(request_id, &address);
600 if (result != BLUETOOTH_ERROR_NONE) {
601 g_array_append_vals(*out_param1, &address,
602 sizeof(bluetooth_device_address_t));
606 case BT_NETWORK_SERVER_DISCONNECT: {
607 bluetooth_device_address_t address = { {0} };
609 address = g_array_index(in_param1,
610 bluetooth_device_address_t, 0);
612 result = _bt_network_server_disconnect(request_id, &address);
613 if (result != BLUETOOTH_ERROR_NONE) {
614 g_array_append_vals(*out_param1, &address,
615 sizeof(bluetooth_device_address_t));
620 case BT_AUDIO_CONNECT: {
621 bluetooth_device_address_t address = { {0} };
623 address = g_array_index(in_param1,
624 bluetooth_device_address_t, 0);
626 result = _bt_audio_connect(request_id, BT_AUDIO_ALL,
627 &address, out_param1);
630 case BT_AUDIO_DISCONNECT: {
631 bluetooth_device_address_t address = { {0} };
633 address = g_array_index(in_param1,
634 bluetooth_device_address_t, 0);
636 result = _bt_audio_disconnect(request_id, BT_AUDIO_ALL,
637 &address, out_param1);
640 case BT_AG_CONNECT: {
641 bluetooth_device_address_t address = { {0} };
643 address = g_array_index(in_param1,
644 bluetooth_device_address_t, 0);
646 result = _bt_audio_connect(request_id, BT_AUDIO_HSP,
647 &address, out_param1);
650 case BT_AG_DISCONNECT: {
651 bluetooth_device_address_t address = { {0} };
653 address = g_array_index(in_param1,
654 bluetooth_device_address_t, 0);
656 result = _bt_audio_disconnect(request_id, BT_AUDIO_HSP,
657 &address, out_param1);
660 case BT_AV_CONNECT: {
661 bluetooth_device_address_t address = { {0} };
663 address = g_array_index(in_param1,
664 bluetooth_device_address_t, 0);
666 result = _bt_audio_connect(request_id, BT_AUDIO_A2DP,
667 &address, out_param1);
670 case BT_AV_DISCONNECT: {
671 bluetooth_device_address_t address = { {0} };
673 address = g_array_index(in_param1,
674 bluetooth_device_address_t, 0);
676 result = _bt_audio_disconnect(request_id, BT_AUDIO_A2DP,
677 &address, out_param1);
680 case BT_AVRCP_CONTROL_CONNECT: {
681 bluetooth_device_address_t address = { {0} };
683 address = g_array_index(in_param1,
684 bluetooth_device_address_t, 0);
686 result = _bt_audio_connect(request_id, BT_AVRCP,
687 &address, out_param1);
690 case BT_AVRCP_CONTROL_DISCONNECT: {
691 bluetooth_device_address_t address = { {0} };
693 address = g_array_index(in_param1,
694 bluetooth_device_address_t, 0);
696 result = _bt_audio_disconnect(request_id, BT_AVRCP,
697 &address, out_param1);
700 case BT_HF_CONNECT: {
701 bluetooth_device_address_t address = { {0} };
703 address = g_array_index(in_param1,
704 bluetooth_device_address_t, 0);
706 result = _bt_hf_connect(request_id, &address, out_param1);
709 case BT_HF_DISCONNECT: {
710 bluetooth_device_address_t address = { {0} };
712 address = g_array_index(in_param1,
713 bluetooth_device_address_t, 0);
715 result = _bt_hf_disconnect(request_id, &address, out_param1);
718 case BT_GET_SPEAKER_GAIN: {
721 result = _bt_audio_get_speaker_gain(&volume);
723 g_array_append_vals(*out_param1, &volume,
724 sizeof(unsigned int));
727 case BT_SET_SPEAKER_GAIN: {
730 volume = g_array_index(in_param1,
733 result = _bt_audio_set_speaker_gain(volume);
737 case BT_SET_CONTENT_PROTECT: {
740 status = g_array_index(in_param1, gboolean, 0);
742 result = _bt_audio_set_content_protect(status);
746 case BT_OOB_READ_LOCAL_DATA: {
747 bt_oob_data_t local_oob_data;
749 memset(&local_oob_data, 0x00, sizeof(bt_oob_data_t));
750 result = _bt_oob_read_local_data(&local_oob_data);
752 g_array_append_vals(*out_param1, &local_oob_data,
753 sizeof(bt_oob_data_t));
757 case BT_OOB_ADD_REMOTE_DATA: {
758 bluetooth_device_address_t address = { {0} };
759 bt_oob_data_t local_oob_data;
761 address = g_array_index(in_param1,
762 bluetooth_device_address_t, 0);
764 local_oob_data = g_array_index(in_param2,
767 result = _bt_oob_add_remote_data(&address, &local_oob_data);
771 case BT_OOB_REMOVE_REMOTE_DATA: {
772 bluetooth_device_address_t address = { {0} };
774 address = g_array_index(in_param1,
775 bluetooth_device_address_t, 0);
777 result = _bt_oob_remove_remote_data(&address);
781 case BT_AVRCP_SET_TRACK_INFO: {
782 media_metadata_t data;
783 media_metadata_attributes_t meta_data;
785 memset(&data, 0x00, sizeof(media_metadata_t));
786 memset(&meta_data, 0x00, sizeof(media_metadata_attributes_t));
788 data = g_array_index(in_param1,
789 media_metadata_t, 0);
791 meta_data.title = g_strdup(data.title);
792 meta_data.artist = g_strdup(data.artist);
793 meta_data.album = g_strdup(data.album);
794 meta_data.genre = g_strdup(data.genre);
795 meta_data.total_tracks = data.total_tracks;
796 meta_data.number = data.number;
797 meta_data.duration = (int64_t) data.duration;
799 result = _bt_avrcp_set_track_info(&meta_data);
801 g_free((gpointer)meta_data.title);
802 g_free((gpointer)meta_data.artist);
803 g_free((gpointer)meta_data.album);
804 g_free((gpointer)meta_data.genre);
808 case BT_AVRCP_SET_PROPERTY: {
812 type = g_array_index(in_param1, int, 0);
813 value = g_array_index(in_param2, unsigned int, 0);
815 result = _bt_avrcp_set_property(type, value);
819 case BT_AVRCP_SET_PROPERTIES: {
820 media_player_settings_t properties;
822 memset(&properties, 0x00, sizeof(media_player_settings_t));
824 properties = g_array_index(in_param1,
825 media_player_settings_t, 0);
827 result = _bt_avrcp_set_properties(&properties);
831 case BT_AVRCP_HANDLE_CONTROL: {
834 type = g_array_index(in_param1,
837 result = _bt_avrcp_control_cmd(type);
841 case BT_AVRCP_CONTROL_SET_PROPERTY: {
845 type = g_array_index(in_param1, int, 0);
846 value = g_array_index(in_param2, unsigned int, 0);
848 result = _bt_avrcp_control_set_property(type, value);
852 case BT_AVRCP_CONTROL_GET_PROPERTY: {
856 type = g_array_index(in_param1,
859 result = _bt_avrcp_control_get_property(type, &value);
860 g_array_append_vals(*out_param1, &value, sizeof(int));
864 case BT_AVRCP_GET_TRACK_INFO: {
865 media_metadata_t meta_data;
866 media_metadata_attributes_t metadata;
868 memset(&meta_data, 0x00, sizeof(media_metadata_t));
869 memset(&metadata, 0x00, sizeof(media_metadata_attributes_t));
871 result = _bt_avrcp_control_get_track_info(&metadata);
873 if (BLUETOOTH_ERROR_NONE != result)
876 if (_bt_copy_utf8_string(meta_data.title, metadata.title,
877 BT_META_DATA_MAX_LEN))
878 BT_ERR("Error in copying Title\n");
879 if (_bt_copy_utf8_string(meta_data.artist, metadata.artist,
880 BT_META_DATA_MAX_LEN))
881 BT_ERR("Error in copying Artist\n");
882 if (_bt_copy_utf8_string(meta_data.album, metadata.album,
883 BT_META_DATA_MAX_LEN))
884 BT_ERR("Error in copying Album\n");
885 if (_bt_copy_utf8_string(meta_data.genre, metadata.genre,
886 BT_META_DATA_MAX_LEN))
887 BT_ERR("Error in copying Genre\n");
889 if (_bt_utf8_validate(meta_data.title) == FALSE)
890 meta_data.title[0] = '\0';
892 if (_bt_utf8_validate(meta_data.artist) == FALSE)
893 meta_data.artist[0] = '\0';
895 if (_bt_utf8_validate(meta_data.album) == FALSE)
896 meta_data.album[0] = '\0';
898 if (_bt_utf8_validate(meta_data.genre) == FALSE)
899 meta_data.genre[0] = '\0';
901 meta_data.total_tracks = metadata.total_tracks;
902 meta_data.number = metadata.number;
903 meta_data.duration = metadata.duration;
905 g_free((gpointer)metadata.title);
906 g_free((gpointer)metadata.artist);
907 g_free((gpointer)metadata.album);
908 g_free((gpointer)metadata.genre);
910 g_array_append_vals(*out_param1, &meta_data,
911 sizeof(media_metadata_t));
914 case BT_RFCOMM_CLIENT_CONNECT: {
916 result = BLUETOOTH_ERROR_NONE;
918 bluetooth_device_address_t address = { {0} };
922 address = g_array_index(in_param1,
923 bluetooth_device_address_t, 0);
925 input_string = &g_array_index(in_param2, char, 0);
927 connect_type = g_array_index(in_param3, int, 0);
929 if (connect_type == BT_RFCOMM_UUID) {
930 result = _bt_rfcomm_connect_using_uuid(request_id,
931 &address, input_string);
933 result = _bt_rfcomm_connect_using_channel(request_id,
934 &address, input_string);
937 if (result != BLUETOOTH_ERROR_NONE) {
938 g_array_append_vals(*out_param1, &address,
939 sizeof(bluetooth_device_address_t));
944 case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
945 result = _bt_rfcomm_cancel_connect();
947 case BT_RFCOMM_CLIENT_IS_CONNECTED: {
948 gboolean connected = FALSE;
949 result = _bt_rfcomm_is_connected(&connected);
951 g_array_append_vals(*out_param1, &connected, sizeof(gboolean));
954 case BT_RFCOMM_SOCKET_DISCONNECT: {
956 result = BLUETOOTH_ERROR_NONE;
960 socket_fd = g_array_index(in_param1, int, 0);
962 result = _bt_rfcomm_disconnect(socket_fd);
966 case BT_RFCOMM_SOCKET_WRITE: {
968 result = BLUETOOTH_ERROR_NONE;
974 socket_fd = g_array_index(in_param1, int, 0);
975 length = g_array_index(in_param2, int, 0);
976 buffer = &g_array_index(in_param3, char, 0);
978 result = _bt_rfcomm_write(socket_fd, buffer, length);
982 case BT_RFCOMM_CREATE_SOCKET: {
984 result = BLUETOOTH_ERROR_NONE;
990 sender = dbus_g_method_get_sender(context);
991 uuid = &g_array_index(in_param1, char, 0);
993 result = _bt_rfcomm_create_socket(sender, uuid);
997 result = BLUETOOTH_ERROR_NONE;
1000 g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1006 case BT_RFCOMM_REMOVE_SOCKET: {
1007 #ifdef RFCOMM_DIRECT
1008 result = BLUETOOTH_ERROR_NONE;
1012 socket_fd = g_array_index(in_param1, int, 0);
1014 result = _bt_rfcomm_remove_socket(socket_fd);
1018 case BT_RFCOMM_LISTEN: {
1023 socket_fd = g_array_index(in_param1, int, 0);
1024 pending = g_array_index(in_param2, int, 0);
1025 is_native = g_array_index(in_param3, gboolean, 0);
1027 result = _bt_rfcomm_listen(socket_fd, pending, is_native);
1030 case BT_RFCOMM_IS_UUID_AVAILABLE: {
1031 gboolean available = TRUE;
1034 uuid = &g_array_index(in_param1, char, 0);
1036 result = _bt_rfcomm_is_uuid_available(uuid, &available);
1038 g_array_append_vals(*out_param1, &available, sizeof(gboolean));
1041 case BT_RFCOMM_ACCEPT_CONNECTION: {
1044 socket_fd = g_array_index(in_param1, int, 0);
1045 BT_DBG(" socket fd %d", socket_fd);
1046 result = _bt_rfcomm_accept_connection();
1049 case BT_RFCOMM_REJECT_CONNECTION: {
1052 socket_fd = g_array_index(in_param1, int, 0);
1053 BT_DBG(" socket fd %d", socket_fd);
1054 result = _bt_rfcomm_reject_connection();
1057 case BT_CONNECT_LE: {
1058 bluetooth_device_address_t address = { {0} };
1059 gboolean auto_connect;
1061 address = g_array_index(in_param1,
1062 bluetooth_device_address_t, 0);
1064 auto_connect = g_array_index(in_param2,
1067 result = _bt_connect_le_device(&address, auto_connect);
1071 case BT_DISCONNECT_LE: {
1072 bluetooth_device_address_t address = { {0} };
1074 address = g_array_index(in_param1,
1075 bluetooth_device_address_t, 0);
1077 result = _bt_disconnect_le_device(&address);
1081 case BT_SET_LE_PRIVACY: {
1082 gboolean set_privacy;
1084 set_privacy = g_array_index(in_param1, gboolean, 0);
1086 result = _bt_set_le_privacy(set_privacy);
1090 case BT_HDP_CONNECT:
1091 case BT_HDP_DISCONNECT:
1092 case BT_HDP_SEND_DATA:
1094 case BT_GATT_GET_PRIMARY_SERVICES:
1095 case BT_GATT_DISCOVER_CHARACTERISTICS:
1096 case BT_GATT_SET_PROPERTY_REQUEST:
1097 case BT_GATT_READ_CHARACTERISTIC:
1098 case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
1099 /* Just call to check the privilege */
1102 result = BLUETOOTH_ERROR_INTERNAL;
1109 static int __bt_obexd_request(int function_name,
1112 DBusGMethodInvocation *context,
1117 GArray **out_param1)
1123 BT_DBG("function_name : %x", function_name);
1125 switch (function_name) {
1126 case BT_OPP_PUSH_FILES: {
1127 BT_DBG("BT_OPP_PUSH_FILES");
1129 bluetooth_device_address_t address = { {0} };
1130 bt_file_path_t path;
1134 address = g_array_index(in_param1,
1135 bluetooth_device_address_t, 0);
1137 file_count = g_array_index(in_param3, int, 0);
1139 file_path = g_new0(char *, file_count + 1);
1141 for (i = 0; i < file_count; i++) {
1142 path = g_array_index(in_param2,
1145 file_path[i] = g_strdup(path.path);
1147 BT_DBG("_bt_opp_client_push_files");
1148 result = _bt_opp_client_push_files(request_id, context,
1149 &address, file_path,
1152 for (i = 0; i < file_count; i++) {
1153 g_free(file_path[i]);
1160 case BT_OPP_CANCEL_PUSH: {
1161 result = _bt_opp_client_cancel_push();
1165 case BT_OPP_IS_PUSHING_FILES: {
1166 gboolean is_sending = FALSE;
1168 result = _bt_opp_client_is_sending(&is_sending);
1170 g_array_append_vals(*out_param1, &is_sending,
1174 case BT_OBEX_SERVER_ALLOCATE: {
1180 sender = dbus_g_method_get_sender(context);
1181 path = &g_array_index(in_param1, char, 0);
1182 is_native = g_array_index(in_param2, gboolean, 0);
1183 app_pid = g_array_index(in_param3, int, 0);
1185 result = _bt_obex_server_allocate(sender, path, app_pid, is_native);
1190 case BT_OBEX_SERVER_DEALLOCATE: {
1194 is_native = g_array_index(in_param1, gboolean, 0);
1195 app_pid = g_array_index(in_param2, int, 0);
1197 result = _bt_obex_server_deallocate(app_pid, is_native);
1200 case BT_OBEX_SERVER_IS_ACTIVATED: {
1201 gboolean is_activated = FALSE;
1203 result = _bt_obex_server_is_activated(&is_activated);
1205 g_array_append_vals(*out_param1, &is_activated,
1210 case BT_OBEX_SERVER_ACCEPT_CONNECTION: {
1211 result = _bt_obex_server_accept_connection(request_id);
1215 case BT_OBEX_SERVER_REJECT_CONNECTION: {
1216 result = _bt_obex_server_reject_connection();
1220 case BT_OBEX_SERVER_ACCEPT_FILE: {
1223 file_name = &g_array_index(in_param1, char, 0);
1225 result = _bt_obex_server_accept_authorize(file_name, TRUE);
1229 case BT_OBEX_SERVER_REJECT_FILE: {
1230 result = _bt_obex_server_reject_authorize();
1234 case BT_OBEX_SERVER_SET_PATH: {
1236 char *destination_path;
1238 destination_path = &g_array_index(in_param1, char, 0);
1239 is_native = g_array_index(in_param2, gboolean, 0);
1241 result = _bt_obex_server_set_destination_path(destination_path,
1246 case BT_OBEX_SERVER_SET_ROOT: {
1249 root = &g_array_index(in_param1, char, 0);
1251 result = _bt_obex_server_set_root(root);
1255 case BT_OBEX_SERVER_CANCEL_TRANSFER: {
1258 transfer_id = g_array_index(in_param1, int, 0);
1260 result = _bt_obex_server_cancel_transfer(transfer_id);
1264 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS: {
1265 result = _bt_obex_server_cancel_all_transfers();
1269 case BT_OBEX_SERVER_IS_RECEIVING: {
1270 gboolean is_receiving = FALSE;
1272 result = _bt_obex_server_is_receiving(&is_receiving);
1274 g_array_append_vals(*out_param1, &is_receiving,
1278 case BT_PBAP_CONNECT: {
1279 bluetooth_device_address_t address = { {0} };
1281 address = g_array_index(in_param1,
1282 bluetooth_device_address_t, 0);
1284 result = _bt_pbap_connect(&address);
1287 case BT_PBAP_DISCONNECT: {
1288 bluetooth_device_address_t address = { {0} };
1290 address = g_array_index(in_param1,
1291 bluetooth_device_address_t, 0);
1293 result = _bt_pbap_disconnect(&address);
1296 case BT_PBAP_GET_PHONEBOOK_SIZE: {
1297 bluetooth_device_address_t address = { {0} };
1298 bt_pbap_folder_t folder = { 0, };
1300 address = g_array_index(in_param1, bluetooth_device_address_t, 0);
1301 folder = g_array_index(in_param2, bt_pbap_folder_t, 0);
1303 result = _bt_pbap_get_phonebook_size(&address, folder.addressbook,
1304 folder.folder_type);
1307 case BT_PBAP_GET_PHONEBOOK: {
1308 bluetooth_device_address_t address = { {0} };
1309 bt_pbap_folder_t folder = { 0, };
1310 bt_pbap_pull_parameters_t app_param = { 0, };
1312 address = g_array_index(in_param1, bluetooth_device_address_t, 0);
1313 folder = g_array_index(in_param2, bt_pbap_folder_t, 0);
1314 app_param = g_array_index(in_param3, bt_pbap_pull_parameters_t, 0);
1316 result = _bt_pbap_get_phonebook(&address, folder.addressbook,
1317 folder.folder_type, &app_param);
1320 case BT_PBAP_GET_LIST: {
1321 bluetooth_device_address_t address = { {0} };
1322 bt_pbap_folder_t folder = { 0, };
1323 bt_pbap_list_parameters_t app_param = { 0, };
1325 address = g_array_index(in_param1, bluetooth_device_address_t, 0);
1326 folder = g_array_index(in_param2, bt_pbap_folder_t, 0);
1327 app_param = g_array_index(in_param3, bt_pbap_list_parameters_t, 0);
1329 result = _bt_pbap_get_list(&address, folder.addressbook,
1330 folder.folder_type, &app_param);
1333 case BT_PBAP_PULL_VCARD: {
1334 bluetooth_device_address_t address = { {0} };
1335 bt_pbap_folder_t folder = { 0, };
1336 bt_pbap_pull_vcard_parameters_t app_param = { 0, };
1338 address = g_array_index(in_param1, bluetooth_device_address_t, 0);
1339 folder = g_array_index(in_param2, bt_pbap_folder_t, 0);
1340 app_param = g_array_index(in_param3, bt_pbap_pull_vcard_parameters_t, 0);
1342 result = _bt_pbap_pull_vcard(&address, folder.addressbook,
1343 folder.folder_type, &app_param);
1346 case BT_PBAP_PHONEBOOK_SEARCH: {
1347 bluetooth_device_address_t address = { {0} };
1348 bt_pbap_folder_t folder = { 0, };
1349 bt_pbap_search_parameters_t app_param = { 0, };
1351 address = g_array_index(in_param1, bluetooth_device_address_t, 0);
1352 folder = g_array_index(in_param2, bt_pbap_folder_t, 0);
1353 app_param = g_array_index(in_param3, bt_pbap_search_parameters_t, 0);
1355 result = _bt_pbap_phonebook_search(&address, folder.addressbook,
1356 folder.folder_type, &app_param);
1361 BT_ERR("Unknown function!");
1362 result = BLUETOOTH_ERROR_INTERNAL;
1371 static int __bt_agent_request(int function_name,
1374 DBusGMethodInvocation *context,
1379 GArray **out_param1)
1382 switch(function_name) {
1383 case BT_SET_AUTHORIZATION: {
1389 type = g_array_index(in_param1, int, 0);
1390 uuid = &g_array_index(in_param2, char, 0);
1391 path = &g_array_index(in_param3, char, 0);
1392 fd = g_array_index(in_param4, int, 0);
1393 result = _bt_register_osp_server_in_agent(type, uuid, path, fd);
1396 case BT_UNSET_AUTHORIZATION: {
1399 type = g_array_index(in_param1, int, 0);
1400 uuid = &g_array_index(in_param2, char, 0);
1401 result = _bt_unregister_osp_server_in_agent(type, uuid);
1405 BT_ERR("Unknown function!");
1406 result = BLUETOOTH_ERROR_INTERNAL;
1413 static int __bt_core_request(int function_name,
1416 DBusGMethodInvocation *context,
1421 switch (function_name) {
1422 case BT_ENABLE_ADAPTER:
1426 status = _bt_adapter_get_status();
1428 if (status == BT_ACTIVATING) {
1429 BT_DBG("Enabling in progress");
1430 result = BLUETOOTH_ERROR_IN_PROGRESS;
1431 } else if (status == BT_ACTIVATED) {
1432 BT_DBG("Already enabled");
1433 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
1435 _bt_adapter_set_status(BT_ACTIVATING);
1436 _bt_adapter_start_enable_timer();
1437 result = BLUETOOTH_ERROR_NONE;
1442 case BT_DISABLE_ADAPTER:
1446 status = _bt_adapter_get_status();
1447 if (status == BT_DEACTIVATING) {
1448 BT_DBG("Disabling in progress");
1449 result = BLUETOOTH_ERROR_IN_PROGRESS;
1451 else if (status == BT_DEACTIVATED) {
1452 BT_DBG("Already disabled");
1453 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
1457 _bt_adapter_set_status(BT_DEACTIVATING);
1458 result = BLUETOOTH_ERROR_NONE;
1463 case BT_ENABLE_ADAPTER_LE:
1465 bt_le_status_t le_status;
1467 le_status = _bt_adapter_get_le_status();
1468 if (le_status == BT_LE_ACTIVATING) {
1469 BT_DBG("Enabling in progress");
1470 result = BLUETOOTH_ERROR_IN_PROGRESS;
1472 else if (le_status == BT_LE_ACTIVATED) {
1473 BT_DBG("Already enabled");
1474 result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
1476 _bt_adapter_set_le_status(BT_LE_ACTIVATING);
1477 _bt_adapter_start_le_enable_timer();
1478 result = BLUETOOTH_ERROR_NONE;
1483 case BT_DISABLE_ADAPTER_LE:
1485 bt_le_status_t le_status;
1487 le_status = _bt_adapter_get_le_status();
1488 if (le_status == BT_LE_DEACTIVATING) {
1489 BT_DBG("Disabling in progress");
1490 result = BLUETOOTH_ERROR_IN_PROGRESS;
1492 else if (le_status == BT_LE_DEACTIVATED) {
1493 BT_DBG("Already disabled");
1494 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
1498 _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
1499 result = BLUETOOTH_ERROR_NONE;
1505 BT_ERR("Unknown function!");
1506 result = BLUETOOTH_ERROR_INTERNAL;
1513 gboolean __bt_service_check_privilege(int function_name,
1519 gboolean result = TRUE;
1521 cookie = (const char *)&g_array_index(in_param5, char, 0);
1523 retv_if(cookie == NULL, FALSE);
1525 switch (function_name) {
1526 case BT_SET_LOCAL_NAME:
1527 case BT_START_DISCOVERY:
1528 case BT_START_CUSTOM_DISCOVERY:
1529 case BT_CANCEL_DISCOVERY:
1530 case BT_OOB_ADD_REMOTE_DATA:
1531 case BT_OOB_REMOVE_REMOTE_DATA:
1532 case BT_SET_ADVERTISING:
1533 case BT_SET_CUSTOM_ADVERTISING:
1534 case BT_START_LE_DISCOVERY:
1535 case BT_STOP_LE_DISCOVERY:
1537 case BT_BOND_DEVICE:
1538 case BT_CANCEL_BONDING:
1539 case BT_UNBOND_DEVICE:
1541 case BT_SET_AUTHORIZATION:
1542 case BT_UNSET_AUTHORIZATION:
1543 case BT_SEARCH_SERVICE:
1545 case BT_RFCOMM_CLIENT_CONNECT:
1546 case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
1547 case BT_RFCOMM_SOCKET_DISCONNECT:
1548 case BT_RFCOMM_SOCKET_WRITE:
1549 case BT_RFCOMM_CREATE_SOCKET:
1550 case BT_RFCOMM_REMOVE_SOCKET:
1552 case BT_OPP_PUSH_FILES:
1553 case BT_OPP_CANCEL_PUSH:
1555 case BT_OBEX_SERVER_ACCEPT_CONNECTION:
1556 case BT_OBEX_SERVER_REJECT_CONNECTION:
1557 case BT_OBEX_SERVER_ACCEPT_FILE:
1558 case BT_OBEX_SERVER_REJECT_FILE:
1559 case BT_OBEX_SERVER_SET_PATH:
1560 case BT_OBEX_SERVER_SET_ROOT:
1561 case BT_OBEX_SERVER_CANCEL_TRANSFER:
1562 case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS:
1564 case BT_AUDIO_CONNECT:
1565 case BT_AUDIO_DISCONNECT:
1567 case BT_AG_DISCONNECT:
1569 case BT_AV_DISCONNECT:
1570 case BT_AVRCP_CONTROL_CONNECT:
1571 case BT_AVRCP_CONTROL_DISCONNECT:
1573 case BT_HF_DISCONNECT:
1575 case BT_HID_CONNECT:
1576 case BT_HID_DISCONNECT:
1579 case BT_DISCONNECT_LE:
1581 case BT_SET_ADVERTISING_DATA:
1582 case BT_SET_SCAN_RESPONSE_DATA:
1584 case BT_HDP_CONNECT:
1585 case BT_HDP_DISCONNECT:
1586 case BT_HDP_SEND_DATA:
1588 case BT_NETWORK_ACTIVATE:
1589 case BT_NETWORK_DEACTIVATE:
1590 case BT_NETWORK_CONNECT:
1591 case BT_NETWORK_DISCONNECT:
1592 case BT_NETWORK_SERVER_DISCONNECT:
1594 case BT_GATT_GET_PRIMARY_SERVICES:
1595 case BT_GATT_DISCOVER_CHARACTERISTICS:
1596 case BT_GATT_SET_PROPERTY_REQUEST:
1597 case BT_GATT_READ_CHARACTERISTIC:
1598 case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
1600 ret_val = security_server_check_privilege_by_cookie(cookie,
1601 BT_PRIVILEGE_PUBLIC, "w");
1602 if (ret_val == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1603 BT_ERR("[SMACK] Fail to access: %s", BT_PRIVILEGE_PUBLIC);
1608 case BT_ENABLE_ADAPTER:
1609 case BT_DISABLE_ADAPTER:
1610 case BT_RESET_ADAPTER:
1611 case BT_RECOVER_ADAPTER:
1612 case BT_ENABLE_ADAPTER_LE:
1613 case BT_DISABLE_ADAPTER_LE:
1614 case BT_SET_CONNECTABLE:
1615 case BT_SET_DISCOVERABLE_MODE:
1616 case BT_ADD_WHITE_LIST:
1617 case BT_REMOVE_WHITE_LIST:
1618 case BT_CLEAR_WHITE_LIST:
1619 case BT_SET_MANUFACTURER_DATA:
1620 case BT_SET_SCAN_PARAMETERS:
1622 case BT_CANCEL_SEARCH_SERVICE:
1623 case BT_ENABLE_RSSI:
1625 case BT_RFCOMM_ACCEPT_CONNECTION:
1626 case BT_RFCOMM_REJECT_CONNECTION:
1627 case BT_RFCOMM_LISTEN:
1629 case BT_AVRCP_SET_TRACK_INFO:
1630 case BT_AVRCP_SET_PROPERTY:
1631 case BT_AVRCP_SET_PROPERTIES:
1632 case BT_AVRCP_HANDLE_CONTROL:
1633 case BT_AVRCP_CONTROL_SET_PROPERTY:
1634 case BT_AVRCP_CONTROL_GET_PROPERTY:
1635 case BT_AVRCP_GET_TRACK_INFO:
1637 case BT_SET_CONTENT_PROTECT:
1638 case BT_BOND_DEVICE_BY_TYPE:
1639 case BT_SET_LE_PRIVACY:
1640 case BT_LE_CONN_UPDATE:
1642 ret_val = security_server_check_privilege_by_cookie(cookie,
1643 BT_PRIVILEGE_PLATFORM, "w");
1645 if (ret_val == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
1646 BT_ERR("[SMACK] Fail to access: %s", BT_PRIVILEGE_PLATFORM);
1651 case BT_CHECK_ADAPTER:
1654 case BT_GET_LOCAL_NAME:
1655 case BT_GET_LOCAL_ADDRESS:
1656 case BT_GET_LOCAL_VERSION:
1657 case BT_IS_SERVICE_USED:
1658 case BT_GET_DISCOVERABLE_MODE:
1659 case BT_GET_DISCOVERABLE_TIME:
1660 case BT_IS_DISCOVERYING:
1661 case BT_IS_LE_DISCOVERYING:
1662 case BT_IS_CONNECTABLE:
1663 case BT_GET_BONDED_DEVICES:
1664 case BT_GET_BONDED_DEVICE:
1665 case BT_IS_DEVICE_CONNECTED:
1666 case BT_GET_SPEAKER_GAIN:
1667 case BT_SET_SPEAKER_GAIN:
1668 case BT_OOB_READ_LOCAL_DATA:
1669 case BT_RFCOMM_CLIENT_IS_CONNECTED:
1670 case BT_RFCOMM_IS_UUID_AVAILABLE:
1671 case BT_GET_ADVERTISING_DATA:
1672 case BT_GET_SCAN_RESPONSE_DATA:
1673 case BT_IS_ADVERTISING:
1675 case BT_OBEX_SERVER_ALLOCATE:
1676 case BT_OBEX_SERVER_DEALLOCATE:
1678 /* Non-privilege control */
1681 BT_ERR("Unknown function!");
1689 gboolean bt_service_request(
1692 int service_function,
1699 DBusGMethodInvocation *context)
1704 int request_id = -1;
1705 GArray *out_param1 = NULL;
1706 GArray *out_param2 = NULL;
1708 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
1709 out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
1711 if (service_type == BT_CORE_SERVICE) {
1712 BT_DBG("No need to check privilege from bt-core");
1714 else if (__bt_service_check_privilege(service_function,
1715 service_type, in_param5) == FALSE) {
1716 result = BLUETOOTH_ERROR_PERMISSION_DEINED;
1720 if (request_type == BT_ASYNC_REQ
1721 || service_function == BT_OBEX_SERVER_ACCEPT_CONNECTION) {
1723 request_id = _bt_assign_request_id();
1724 BT_DBG("Request ID: %d", request_id);
1726 if (request_id < 0) {
1727 BT_ERR("Fail to assign the request id");
1728 result = BLUETOOTH_ERROR_INTERNAL;
1733 BT_DBG("SERVICE TYPE %d", service_type);
1735 switch (service_type) {
1736 case BT_BLUEZ_SERVICE:
1737 result = __bt_bluez_request(service_function, request_type,
1738 request_id, context, in_param1, in_param2,
1739 in_param3, in_param4, &out_param1);
1741 case BT_OBEX_SERVICE:
1742 result = __bt_obexd_request(service_function, request_type,
1743 request_id, context, in_param1,
1744 in_param2, in_param3,
1745 in_param4, &out_param1);
1747 case BT_AGENT_SERVICE:
1748 result = __bt_agent_request(service_function, request_type,
1749 request_id, context, in_param1,
1750 in_param2, in_param3,
1751 in_param4, &out_param1);
1753 case BT_CORE_SERVICE:
1754 result = __bt_core_request(service_function, request_type,
1755 request_id, context, in_param1);
1757 case BT_CHECK_PRIVILEGE:
1758 result = BLUETOOTH_ERROR_NONE;
1761 BT_ERR("Unknown service type");
1762 result = BLUETOOTH_ERROR_INTERNAL;
1766 if (result != BLUETOOTH_ERROR_NONE) {
1770 g_array_append_vals(out_param2, &result, sizeof(int));
1772 if ((request_type == BT_ASYNC_REQ ||
1773 service_function == BT_OBEX_SERVER_ACCEPT_CONNECTION) &&
1774 service_function != BT_OPP_PUSH_FILES) {
1775 _bt_insert_request_list(request_id, service_function,
1779 if (service_type == BT_CHECK_PRIVILEGE ||
1780 service_function != BT_OPP_PUSH_FILES)
1781 dbus_g_method_return(context, out_param1, out_param2);
1784 g_array_free(out_param1, TRUE);
1785 g_array_free(out_param2, TRUE);
1789 BT_ERR_C("Request is failed [%s] [%x]", _bt_convert_error_to_string(result), result);
1790 g_array_append_vals(out_param2, &result, sizeof(int));
1791 dbus_g_method_return(context, out_param1, out_param2);
1793 g_array_free(out_param1, TRUE);
1794 g_array_free(out_param2, TRUE);
1796 if (request_type == BT_ASYNC_REQ)
1797 _bt_delete_request_id(request_id);
1804 int _bt_service_register(void)
1806 BtService *bt_service;
1807 DBusGConnection *conn;
1812 conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
1813 retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
1815 proxy = dbus_g_proxy_new_for_name(conn, DBUS_SERVICE_DBUS,
1816 DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
1818 if (proxy == NULL) {
1819 BT_ERR("proxy is NULL");
1823 if (!dbus_g_proxy_call(proxy, "RequestName", &err, G_TYPE_STRING,
1824 BT_SERVICE_NAME, G_TYPE_UINT, 0, G_TYPE_INVALID,
1825 G_TYPE_UINT, &result, G_TYPE_INVALID)) {
1827 BT_ERR("RequestName RPC failed[%s]\n", err->message);
1830 g_object_unref(proxy);
1835 g_object_unref(proxy);
1837 if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
1838 BT_ERR("Failed to get the primary well-known name.\n");
1842 bt_service = g_object_new(BT_SERVICE_TYPE, NULL);
1844 dbus_g_connection_register_g_object(conn, BT_SERVICE_PATH,
1845 G_OBJECT(bt_service));
1847 service_object = bt_service;
1848 bt_service_conn = conn;
1850 return BLUETOOTH_ERROR_NONE;
1853 if (bt_service_conn) {
1854 dbus_g_connection_unref(bt_service_conn);
1855 bt_service_conn = NULL;
1858 return BLUETOOTH_ERROR_INTERNAL;
1861 void _bt_service_unregister(void)
1863 if (bt_service_conn) {
1864 if (service_object) {
1865 dbus_g_connection_unregister_g_object(bt_service_conn,
1866 G_OBJECT(service_object));
1867 g_object_unref(service_object);
1868 service_object = NULL;
1871 dbus_g_connection_unref(bt_service_conn);
1872 bt_service_conn = NULL;