ADD_SUBDIRECTORY(bt-api)
ADD_SUBDIRECTORY(bt-oal)
-ADD_SUBDIRECTORY(bt-service-adaptation)
+ADD_SUBDIRECTORY(bt-service)
IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_HTTP_PROXY")
#ADD_SUBDIRECTORY(bt-httpproxy)
+++ /dev/null
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(bt-service C)
-
-#Include Source files for bluetooth service common files only
-SET(SRCS
-../include/bt-internal-types.c
-./services/bt-service-main.c
-./services/bt-service-common.c
-./services/bt-service-event-sender.c
-./services/bt-service-battery-monitor.c
-./services/bt-service-util.c
-./services/bt-request-handler.c
-./services/adapter/bt-service-core-adapter.c
-./services/adapter/bt-service-core-adapter-le.c
-./services/device/bt-service-core-device.c
-./services/device/bt-service-bonded-device.c
-./services/bt-service-event-receiver.c
-./services/bt-service-dpm.c
-./services/bt-service-agent-util.c
-./services/hid/bt-service-hidhost.c
-./services/hid/bt-service-hiddevice.c
-./services/socket/bt-service-socket.c
-./services/rfcomm/bt-service-rfcomm.c
-./services/audio/bt-service-audio.c
-./services/audio/bt-service-headset-connection.c
-./services/audio/hf/bt-service-hf.c
-./services/audio/a2dp_src/bt-service-a2dp-src.c
-./services/audio/a2dp_sink/bt-service-a2dp-sink.c
-./services/health/bt-service-hdp.c
-./services/audio/avrcp/bt-service-avrcp-tg.c
-./services/audio/avrcp/bt-service-avrcp-ctrl.c
-./services/gatt/bt-service-gatt.c
-./services/audio/hf/bt-service-hf-client.c
-)
-
-IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_OBEX")
-LIST(APPEND SRCS ./services/obex/bt-service-obex-agent.c)
-LIST(APPEND SRCS ./services/obex/bt-service-obex-server.c)
-LIST(APPEND SRCS ./services/obex/bt-service-map-client.c)
-LIST(APPEND SRCS ./services/obex/bt-service-opp-client.c)
-LIST(APPEND SRCS ./services/obex/bt-service-pbap.c)
-LIST(APPEND SRCS ./services/obex/bt-service-obex-event-receiver.c)
-LIST(APPEND SRCS ./services/obex/bt-service-oob.c)
-ENDIF()
-
-IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_PAN_NAP")
-LIST(APPEND SRCS ./services/pan_nap/bt-service-pan-nap-event-receiver.c)
-LIST(APPEND SRCS ./services/pan_nap/bt-service-network.c)
-ENDIF()
-
-IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_IPSP")
-LIST(APPEND SRCS ./services/ipsp/bt-service-ipsp.c)
-LIST(APPEND SRCS ./services/ipsp/bt-service-ipsp-event-receiver.c)
-ENDIF()
-
-IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_AVC_TARGET")
-LIST(APPEND SRCS ./services/audio/bt-service-absolute-volume.c)
-ENDIF()
-
-IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
- SET(CMAKE_BUILD_TYPE "Release")
-ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
-
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/services/include)
-IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_OBEX")
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/services/obex/include)
-ENDIF()
-IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_PAN_NAP")
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/services/pan_nap/include)
-ENDIF()
-IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_IPSP")
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/services/ipsp/include)
-ENDIF()
-
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../bt-oal/include)
-LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../bt-oal)
-
-IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_FACTORY_MODE")
-SET(PKG_MODULES
- vconf
- dbus-1
- gio-2.0
- gio-unix-2.0
- alarm-service
- capi-network-connection
- cynara-client
- cynara-creds-gdbus
- eventsystem
- storage
- capi-system-info
- libsystemd-daemon
- bincfg
-)
-ELSE()
-SET(PKG_MODULES
- vconf
- dbus-1
- gio-2.0
- gio-unix-2.0
- alarm-service
- capi-network-connection
- cynara-client
- cynara-creds-gdbus
- eventsystem
- storage
- capi-system-info
- libsystemd-daemon
-)
-ENDIF()
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(service_pkgs REQUIRED ${PKG_MODULES})
-
-FOREACH(flag ${service_pkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -Wall")
-ENDFOREACH(flag)
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-SET(CMAKE_C_FLAGS_RELEASE "-O2")
-SET(APP_SYSCONFDIR /opt/var/lib/bluetooth)
-
-FIND_PROGRAM(UNAME NAMES uname)
-EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
-IF("${ARCH}" STREQUAL "arm")
- ADD_DEFINITIONS("-DTARGET")
- MESSAGE("add -DTARGET")
-ENDIF("${ARCH}" STREQUAL "arm")
-
-FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool)
-
-ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-ADD_DEFINITIONS("-DVENDOR=\"${APP_VENDOR}\"")
-ADD_DEFINITIONS("-DAPPNAME=\"${APP_NAME}\"")
-ADD_DEFINITIONS("-DAPP_DIR=\"${APP_DIR}\"")
-ADD_DEFINITIONS("-DAPP_LOCALEDIR=\"${APP_LOCALEDIR}\"")
-ADD_DEFINITIONS("-DAPP_SYSCONFDIR=\"${APP_SYSCONFDIR}\"")
-ADD_DEFINITIONS("-DHPS_FEATURE")
-ADD_DEFINITIONS("-DTIZEN_FEATURE_BT_DPM")
-
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
-
-ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${service_pkgs_LDFLAGS} bt-oal -ldl)
-
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.projectx.bt.service DESTINATION share/dbus-1/system-services)
-INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
-
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/auto-pair-blacklist DESTINATION /opt/var/lib/bluetooth/)
-
-# install booting script
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/bluetooth-frwk-service.conf.in ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth-frwk-service.conf)
-
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/wearable/stack_info DESTINATION /usr/etc/bluetooth/)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mobile/stack_info DESTINATION /usr/etc/bluetooth/)
-
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth-frwk-service.conf DESTINATION /etc/dbus-1/system.d)
-
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} -ldl)
-
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+++ /dev/null
-AddressBlacklist=00:02:C7,00:16:FE,00:19:C1,00:1B:FB,00:1E:3D,00:21:4F,00:23:06,00:24:33,00:A0:79,00:0E:6D,00:13:E0,00:21:E8,00:60:57,00:0E:9F,00:12:1C,00:18:91,00:18:96,00:13:04,00:16:FD,00:22:A0,00:0B:4C,00:60:6F,00:23:3D,00:C0:59,00:0A:30,00:1E:AE,00:1C:D7,00:80:F0,00:12:8A,00:09:93,00:80:37,00:26:7E,00:1A:1B,00:14:9A,00:0B:24,08:76:95,00:14:09,00:1E:B2\r
-ExactNameBlacklist=Motorola IHF1000,i.TechBlueBAND,X5 Stereo v1.3,KML_CAN,SYNC,UConnect\r
-PartialNameBlacklist=BMW,Audi,Parrot,HandsFreeLink,Car,MB PhoneSystem,CAR MULTIMEDIA,MB Bluetooth,Pama\r
-KeyboardAutoPair=00:0F:F6\r
+++ /dev/null
-#!/bin/sh
-
-#
-# Script for running BT Service during booting time
-#
-
-if [ -x /usr/bin/bt-service ]; then
- /usr/bin/bt-service &
-fi
+++ /dev/null
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
- <policy user="root">
- <allow own="org.projectx.bt"/>
- <allow send_destination="org.projectx.bt"/>
- <allow own="org.bluez.obex"/>
- <allow send_destination="org.bluez.obex"/>
- </policy>
- <policy group="network_fw">
- <allow own="org.projectx.bt"/>
- <allow send_destination="org.projectx.bt"/>
- <allow own="org.bluez.obex"/>
- <allow send_destination="org.bluez.obex"/>
- <allow own="org.projectx.bluetooth.share"/>
- <allow send_destination="org.projectx.bluetooth.share"/>
- <allow send_destination_prefix="org.tizen.csd.Call.Instance" send_interface="org.tizen.csd.Call.Instance" send_member="SendDtmf"/>
- <allow send_destination_prefix="org.tizen.csd.Call.Instance" send_interface="org.tizen.csd.Call.Instance" send_member="VendorCmd"/>
- </policy>
- <policy group="pulse">
- <allow send_destination="org.projectx.bt"/>
- </policy>
- <policy context="default">
- <deny own="org.projectx.bt"/>
- <deny send_destination="org.projectx.bt" send_type="method_call"/>
- <deny own="org.bluez.obex"/>
- <deny send_destination="org.bluez.obex" send_type="method_call"/>
- <allow send_destination="org.projectx.bt" send_interface="org.projectx.bt"/>
- <allow send_destination="org.projectx.bt" send_interface="org.freedesktop.DBus.Properties" send_member="GetAll"/>
- <check send_destination="org.projectx.bt" send_interface="org.bluez.Agent1" privilege="http://tizen.org/privilege/bluetooth.admin"/>
- <allow send_destination="org.projectx.bt" send_interface="org.bluez.obex.reply"/>
- <deny own="org.projectx.bluetooth.share"/>
- <deny send_destination="org.projectx.bluetooth.share"/>
- <deny own_prefix="org.tizen.csd.Call.Instance"/>
- <allow own_prefix="org.tizen.csd.Call.Instance"/>
- <deny send_destination_prefix="org.tizen.csd.Call.Instance" send_interface="org.tizen.csd.Call.Instance" send_member="SendDtmf"/>
- <deny send_destination_prefix="org.tizen.csd.Call.Instance" send_interface="org.tizen.csd.Call.Instance" send_member="VendorCmd"/>
- </policy>
-</busconfig>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<node name="/org/projectx/bt_service">
- <interface name="org.projectx.bt">
- <method name="service_request">
- <annotation name="org.freedesktop.DBus.GLib.Async" value="bt_service_request"/>
- <!-- INPUT PARAMS FOR SERVICE FUNCTION -->
- <arg type="i" name="service_type" direction="in" />
- <arg type="i" name="service_function" direction="in" />
- <arg type="i" name="request_type" direction="in" />
- <arg type="ay" name="input_param1" direction="in" />
- <arg type="ay" name="input_param2" direction="in" />
- <arg type="ay" name="input_param3" direction="in" />
- <arg type="ay" name="input_param4" direction="in" />
- <arg type="ay" name="input_param5" direction="in" />
- <!-- OUTPUT PARAMS FOR SERVICE FUNCTION -->
- <arg type="ay" name="output_param1" direction="out" />
- <arg type="ay" name="output_param2" direction="out" />
- </method>
- </interface>
-</node>
-
+++ /dev/null
-# DBUS Signal argument converting list for bluetooth frwk lib
-VOID:STRING
-VOID:STRING,UINT,INT
-VOID:STRING,STRING
-VOID:STRING,STRING,INT
-VOID:UINT
-VOID:STRING,STRING,INT,UINT
-VOID:STRING,VARIANT
-# for BlueZ4
-VOID:STRING,BOXED
-# for obex
-VOID:STRING,STRING,UINT64
-VOID:UINT64
-VOID:STRING,STRING,STRING
-# for obexd
-VOID:OBJECT,BOOLEAN
-VOID:INT,INT
-
+++ /dev/null
-Bluez 5.16,
-HFP AG 1.6
-HSP AG 1.2
-A2DP Source 1.2
-AVRCP Target 1.3
-GAVDP 1.2
-OPP 1.1
-PBAP PSE 1.1
-PAN NAP 1.0
-PAN USER 1.0
+++ /dev/null
-[D-BUS Service]
-Name=org.projectx.bt
-Exec=/bin/false
-SystemdService=bluetooth-frwk.service
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_MAIN_H_
-#define _BT_SERVICE_MAIN_H_
-
-#include <sys/types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-gboolean _bt_terminate_service(gpointer user_data);
-
-gboolean _bt_reliable_terminate_service(gpointer user_data);
-
-int _bt_service_initialize(void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_MAIN_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __STACKTRIM_H__
-#define __STACKTRIM_H__
-
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/mman.h>
-
-#define BUF_SIZE 256
-#define PAGE_SIZE (1 << 12)
-#define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1)))
-#define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1)))
-#define PAGE_ALIGN(addr) _ALIGN_DOWN(addr, PAGE_SIZE)
-
-static inline void stack_trim(void)
-{
-#ifdef STACK_FLUSH
- unsigned int sp;
- char buf[BUF_SIZE];
- FILE *file;
- unsigned int stacktop;
- int found = 0;
-
- asm volatile ("mov %0,sp " : "=r"(sp));
-
- sprintf(buf, "/proc/%d/maps", getpid());
- file = fopen(buf, "r");
- while (fgets(buf, BUF_SIZE, file) != NULL) {
- if (strstr(buf, "[stack]")) {
- found = 1;
- break;
- }
- }
- fclose(file);
-
- if (found) {
- sscanf(buf, "%x-", &stacktop);
- if (madvise((void *)PAGE_ALIGN(stacktop), PAGE_ALIGN(sp) - stacktop,
- MADV_DONTNEED) < 0)
- perror("stack madvise fail");
- }
-#endif
-}
-
-#endif /* __STACKTRIM_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_OPP_CLIENT_H_
-#define _BT_SERVICE_OPP_CLIENT_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include <gio/gio.h>
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define BT_OBEX_CLIENT_AGENT_PATH "/org/obex/client_agent"
-
-typedef enum {
- BT_TRANSFER_STATUS_QUEUED = 0x00,
- BT_TRANSFER_STATUS_STARTED,
- BT_TRANSFER_STATUS_PROGRESS,
- BT_TRANSFER_STATUS_COMPLETED,
-} bt_transfer_status_t;
-
-typedef struct {
- char path[BT_FILE_PATH_MAX];
-} bt_file_path_t;
-
-typedef struct {
- GDBusProxy *proxy;
- GDBusProxy *properties_proxy;
- char *transfer_name;
- char *file_name;
- char *transfer_path;
- bt_transfer_status_t transfer_status;
- gint64 size;
- guint64 progress;
-} bt_transfer_info_t;
-
-typedef struct {
- int request_id;
- int result;
-
- int file_count;
- int file_offset;
- char **file_name_array;
- char *session_path;
-
- char *address;
- gboolean is_canceled;
- bt_transfer_info_t *transfer_info;
-} bt_sending_info_t;
-
-typedef struct {
- char *address;
- char **file_path;
- int file_count;
- int request_id;
-} bt_sending_data_t;
-
-
-int _bt_opp_client_push_files(int request_id, GDBusMethodInvocation *context,
- bluetooth_device_address_t *remote_address,
- char **file_path, int file_count);
-
-int _bt_opp_client_cancel_push(void);
-
-int _bt_opp_client_cancel_all_transfers(void);
-
-int _bt_opp_client_is_sending(gboolean *sending);
-
-void _bt_sending_files(void);
-
-void _bt_opc_disconnected(const char *session_path);
-
-gboolean _bt_obex_client_progress(const char *transfer_path, guint64 transferred);
-
-gboolean _bt_obex_client_started(const char *transfer_path);
-
-gboolean _bt_obex_client_completed(const char *transfer_path, gboolean success);
-
-void _bt_opp_client_check_pending_transfer(const char *address);
-
-int _bt_opp_get_client_progress(guint8 *progress);
-
-void _bt_cancel_queued_transfers(void);
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_OPP_CLIENT_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef BT_SERVICE_PBAP_H
-#define BT_SERVICE_PBAP_H
-
-#include <stdint.h>
-#include <glib.h>
-#include <unistd.h>
-#include <dlog.h>
-#include <stdio.h>
-
-#undef LOG_TAG
-#define LOG_TAG "BLUETOOTH_FRWK_SERVICE"
-#define ERR(fmt, args...) SLOGE(fmt, ##args)
-
-int _bt_pbap_connect(const bluetooth_device_address_t *address);
-
-int _bt_pbap_disconnect(const bluetooth_device_address_t *address);
-
-int _bt_pbap_is_connected(bluetooth_device_address_t *device_address,
- gboolean *connected);
-
-int _bt_pbap_get_phonebook_size(const bluetooth_device_address_t *address,
- int source, int type);
-
-int _bt_pbap_get_phonebook(const bluetooth_device_address_t *address,
- int source, int type, bt_pbap_pull_parameters_t *app_param);
-
-int _bt_pbap_get_list(const bluetooth_device_address_t *address, int source,
- int type, bt_pbap_list_parameters_t *app_param);
-
-int _bt_pbap_pull_vcard(const bluetooth_device_address_t *address,
- int source, int type, bt_pbap_pull_vcard_parameters_t *app_param);
-
-int _bt_pbap_phonebook_search(const bluetooth_device_address_t *address,
- int source, int type, bt_pbap_search_parameters_t *app_param);
-
-void _bt_pbap_obex_transfer_completed(const char *transfer_path, gboolean transfer_status);
-
-void _bt_obex_pbap_client_disconnect(char *path);
-#endif
+++ /dev/null
-Bluez 5.16,
-HFP 1.6
-HSP AG 1.2
-SPP 1.1
-A2DP Source 1.2
-AVRCP Target 1.3
-GAVDP 1.2
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(bt-service C)
+#Include Source files for bluetooth service common files only
SET(SRCS
-bt-service-main.c
-bt-service-event-sender.c
-bt-service-headset-connection.c
-bt-service-event-receiver.c
-bt-service-common.c
-bt-service-util.c
-bt-service-adapter.c
-bt-service-adapter-le.c
-bt-service-device.c
-bt-service-hid.c
-bt-service-network.c
-bt-service-audio.c
-bt-service-oob.c
-bt-service-obex-agent.c
-bt-service-opp-client.c
-bt-service-obex-server.c
-bt-service-rfcomm-client.c
-bt-service-rfcomm-server.c
-bt-service-avrcp.c
-bt-service-avrcp-controller.c
-bt-request-handler.c
-bt-service-agent.c
-bt-service-gap-agent.c
-bt-service-pbap.c
-bt-service-dpm.c
-bt-service-proximity.c
+../include/bt-internal-types.c
+./services/bt-service-main.c
+./services/bt-service-common.c
+./services/bt-service-event-sender.c
+./services/bt-service-battery-monitor.c
+./services/bt-service-util.c
+./services/bt-request-handler.c
+./services/adapter/bt-service-core-adapter.c
+./services/adapter/bt-service-core-adapter-le.c
+./services/device/bt-service-core-device.c
+./services/device/bt-service-bonded-device.c
+./services/bt-service-event-receiver.c
+./services/bt-service-dpm.c
+./services/bt-service-agent-util.c
+./services/hid/bt-service-hidhost.c
+./services/hid/bt-service-hiddevice.c
+./services/socket/bt-service-socket.c
+./services/rfcomm/bt-service-rfcomm.c
+./services/audio/bt-service-audio.c
+./services/audio/bt-service-headset-connection.c
+./services/audio/hf/bt-service-hf.c
+./services/audio/a2dp_src/bt-service-a2dp-src.c
+./services/audio/a2dp_sink/bt-service-a2dp-sink.c
+./services/health/bt-service-hdp.c
+./services/audio/avrcp/bt-service-avrcp-tg.c
+./services/audio/avrcp/bt-service-avrcp-ctrl.c
+./services/gatt/bt-service-gatt.c
+./services/audio/hf/bt-service-hf-client.c
)
-IF(LIBNOTIFY_SUPPORT)
-LIST(APPEND SRCS
-bt-popup.c
-)
-ENDIF(LIBNOTIFY_SUPPORT)
+IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_OBEX")
+LIST(APPEND SRCS ./services/obex/bt-service-obex-agent.c)
+LIST(APPEND SRCS ./services/obex/bt-service-obex-server.c)
+LIST(APPEND SRCS ./services/obex/bt-service-map-client.c)
+LIST(APPEND SRCS ./services/obex/bt-service-opp-client.c)
+LIST(APPEND SRCS ./services/obex/bt-service-pbap.c)
+LIST(APPEND SRCS ./services/obex/bt-service-obex-event-receiver.c)
+LIST(APPEND SRCS ./services/obex/bt-service-oob.c)
+ENDIF()
-IF(LIBNOTIFICATION_SUPPORT)
-LIST(APPEND SRCS
-bt-service-agent-notification.c
-)
-ENDIF(LIBNOTIFICATION_SUPPORT)
+IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_PAN_NAP")
+LIST(APPEND SRCS ./services/pan_nap/bt-service-pan-nap-event-receiver.c)
+LIST(APPEND SRCS ./services/pan_nap/bt-service-network.c)
+ENDIF()
+
+IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_IPSP")
+LIST(APPEND SRCS ./services/ipsp/bt-service-ipsp.c)
+LIST(APPEND SRCS ./services/ipsp/bt-service-ipsp-event-receiver.c)
+ENDIF()
+
+IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_AVC_TARGET")
+LIST(APPEND SRCS ./services/audio/bt-service-absolute-volume.c)
+ENDIF()
IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
- SET(CMAKE_BUILD_TYPE "Release")
+ SET(CMAKE_BUILD_TYPE "Release")
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/services/include)
+IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_OBEX")
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/services/obex/include)
+ENDIF()
+IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_PAN_NAP")
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/services/pan_nap/include)
+ENDIF()
+IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_IPSP")
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/services/ipsp/include)
+ENDIF()
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../bt-oal/include)
+LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../bt-oal)
+IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_FACTORY_MODE")
SET(PKG_MODULES
- vconf
- aul
- vconf
- syspopup-caller
- dbus-1
- gio-2.0
- alarm-service
- capi-content-mime-type
- capi-network-connection
- cynara-client
- cynara-creds-gdbus
- eventsystem
- storage
+ vconf
+ dbus-1
+ gio-2.0
+ gio-unix-2.0
+ alarm-service
+ capi-network-connection
+ cynara-client
+ cynara-creds-gdbus
+ eventsystem
+ storage
+ capi-system-info
+ libsystemd-daemon
+ bincfg
)
-
-IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_NETWORK_TETHERING_ENABLE")
-SET(PKG_MODULES ${PKG_MODULES}
- capi-network-tethering
+ELSE()
+SET(PKG_MODULES
+ vconf
+ dbus-1
+ gio-2.0
+ gio-unix-2.0
+ alarm-service
+ capi-network-connection
+ cynara-client
+ cynara-creds-gdbus
+ eventsystem
+ storage
+ capi-system-info
+ libsystemd-daemon
)
ENDIF()
pkg_check_modules(service_pkgs REQUIRED ${PKG_MODULES})
FOREACH(flag ${service_pkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -Wall")
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -Wall")
ENDFOREACH(flag)
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
SET(CMAKE_C_FLAGS_RELEASE "-O2")
SET(APP_SYSCONFDIR /opt/var/lib/bluetooth)
FIND_PROGRAM(UNAME NAMES uname)
EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
IF("${ARCH}" STREQUAL "arm")
- ADD_DEFINITIONS("-DTARGET")
- MESSAGE("add -DTARGET")
+ ADD_DEFINITIONS("-DTARGET")
+ MESSAGE("add -DTARGET")
ENDIF("${ARCH}" STREQUAL "arm")
FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool)
-#EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=bt ${CMAKE_CURRENT_SOURCE_DIR}/bt-request-service.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/bt-service-method.h")
-#EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=bt_obex_agent ${CMAKE_CURRENT_SOURCE_DIR}/bt-service-obex-agent.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/bt-obex-agent-method.h")
-
-#EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=gap_agent ${CMAKE_CURRENT_SOURCE_DIR}/bt-service-gap-agent1.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/bt-gap-agent-method.h")
-
-#EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=bt_media_agent ${CMAKE_CURRENT_SOURCE_DIR}/bt-service-media-agent.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/bt-media-agent-method.h")
ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
ADD_DEFINITIONS("-DVENDOR=\"${APP_VENDOR}\"")
ADD_DEFINITIONS("-DAPP_LOCALEDIR=\"${APP_LOCALEDIR}\"")
ADD_DEFINITIONS("-DAPP_SYSCONFDIR=\"${APP_SYSCONFDIR}\"")
ADD_DEFINITIONS("-DHPS_FEATURE")
-ADD_DEFINITIONS("-DTIZEN_DPM_ENABLE")
+ADD_DEFINITIONS("-DTIZEN_FEATURE_BT_DPM")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${service_pkgs_LDFLAGS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${service_pkgs_LDFLAGS} bt-oal -ldl)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.projectx.bt.service DESTINATION share/dbus-1/system-services)
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
# install booting script
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/bluetooth-frwk-service.conf.in ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth-frwk-service.conf)
-IF (TIZEN_PROFILE_WEARABLE)
- INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/wearable/stack_info DESTINATION /usr/etc/bluetooth/)
-ELSE ()
- INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mobile/stack_info DESTINATION /usr/etc/bluetooth/)
-ENDIF (TIZEN_PROFILE_WEARABLE)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/wearable/stack_info DESTINATION /usr/etc/bluetooth/)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mobile/stack_info DESTINATION /usr/etc/bluetooth/)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth-frwk-service.conf DESTINATION /etc/dbus-1/system.d)
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} -ldl)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-AddressBlacklist=00:02:C7,00:16:FE,00:19:C1,00:1B:FB,00:1E:3D,00:21:4F,00:23:06,00:24:33,00:A0:79,00:0E:6D,00:13:E0,00:21:E8,00:60:57,00:0E:9F,00:12:1C,00:18:91,00:18:96,00:13:04,00:16:FD,00:22:A0,00:0B:4C,00:60:6F,00:23:3D,00:C0:59,00:0A:30,00:1E:AE,00:1C:D7,00:80:F0,00:12:8A,00:09:93,00:80:37,00:26:7E,08:76:95,00:1E:B2,00:26:E8,60:38:0E
-ExactNameBlacklist=Motorola IHF1000,i.TechBlueBAND,X5 Stereo v1.3,KML_CAN,SYNC,UConnect,Blue&Me
-PartialNameBlacklist=BMW,Audi,Parrot,HandsFreeLink,Car,MB PhoneSystem,CAR MULTIMEDIA,MB Bluetooth,Pama
-KeyboardAutoPair=00:0F:F6
+AddressBlacklist=00:02:C7,00:16:FE,00:19:C1,00:1B:FB,00:1E:3D,00:21:4F,00:23:06,00:24:33,00:A0:79,00:0E:6D,00:13:E0,00:21:E8,00:60:57,00:0E:9F,00:12:1C,00:18:91,00:18:96,00:13:04,00:16:FD,00:22:A0,00:0B:4C,00:60:6F,00:23:3D,00:C0:59,00:0A:30,00:1E:AE,00:1C:D7,00:80:F0,00:12:8A,00:09:93,00:80:37,00:26:7E,00:1A:1B,00:14:9A,00:0B:24,08:76:95,00:14:09,00:1E:B2\r
+ExactNameBlacklist=Motorola IHF1000,i.TechBlueBAND,X5 Stereo v1.3,KML_CAN,SYNC,UConnect\r
+PartialNameBlacklist=BMW,Audi,Parrot,HandsFreeLink,Car,MB PhoneSystem,CAR MULTIMEDIA,MB Bluetooth,Pama\r
+KeyboardAutoPair=00:0F:F6\r
<busconfig>
<policy user="root">
<allow own="org.projectx.bt"/>
+ <allow send_destination="org.projectx.bt"/>
+ <allow own="org.bluez.obex"/>
+ <allow send_destination="org.bluez.obex"/>
</policy>
- <policy user="network_fw">
+ <policy group="network_fw">
<allow own="org.projectx.bt"/>
+ <allow send_destination="org.projectx.bt"/>
+ <allow own="org.bluez.obex"/>
+ <allow send_destination="org.bluez.obex"/>
+ <allow own="org.projectx.bluetooth.share"/>
+ <allow send_destination="org.projectx.bluetooth.share"/>
+ <allow send_destination_prefix="org.tizen.csd.Call.Instance" send_interface="org.tizen.csd.Call.Instance" send_member="SendDtmf"/>
+ <allow send_destination_prefix="org.tizen.csd.Call.Instance" send_interface="org.tizen.csd.Call.Instance" send_member="VendorCmd"/>
+ </policy>
+ <policy group="pulse">
+ <allow send_destination="org.projectx.bt"/>
</policy>
<policy context="default">
<deny own="org.projectx.bt"/>
+ <deny send_destination="org.projectx.bt" send_type="method_call"/>
+ <deny own="org.bluez.obex"/>
+ <deny send_destination="org.bluez.obex" send_type="method_call"/>
<allow send_destination="org.projectx.bt" send_interface="org.projectx.bt"/>
- <allow send_destination="org.projectx.bt_event"/>
- <allow send_destination="org.projectx.bluetooth.share"/>
- <allow send_destination="org.tizen.csd.Call.Instance"/>
+ <allow send_destination="org.projectx.bt" send_interface="org.freedesktop.DBus.Properties" send_member="GetAll"/>
+ <check send_destination="org.projectx.bt" send_interface="org.bluez.Agent1" privilege="http://tizen.org/privilege/bluetooth.admin"/>
+ <allow send_destination="org.projectx.bt" send_interface="org.bluez.obex.reply"/>
+ <deny own="org.projectx.bluetooth.share"/>
+ <deny send_destination="org.projectx.bluetooth.share"/>
+ <deny own_prefix="org.tizen.csd.Call.Instance"/>
+ <allow own_prefix="org.tizen.csd.Call.Instance"/>
+ <deny send_destination_prefix="org.tizen.csd.Call.Instance" send_interface="org.tizen.csd.Call.Instance" send_member="SendDtmf"/>
+ <deny send_destination_prefix="org.tizen.csd.Call.Instance" send_interface="org.tizen.csd.Call.Instance" send_member="VendorCmd"/>
</policy>
</busconfig>
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <string.h>
-#include <glib.h>
-#include <dlog.h>
-#include <gio/gio.h>
-#include <cynara-client.h>
-#include <cynara-creds-gdbus.h>
-
-#include "bluetooth-api.h"
-#include "bt-service-common.h"
-#include "bt-service-util.h"
-#include "bt-service-event.h"
-#include "bt-service-adapter.h"
-#include "bt-service-adapter-le.h"
-#include "bt-service-device.h"
-#include "bt-service-hid.h"
-#include "bt-service-network.h"
-#include "bt-service-audio.h"
-#include "bt-service-oob.h"
-#include "bt-service-avrcp.h"
-#include "bt-service-avrcp-controller.h"
-#include "bt-service-opp-client.h"
-#include "bt-service-obex-server.h"
-#include "bt-service-rfcomm-client.h"
-#include "bt-service-rfcomm-server.h"
-#include "bt-request-handler.h"
-#include "bt-service-pbap.h"
-#include "bt-service-dpm.h"
-#include "bt-service-agent.h"
-#include "bt-service-proximity.h"
-
-static GDBusConnection *bt_service_conn;
-static guint owner_id = 0;
-cynara *p_cynara;
-cynara_configuration *conf;
-
-static const gchar bt_service_introspection_xml[] =
-"<node name='/org/projectx/bt_service'>"
-" <interface name='org.projectx.bt'>"
-" <method name='service_request'>"
- /* Input Parameters */
-" <arg type='i' name='service_type' direction='in' />"
-" <arg type='i' name='service_function' direction='in' />"
-" <arg type='i' name='request_type' direction='in' />"
-" <arg type='ay' name='input_param1' direction='in' />"
-" <arg type='ay' name='input_param2' direction='in' />"
-" <arg type='ay' name='input_param3' direction='in' />"
-" <arg type='ay' name='input_param4' direction='in' />"
-" <arg type='ay' name='input_param5' direction='in' />"
- /* Return Parameters */
-" <arg type='i' name='output_param1' direction='out' />"
-" <arg type='v' name='output_param2' direction='out' />"
-" </method>"
-" </interface>"
-"</node>";
-
-static gboolean name_acquired = FALSE;
-
-static char *current_sender_playing = NULL;
-
-static void __bt_service_method(GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *method_name,
- GVariant *parameters,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
-
-int __bt_bluez_request(int function_name,
- int request_type,
- int request_id,
- GDBusMethodInvocation *context,
- GVariant *in_param1,
- GVariant *in_param2,
- GVariant *in_param3,
- GVariant *in_param4,
- GArray **out_param1);
-int __bt_obexd_request(int function_name,
- int request_type,
- int request_id,
- GDBusMethodInvocation *context,
- GVariant *in_param1,
- GVariant *in_param2,
- GVariant *in_param3,
- GVariant *in_param4,
- GArray **out_param1);
-int __bt_agent_request(int function_name,
- int request_type,
- int request_id,
- GDBusMethodInvocation *context,
- GVariant *in_param1,
- GVariant *in_param2,
- GVariant *in_param3,
- GVariant *in_param4,
- GArray **out_param1);
-int __bt_core_request(int function_name,
- int request_type,
- int request_id,
- GDBusMethodInvocation *context,
- GVariant *in_param1);
-
-gboolean __bt_service_check_privilege(int function_name,
- int service_type,
- const char *unique_name);
-
-/* Function definitions*/
-static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
-{
- char *data;
- int size;
-
- size = g_variant_get_size(var);
- if (size > 0) {
- data = (char *)g_variant_get_data(var);
- if (data)
- param = g_array_append_vals(param, data, size);
-
- }
-}
-
-static void __bt_service_get_parameters(GVariant *in_param,
- void *value, int size)
-{
- void *buf = NULL;
- buf = (void *)g_variant_get_data(in_param);
- memcpy(value, buf, size);
-}
-
-static void __bt_service_method(GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *method_name,
- GVariant *parameters,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
-{
- FN_START;
-
- BT_DBG("Method[%s] Object Path[%s] Interface Name[%s]",
- method_name, object_path, interface_name);
-
- if (g_strcmp0(method_name, "service_request") == 0) {
- int service_type;
- int service_function;
- int request_type;
- GVariant *param1 = NULL;
- GVariant *param2 = NULL;
- GVariant *param3 = NULL;
- GVariant *param4 = NULL;
- GVariant *param5 = NULL;
- GArray *out_param1 = NULL;
- GVariant *out_var = NULL;
- int result = 0;
- int request_id = -1;
- const char *sender = NULL;
-
- g_variant_get(parameters, "(iii@ay@ay@ay@ay@ay)", &service_type,
- &service_function, &request_type,
- ¶m1, ¶m2, ¶m3, ¶m4, ¶m5);
-
- out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
-
- sender = g_dbus_method_invocation_get_sender(invocation);
-
- if (service_type == BT_CORE_SERVICE) {
- BT_DBG("No need to check privilege from bt-core");
- } else if (__bt_service_check_privilege(service_function,
- service_type, (const char *)sender) == FALSE) {
- BT_ERR("Client don't have the privilege to excute this function");
- result = BLUETOOTH_ERROR_PERMISSION_DEINED;
- goto fail;
- }
-
- if (request_type == BT_ASYNC_REQ
- || service_function == BT_OBEX_SERVER_ACCEPT_CONNECTION) {
- /* Set the timer */
- request_id = _bt_assign_request_id();
- BT_DBG("Request ID: %d", request_id);
-
- if (request_id < 0) {
- BT_ERR("Fail to assign the request id");
- result = BLUETOOTH_ERROR_INTERNAL;
-
- goto fail;
- }
- }
-
- BT_DBG("Service type = %s, fn = %s (0x%x)", __bt_convert_service_type_to_string(service_type),
- _bt_convert_service_function_to_string(service_function), service_function);
- switch (service_type) {
- case BT_BLUEZ_SERVICE:
- result = __bt_bluez_request(service_function,
- request_type, request_id,
- invocation, param1, param2,
- param3, param4, &out_param1);
- break;
- case BT_OBEX_SERVICE:
- result = __bt_obexd_request(service_function,
- request_type, request_id,
- invocation, param1,
- param2, param3,
- param4, &out_param1);
- break;
- case BT_AGENT_SERVICE:
- result = __bt_agent_request(service_function,
- request_type, request_id,
- invocation, param1,
- param2, param3,
- param4, &out_param1);
- break;
- case BT_CORE_SERVICE:
- result = __bt_core_request(service_function,
- request_type, request_id,
- invocation, param1);
- break;
- case BT_CHECK_PRIVILEGE:
- result = BLUETOOTH_ERROR_NONE;
- break;
- default:
- BT_ERR("Unknown service type");
- result = BLUETOOTH_ERROR_INTERNAL;
- goto fail;
- }
-
- if (result != BLUETOOTH_ERROR_NONE)
- goto fail;
-
- if ((request_type == BT_ASYNC_REQ ||
- service_function == BT_OBEX_SERVER_ACCEPT_CONNECTION) &&
- service_function != BT_OPP_PUSH_FILES) {
- BT_DBG("INSERT INTO REQ LIST");
- _bt_insert_request_list(request_id, service_function,
- NULL, invocation);
- } else {
- /* Return result */
- if (service_type == BT_CHECK_PRIVILEGE ||
- service_function != BT_OPP_PUSH_FILES) {
- out_var = g_variant_new_from_data((const GVariantType *)"ay",
- out_param1->data, out_param1->len,
- TRUE, NULL, NULL);
-
- GVariant *temp = g_variant_new("(iv)", result, out_var);
- g_dbus_method_invocation_return_value(invocation, temp);
- }
- }
-
- g_array_free(out_param1, TRUE);
- g_variant_unref(param1);
- g_variant_unref(param2);
- g_variant_unref(param3);
- g_variant_unref(param4);
- g_variant_unref(param5);
- FN_END;
- return;
-fail:
- BT_ERR_C("Request is failed [%s] [0x%x]",
- _bt_convert_error_to_string(result), result);
-
- out_var = g_variant_new_from_data((const GVariantType *)"ay",
- out_param1->data, out_param1->len,
- TRUE, NULL, NULL);
-
- GVariant *temp = g_variant_new("(iv)", result, out_var);
- g_dbus_method_invocation_return_value(invocation, temp);
-
- g_array_free(out_param1, TRUE);
- out_param1 = NULL;
-
- if (request_type == BT_ASYNC_REQ)
- _bt_delete_request_id(request_id);
-
- g_variant_unref(param1);
- g_variant_unref(param2);
- g_variant_unref(param3);
- g_variant_unref(param4);
- g_variant_unref(param5);
- }
-
- FN_END;
- return;
-}
-
-
-static const GDBusInterfaceVTable method_table = {
- __bt_service_method,
- NULL,
- NULL,
-};
-
-int __bt_bluez_request(int function_name,
- int request_type,
- int request_id,
- GDBusMethodInvocation *context,
- GVariant *in_param1,
- GVariant *in_param2,
- GVariant *in_param3,
- GVariant *in_param4,
- GArray **out_param1)
-{
- int result = BLUETOOTH_ERROR_NONE;
-
- switch (function_name) {
- case BT_ENABLE_ADAPTER:
- result = _bt_enable_adapter();
- break;
- case BT_DISABLE_ADAPTER:
- result = _bt_disable_adapter();
- break;
- case BT_RECOVER_ADAPTER:
- result = _bt_recover_adapter();
- break;
- case BT_ENABLE_ADAPTER_LE:
- _bt_set_le_intended_status(TRUE);
- result = _bt_enable_adapter_le();
- break;
- case BT_DISABLE_ADAPTER_LE:
- _bt_set_le_intended_status(FALSE);
- result = _bt_disable_adapter_le();
- break;
- case BT_RESET_ADAPTER:
- result = _bt_reset_adapter();
- break;
- case BT_CHECK_ADAPTER: {
- int enabled = BT_ADAPTER_DISABLED;
-
- result = _bt_check_adapter(&enabled);
-
- g_array_append_vals(*out_param1, &enabled,
- sizeof(int));
- break;
- }
- case BT_GET_LOCAL_ADDRESS: {
- bluetooth_device_address_t local_address = { {0} };
- result = _bt_get_local_address(&local_address);
-
- g_array_append_vals(*out_param1, &local_address,
- sizeof(bluetooth_device_address_t));
- break;
- }
- case BT_GET_LOCAL_VERSION: {
- bluetooth_version_t ver = { {0} };
- result = _bt_get_local_version(&ver);
-
- g_array_append_vals(*out_param1, &ver,
- sizeof(bluetooth_version_t));
- break;
- }
- case BT_GET_LOCAL_NAME: {
- bluetooth_device_name_t local_name = { {0} };
- result = _bt_get_local_name(&local_name);
-
- g_array_append_vals(*out_param1, &local_name,
- sizeof(bluetooth_device_name_t));
-
- break;
- }
- case BT_SET_LOCAL_NAME: {
- bluetooth_device_name_t local_name = { {0} };
- __bt_service_get_parameters(in_param1,
- &local_name, sizeof(bluetooth_device_name_t));
-
- result = _bt_set_local_name(local_name.name);
-
- break;
- }
- case BT_IS_SERVICE_USED: {
- char *uuid;
- gboolean used = FALSE;
-
- uuid = (char *)g_variant_get_data(in_param1);
-
- result = _bt_is_service_used(uuid, &used);
-
- if (result == BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &used,
- sizeof(gboolean));
- }
- break;
- }
- case BT_GET_DISCOVERABLE_MODE: {
- int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
-
- result = _bt_get_discoverable_mode(&mode);
-
- g_array_append_vals(*out_param1, &mode, sizeof(int));
- break;
- }
- case BT_SET_DISCOVERABLE_MODE: {
- int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
- int time = 0;
-
- __bt_service_get_parameters(in_param1, &mode, sizeof(int));
- __bt_service_get_parameters(in_param2, &time, sizeof(int));
-
- result = _bt_set_discoverable_mode(mode, time);
- break;
- }
- case BT_GET_DISCOVERABLE_TIME: {
- int timeout = 0;
-
- result = _bt_get_timeout_value(&timeout);
-
- g_array_append_vals(*out_param1, &timeout, sizeof(int));
- break;
- }
- case BT_START_DISCOVERY:
- result = _bt_start_discovery();
-
- break;
- case BT_START_CUSTOM_DISCOVERY: {
- bt_discovery_role_type_t role;
-
- __bt_service_get_parameters(in_param1,
- &role, sizeof(bt_discovery_role_type_t));
- result = _bt_start_custom_discovery(role);
-
- break;
- }
- case BT_CANCEL_DISCOVERY:
- result = _bt_cancel_discovery();
- break;
- case BT_IS_DISCOVERYING: {
- gboolean discovering = FALSE;
- discovering = _bt_is_discovering();
- g_array_append_vals(*out_param1,
- &discovering, sizeof(gboolean));
- break;
- }
- case BT_START_LE_DISCOVERY: {
- char *sender = NULL;
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
- result = _bt_start_le_scan(sender);
-
- break;
- }
- case BT_STOP_LE_DISCOVERY: {
- char *sender = NULL;
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
- result = _bt_stop_le_scan(sender);
-
- break;
- }
- case BT_IS_LE_DISCOVERYING: {
- gboolean le_discovering = FALSE;
-
- le_discovering = _bt_is_le_scanning();
- g_array_append_vals(*out_param1,
- &le_discovering, sizeof(gboolean));
-
- break;
- }
- case BT_REGISTER_SCAN_FILTER: {
- char *sender = NULL;
- bluetooth_le_scan_filter_t scan_filter;
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
- __bt_service_get_parameters(in_param1, &scan_filter,
- sizeof(bluetooth_le_scan_filter_t));
- BT_DBG("bluetooth_le_scan_filter_t [features : %.2x]",
- scan_filter.added_features);
-
- result = _bt_register_scan_filter(sender,
- &scan_filter);
-
- break;
- }
- case BT_IS_SCAN_FILTER_SUPPORTED:{
- int is_supported = 0;
-
- if (_bt_is_scan_filter_supported() == TRUE)
- is_supported = 1;
-
- g_array_append_vals(*out_param1,
- &is_supported, sizeof(int));
-
- break;
- }
- case BT_ENABLE_RSSI: {
- bluetooth_device_address_t bd_addr;
- int link_type;
- bt_rssi_threshold_t rssi_threshold;
- int low_threshold;
- int in_range_threshold;
- int high_threshold;
-
- BT_DBG("Enable RSSI");
-
- __bt_service_get_parameters(in_param1,
- &bd_addr, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &link_type, sizeof(int));
- __bt_service_get_parameters(in_param3,
- &rssi_threshold, sizeof(bt_rssi_threshold_t));
-
- low_threshold = rssi_threshold.low_threshold;
- in_range_threshold = rssi_threshold.in_range_threshold;
- high_threshold = rssi_threshold.high_threshold;
-
- result = _bt_enable_rssi(&bd_addr,
- link_type, low_threshold,
- in_range_threshold, high_threshold);
- break;
- }
- case BT_GET_RSSI: {
- int link_type;
- bluetooth_device_address_t bd_addr;
-
- BT_DBG("Get RSSI Strength");
-
- __bt_service_get_parameters(in_param1,
- &bd_addr, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &link_type, sizeof(int));
-
- result = _bt_get_rssi_strength(&bd_addr, link_type);
- break;
- }
- case BT_IS_CONNECTABLE: {
- gboolean is_connectable;
-
- is_connectable = _bt_is_connectable();
- g_array_append_vals(*out_param1,
- &is_connectable, sizeof(gboolean));
- break;
- }
- case BT_SET_CONNECTABLE: {
- gboolean is_connectable;
-
- __bt_service_get_parameters(in_param1,
- &is_connectable, sizeof(gboolean));
- result = _bt_set_connectable(is_connectable);
- break;
- }
- case BT_SET_ADVERTISING: {
- char *sender = NULL;
- int adv_handle;
- gboolean enable = FALSE;
- gboolean use_reserved_slot = FALSE;
-
- __bt_service_get_parameters(in_param1,
- &adv_handle, sizeof(int));
- __bt_service_get_parameters(in_param2,
- &enable, sizeof(gboolean));
- __bt_service_get_parameters(in_param3,
- &use_reserved_slot, sizeof(gboolean));
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
-
- result = _bt_set_advertising(sender, adv_handle,
- enable, use_reserved_slot);
- break;
- }
- case BT_SET_CUSTOM_ADVERTISING: {
- char *sender = NULL;
- int adv_handle;
- gboolean enable = FALSE;
- bluetooth_advertising_params_t adv_params;
- gboolean use_reserved_slot = FALSE;
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
-
- __bt_service_get_parameters(in_param1, &adv_handle,
- sizeof(int));
- __bt_service_get_parameters(in_param2, &enable,
- sizeof(gboolean));
- __bt_service_get_parameters(in_param3, &adv_params,
- sizeof(bluetooth_advertising_params_t));
- __bt_service_get_parameters(in_param4, &use_reserved_slot,
- sizeof(gboolean));
-
- BT_DBG("bluetooth_advertising_params_t [%f %f %d %d %d]",
- adv_params.interval_min, adv_params.interval_max,
- adv_params.filter_policy, adv_params.type, adv_params.tx_power_level);
- result = _bt_set_custom_advertising(sender, adv_handle,
- enable, &adv_params, use_reserved_slot);
- break;
- }
- case BT_GET_ADVERTISING_DATA: {
- bluetooth_advertising_data_t adv = { {0} };
- int length = 0;
-
- result = _bt_get_advertising_data(&adv, &length);
- if (result == BLUETOOTH_ERROR_NONE)
- g_array_append_vals(*out_param1, adv.data, length);
-
- break;
- }
- case BT_SET_ADVERTISING_DATA: {
- char *sender = NULL;
- int adv_handle;
- bluetooth_advertising_data_t adv = { {0} };
- int length;
- gboolean use_reserved_slot = FALSE;
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
-
- __bt_service_get_parameters(in_param1,
- &adv_handle, sizeof(int));
- __bt_service_get_parameters(in_param2,
- &adv, sizeof(bluetooth_advertising_data_t));
- __bt_service_get_parameters(in_param3,
- &length, sizeof(int));
- __bt_service_get_parameters(in_param4,
- &use_reserved_slot, sizeof(gboolean));
-
- result = _bt_set_advertising_data(sender, adv_handle,
- &adv, length, use_reserved_slot);
- break;
- }
- case BT_GET_SCAN_RESPONSE_DATA: {
- bluetooth_scan_resp_data_t rsp = { {0} };
- int length = 0;
-
- result = _bt_get_scan_response_data(&rsp, &length);
- if (result == BLUETOOTH_ERROR_NONE)
- g_array_append_vals(*out_param1, rsp.data, length);
-
- break;
- }
- case BT_SET_SCAN_RESPONSE_DATA: {
- char *sender = NULL;
- int adv_handle;
- bluetooth_scan_resp_data_t rsp = { {0} };
- int length;
- gboolean use_reserved_slot = FALSE;
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
-
- __bt_service_get_parameters(in_param1,
- &adv_handle, sizeof(int));
- __bt_service_get_parameters(in_param2,
- &rsp, sizeof(bluetooth_scan_resp_data_t));
- __bt_service_get_parameters(in_param3,
- &length, sizeof(int));
- __bt_service_get_parameters(in_param4,
- &use_reserved_slot, sizeof(gboolean));
-
- result = _bt_set_scan_response_data(sender, adv_handle,
- &rsp, length, use_reserved_slot);
-
- break;
- }
- case BT_SET_MANUFACTURER_DATA: {
- bluetooth_manufacturer_data_t m_data = { 0 };
- __bt_service_get_parameters(in_param1,
- &m_data, sizeof(bluetooth_manufacturer_data_t));
-
- result = _bt_set_manufacturer_data(&m_data);
- break;
- }
- case BT_SET_SCAN_PARAMETERS: {
- bluetooth_le_scan_params_t scan_params;
- __bt_service_get_parameters(in_param1, &scan_params,
- sizeof(bluetooth_le_scan_params_t));
-
- BT_DBG("bluetooth_le_scan_params_t [%f %f %d]",
- scan_params.interval, scan_params.window,
- scan_params.type);
-
- result = _bt_prepare_scan_parameters(&scan_params, 0);
- break;
- }
- case BT_SET_SCAN_TYPE: {
- int scan_type = 0;
- __bt_service_get_parameters(in_param1, &scan_type, sizeof(int));
-
- BT_DBG("bluetooth_le_scan_type [%d]", scan_type);
- result = _bt_prepare_scan_parameters(NULL, scan_type);
- break;
- }
- case BT_LE_CONN_UPDATE: {
- char *sender = NULL;
- bluetooth_device_address_t local_address = { {0} };
- bluetooth_le_connection_param_t parameters = {0};
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
-
- __bt_service_get_parameters(in_param1, &local_address,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2, ¶meters,
- sizeof(bluetooth_le_connection_param_t));
-
- result = _bt_le_conn_update(sender,
- local_address.addr,
- parameters.interval_min,
- parameters.interval_max,
- parameters.latency,
- parameters.timeout);
- break;
- }
- case BT_IS_ADVERTISING: {
- gboolean advertising = FALSE;
- advertising = _bt_is_advertising();
-
- g_array_append_vals(*out_param1, &advertising,
- sizeof(gboolean));
- break;
- }
- case BT_ADD_WHITE_LIST: {
- bluetooth_device_address_t address = { {0} };
- int addr_type = 0;
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2, &addr_type,
- sizeof(int));
-
- result = _bt_add_white_list(&address, addr_type);
- break;
- }
- case BT_REMOVE_WHITE_LIST: {
- bluetooth_device_address_t address = { {0} };
- int addr_type = 0;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &addr_type, sizeof(int));
-
- result = _bt_remove_white_list(&address, addr_type);
- break;
- }
- case BT_CLEAR_WHITE_LIST: {
- result = _bt_clear_white_list();
- break;
- }
- case BT_GET_BONDED_DEVICES: {
- result = _bt_get_bonded_devices(out_param1);
- break;
- }
- case BT_GET_PROFILE_CONNECTED_DEVICES: {
- char *uuid;
- uuid = (char *)g_variant_get_data(in_param1);
- result = _bt_get_profile_connected_devices(uuid, out_param1);
- break;
- }
- case BT_SET_PASSKEY_NOTIFICATION: {
- char *sender = NULL;
- gboolean enable;
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
- __bt_service_get_parameters(in_param1,
- &enable, sizeof(gboolean));
-
- result = _bt_set_passkey_notification(sender, enable);
- break;
- }
- case BT_GET_BONDED_DEVICE: {
- bluetooth_device_address_t address = { {0} };
- bluetooth_device_info_t dev_info;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
- result = _bt_get_bonded_device_info(&address, &dev_info);
-
- if (result == BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &dev_info,
- sizeof(bluetooth_device_info_t));
- }
- break;
- }
- case BT_GET_IS_ALIAS_SET: {
- bluetooth_device_address_t address = { {0} };
- gboolean is_alias_set = FALSE;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_is_alias_set(&address, &is_alias_set);
- if (result == BLUETOOTH_ERROR_NONE)
- g_array_append_vals(*out_param1, &is_alias_set, sizeof(gboolean));
-
- break;
- }
- case BT_DISCONNECT_DEVICE: {
- bluetooth_device_address_t addr = { {0} };
- char address[BLUETOOTH_ADDRESS_STRING_LENGTH + 1];
-
- __bt_service_get_parameters(in_param1,
- &addr, sizeof(bluetooth_device_address_t));
- _bt_convert_addr_type_to_string(address, addr.addr);
-
- result = _bt_disconnect_all(address);
- break;
- }
- case BT_BOND_DEVICE: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_bond_device(request_id, &address,
- BLUETOOTH_DEV_CONN_DEFAULT, out_param1);
- break;
- }
- case BT_BOND_DEVICE_BY_TYPE: {
- bluetooth_device_address_t address = { {0} };
- unsigned short conn_type = 0;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &conn_type, sizeof(unsigned short));
-
- result = _bt_bond_device(request_id, &address,
- conn_type, out_param1);
- break;
- }
- case BT_CANCEL_BONDING: {
- result = _bt_cancel_bonding();
- break;
- }
- case BT_PASSKEY_REPLY: {
- const char *passkey = NULL;
- gboolean authentication_reply = FALSE;
-
- passkey = g_variant_get_data(in_param1);
- __bt_service_get_parameters(in_param2,
- &authentication_reply, sizeof(gboolean));
- result = _bt_passkey_reply(passkey, authentication_reply);
- break;
- }
- case BT_PASSKEY_CONFIRMATION_REPLY: {
- gboolean confirmation_reply = FALSE;
-
- __bt_service_get_parameters(in_param1,
- &confirmation_reply, sizeof(gboolean));
- result = _bt_passkey_confirmation_reply(confirmation_reply);
- break;
- }
- case BT_UNBOND_DEVICE: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_unbond_device(request_id, &address, out_param1);
-
- break;
- }
- case BT_SET_ALIAS: {
- bluetooth_device_address_t address = { {0} };
- const char *local_name;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- local_name = (const char *)g_variant_get_data(in_param2);
-
- result = _bt_set_alias(&address, local_name);
- break;
- }
- case BT_SEARCH_SERVICE: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_search_device(request_id, &address);
- if (result != BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &address,
- sizeof(bluetooth_device_address_t));
- }
- break;
- }
- case BT_CANCEL_SEARCH_SERVICE: {
- result = _bt_cancel_search_device();
- break;
- }
- case BT_SET_AUTHORIZATION: {
- bluetooth_device_address_t address = { {0} };
- gboolean authorize;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &authorize, sizeof(gboolean));
-
- result = _bt_set_authorization(&address, authorize);
- break;
- }
- case BT_IS_DEVICE_CONNECTED: {
- bluetooth_device_address_t address = { {0} };
- int type;
- gboolean connected = FALSE;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &type, sizeof(int));
-
- result = _bt_is_device_connected(&address, type, &connected);
- BT_DBG("is_connected: %d", connected);
- if (result == BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &connected,
- sizeof(gboolean));
- }
-
- break;
- }
- case BT_GET_CONNECTED_LINK_TYPE: {
- bluetooth_device_address_t address = { {0} };
- bluetooth_connected_link_t connected = BLUETOOTH_CONNECTED_LINK_NONE;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_get_connected_link(&address, &connected);
-
- if (result == BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &connected,
- sizeof(guint));
- }
-
- break;
- }
- case BT_SET_PIN_CODE: {
- bluetooth_device_address_t address = { {0} };
- bluetooth_device_pin_code_t pin_code = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &pin_code, sizeof(bluetooth_device_pin_code_t));
-
- result = _bt_set_pin_code(&address, &pin_code);
- break;
- }
- case BT_UNSET_PIN_CODE: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_unset_pin_code(&address);
- break;
- }
- case BT_UPDATE_LE_CONNECTION_MODE: {
- char *sender = NULL;
- bluetooth_device_address_t remote_address = { { 0 } };
- bluetooth_le_connection_param_t param = { 0 };
- bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED;
-
- __bt_service_get_parameters(in_param1, &remote_address,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2, &mode,
- sizeof(bluetooth_le_connection_mode_t));
-
- result = _bt_get_le_connection_parameter(mode, ¶m);
- if (result != BLUETOOTH_ERROR_NONE)
- break;
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
-
- result = _bt_le_conn_update(sender,
- remote_address.addr,
- param.interval_min,
- param.interval_max,
- param.latency,
- param.timeout);
- break;
- }
-
- case BT_SET_PROFILE_TRUSTED: {
- bluetooth_device_address_t bd_addr = { {0} };
- int profile;
- int trust;
-
- __bt_service_get_parameters(in_param1, &bd_addr,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2, &profile, sizeof(int));
- __bt_service_get_parameters(in_param3, &trust, sizeof(int));
-
- result = _bt_set_trust_profile(&bd_addr, profile, trust);
- break;
- }
- case BT_GET_PROFILE_TRUSTED: {
- bluetooth_device_address_t bd_addr = { {0} };
- int profile;
- guint trusted_profile = 0;
-
- __bt_service_get_parameters(in_param1, &bd_addr,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2, &profile, sizeof(int));
-
- result = _bt_get_trust_profile(&bd_addr, profile, &trusted_profile);
- BT_DBG("TRUST %d", trusted_profile);
- if (result == BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &trusted_profile,
- sizeof(guint));
- }
-
- break;
- }
- case BT_SET_PROFILE_RESTRICTED: {
- bluetooth_device_address_t bd_addr = { {0} };
- int profile;
- int restricted;
-
- __bt_service_get_parameters(in_param1, &bd_addr,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2, &profile, sizeof(int));
- __bt_service_get_parameters(in_param3, &restricted, sizeof(int));
-
- result = _bt_set_restrict_profile(&bd_addr, profile, restricted);
- break;
- }
- case BT_GET_PROFILE_RESTRICTED: {
- bluetooth_device_address_t bd_addr = { {0} };
- int profile;
- guint restricted_profile = 0;
-
- __bt_service_get_parameters(in_param1, &bd_addr,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2, &profile, sizeof(int));
-
- result = _bt_get_restrict_profile(&bd_addr, profile, &restricted_profile);
- BT_DBG("Restricted %d", restricted_profile);
- if (result == BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &restricted_profile,
- sizeof(guint));
- }
-
- break;
- }
- case BT_HID_CONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_hid_connect(request_id, &address);
- if (result != BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &address,
- sizeof(bluetooth_device_address_t));
- }
- break;
- }
- case BT_HID_DISCONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_hid_disconnect(request_id, &address);
- if (result != BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &address,
- sizeof(bluetooth_device_address_t));
- }
- break;
- }
- case BT_HID_ENABLE_BARCODE_FEATURE: {
- result = _bt_hid_enable_barcode_feature();
- break;
- }
- case BT_NETWORK_ACTIVATE:
- result = _bt_network_activate();
- break;
- case BT_NETWORK_DEACTIVATE:
- result = _bt_network_deactivate();
- break;
- case BT_NETWORK_CONNECT: {
- bluetooth_device_address_t address = { {0} };
- int role;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &role, sizeof(int));
-
- result = _bt_network_connect(request_id, role, &address);
- if (result != BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &address,
- sizeof(bluetooth_device_address_t));
- }
- break;
- }
- case BT_NETWORK_DISCONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_network_disconnect(request_id, &address);
- if (result != BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &address,
- sizeof(bluetooth_device_address_t));
- }
- break;
- }
- case BT_NETWORK_SERVER_DISCONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_network_server_disconnect(request_id, &address);
- if (result != BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &address,
- sizeof(bluetooth_device_address_t));
- }
- break;
- }
-
- case BT_AUDIO_CONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_audio_connect(request_id, BT_AUDIO_ALL,
- &address, *out_param1);
- break;
- }
- case BT_AUDIO_DISCONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_audio_disconnect(request_id, BT_AUDIO_ALL,
- &address, *out_param1);
- break;
- }
- case BT_AG_CONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_audio_connect(request_id, BT_AUDIO_HSP,
- &address, *out_param1);
- break;
- }
- case BT_AG_DISCONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_audio_disconnect(request_id, BT_AUDIO_HSP,
- &address, *out_param1);
- break;
- }
- case BT_AV_CONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_audio_connect(request_id, BT_AUDIO_A2DP,
- &address, *out_param1);
- break;
- }
- case BT_AV_DISCONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_audio_disconnect(request_id, BT_AUDIO_A2DP,
- &address, *out_param1);
- break;
- }
- case BT_AVRCP_CONTROL_CONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_audio_connect(request_id, BT_AVRCP,
- &address, *out_param1);
- break;
- }
- case BT_AVRCP_CONTROL_DISCONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_audio_disconnect(request_id, BT_AVRCP,
- &address, *out_param1);
- break;
- }
- case BT_AVRCP_TARGET_CONNECT: {
- bluetooth_device_address_t address = { {0} };
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- result = _bt_audio_connect(request_id, BT_AVRCP_TARGET,
- &address, *out_param1);
- break;
- }
- case BT_AVRCP_TARGET_DISCONNECT: {
- bluetooth_device_address_t address = { {0} };
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- result = _bt_audio_disconnect(request_id, BT_AVRCP_TARGET,
- &address, *out_param1);
- break;
- }
- case BT_AV_SOURCE_CONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
-
- result = _bt_audio_connect(request_id, BT_AUDIO_A2DP_SOURCE,
- &address, *out_param1);
- break;
- }
- case BT_AV_SOURCE_DISCONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
-
- result = _bt_audio_disconnect(request_id, BT_AUDIO_A2DP_SOURCE,
- &address, *out_param1);
- break;
- }
- case BT_HF_CONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_hf_connect(request_id, &address, *out_param1);
- break;
- }
- case BT_HF_DISCONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_hf_disconnect(request_id, &address, *out_param1);
- break;
- }
- case BT_SET_CONTENT_PROTECT: {
- gboolean status;
-
- __bt_service_get_parameters(in_param1,
- &status, sizeof(gboolean));
-
- result = _bt_audio_set_content_protect(status);
-
- break;
- }
- case BT_OOB_READ_LOCAL_DATA: {
- bt_oob_data_t local_oob_data;
-
- memset(&local_oob_data, 0x00, sizeof(bt_oob_data_t));
- result = _bt_oob_read_local_data(&local_oob_data);
-
- g_array_append_vals(*out_param1, &local_oob_data,
- sizeof(bt_oob_data_t));
-
- break;
- }
- case BT_OOB_ADD_REMOTE_DATA: {
- bluetooth_device_address_t address = { {0} };
- bt_oob_data_t remote_oob_data;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &remote_oob_data, sizeof(bt_oob_data_t));
-
- result = _bt_oob_add_remote_data(&address, &remote_oob_data);
-
- break;
- }
- case BT_OOB_REMOVE_REMOTE_DATA: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_oob_remove_remote_data(&address);
-
- break;
- }
- case BT_LE_OOB_READ_LOCAL_DATA: {
- bt_oob_data_t local_oob_data;
-
- memset(&local_oob_data, 0x00, sizeof(bt_oob_data_t));
- result = _bt_le_oob_read_local_data(&local_oob_data);
-
- g_array_append_vals(*out_param1, &local_oob_data,
- sizeof(bt_oob_data_t));
-
- break;
- }
- case BT_LE_OOB_ADD_REMOTE_DATA: {
- bluetooth_device_address_t address = { {0} };
- unsigned short address_type;
- bt_oob_data_t remote_oob_data;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &address_type, sizeof(unsigned short));
- __bt_service_get_parameters(in_param3,
- &remote_oob_data, sizeof(bt_oob_data_t));
-
- result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
-
- break;
- }
- case BT_AVRCP_SET_TRACK_INFO: {
- media_metadata_t data;
- media_metadata_attributes_t meta_data;
-
- memset(&data, 0x00, sizeof(media_metadata_t));
- memset(&meta_data, 0x00, sizeof(media_metadata_attributes_t));
-
- __bt_service_get_parameters(in_param1,
- &data, sizeof(media_metadata_t));
-
- meta_data.title = g_strdup(data.title);
- meta_data.artist = g_strdup(data.artist);
- meta_data.album = g_strdup(data.album);
- meta_data.genre = g_strdup(data.genre);
- meta_data.total_tracks = data.total_tracks;
- meta_data.number = data.number;
- meta_data.duration = (int64_t) data.duration;
-
- if (meta_data.title)
- BT_INFO("title [%s]", meta_data.title);
- if (meta_data.artist)
- BT_INFO("artist [%s]", meta_data.artist);
- if (meta_data.album)
- BT_INFO("album [%s]", meta_data.album);
- if (meta_data.genre)
- BT_INFO("genre [%s]", meta_data.genre);
- BT_INFO("total_tracks[%d], number[%d], duration[%d]",
- meta_data.total_tracks, meta_data.number, meta_data.duration);
-
- result = _bt_avrcp_set_track_info(&meta_data);
-
- g_free((gpointer)meta_data.title);
- g_free((gpointer)meta_data.artist);
- g_free((gpointer)meta_data.album);
- g_free((gpointer)meta_data.genre);
-
- break;
- }
- case BT_AVRCP_SET_PROPERTY: {
- int type;
- unsigned int value;
- char *sender = NULL;
- sender = (char *)g_dbus_method_invocation_get_sender(context);
- BT_INFO("Sender %s", sender);
-
- __bt_service_get_parameters(in_param1,
- &type, sizeof(int));
- __bt_service_get_parameters(in_param2,
- &value, sizeof(unsigned int));
-
- if (value == STATUS_PLAYING) {
- if (current_sender_playing)
- g_free(current_sender_playing);
- current_sender_playing = g_strdup(sender);
- }
- if (g_strcmp0(sender, current_sender_playing) == 0 ||
- current_sender_playing == NULL) {
- BT_INFO("Current Player Status %d type %d", value, type);
- } else {
- BT_INFO("Current Player and this sender are different");
- result = BLUETOOTH_ERROR_NONE;
- break;
- }
- result = _bt_avrcp_set_property(type, value);
-
- break;
- }
- case BT_AVRCP_SET_PROPERTIES: {
- media_player_settings_t properties;
-
- memset(&properties, 0x00, sizeof(media_player_settings_t));
- __bt_service_get_parameters(in_param1,
- &properties, sizeof(media_player_settings_t));
-
- result = _bt_avrcp_set_properties(&properties);
-
- break;
- }
- case BT_AVRCP_HANDLE_CONTROL: {
- int type;
-
- __bt_service_get_parameters(in_param1, &type, sizeof(int));
-
- result = _bt_avrcp_control_cmd(type);
-
- break;
- }
- case BT_AVRCP_CONTROL_SET_PROPERTY: {
- int type;
- unsigned int value;
-
- __bt_service_get_parameters(in_param1,
- &type, sizeof(int));
- __bt_service_get_parameters(in_param2,
- &value, sizeof(unsigned int));
-
- result = _bt_avrcp_control_set_property(type, value);
-
- break;
- }
- case BT_AVRCP_CONTROL_GET_PROPERTY: {
- int type;
- unsigned int value;
-
- __bt_service_get_parameters(in_param1, &type, sizeof(int));
-
- result = _bt_avrcp_control_get_property(type, &value);
- g_array_append_vals(*out_param1, &value, sizeof(int));
-
- break;
- }
- case BT_AVRCP_GET_TRACK_INFO: {
- media_metadata_t meta_data;
- media_metadata_attributes_t metadata;
-
- memset(&meta_data, 0x00, sizeof(media_metadata_t));
- memset(&metadata, 0x00, sizeof(media_metadata_attributes_t));
-
- result = _bt_avrcp_control_get_track_info(&metadata);
-
- if (BLUETOOTH_ERROR_NONE != result)
- break;
-
- if (_bt_copy_utf8_string(meta_data.title, metadata.title,
- BT_META_DATA_MAX_LEN))
- BT_ERR("Error in copying Title\n");
- if (_bt_copy_utf8_string(meta_data.artist, metadata.artist,
- BT_META_DATA_MAX_LEN))
- BT_ERR("Error in copying Artist\n");
- if (_bt_copy_utf8_string(meta_data.album, metadata.album,
- BT_META_DATA_MAX_LEN))
- BT_ERR("Error in copying Album\n");
- if (_bt_copy_utf8_string(meta_data.genre, metadata.genre,
- BT_META_DATA_MAX_LEN))
- BT_ERR("Error in copying Genre\n");
-
- if (_bt_utf8_validate(meta_data.title) == FALSE)
- meta_data.title[0] = '\0';
-
- if (_bt_utf8_validate(meta_data.artist) == FALSE)
- meta_data.artist[0] = '\0';
-
- if (_bt_utf8_validate(meta_data.album) == FALSE)
- meta_data.album[0] = '\0';
-
- if (_bt_utf8_validate(meta_data.genre) == FALSE)
- meta_data.genre[0] = '\0';
-
- meta_data.total_tracks = metadata.total_tracks;
- meta_data.number = metadata.number;
- meta_data.duration = metadata.duration;
-
- g_free((gpointer)metadata.title);
- g_free((gpointer)metadata.artist);
- g_free((gpointer)metadata.album);
- g_free((gpointer)metadata.genre);
-
- g_array_append_vals(*out_param1, &meta_data,
- sizeof(media_metadata_t));
- break;
- }
- case BT_RFCOMM_CLIENT_CONNECT: {
-#ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
- result = BLUETOOTH_ERROR_NONE;
-#else
- bluetooth_device_address_t address = { {0} };
- char *input_string;
- int connect_type;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- input_string = &g_array_index(in_param2, char, 0);
-
- connect_type = g_array_index(in_param3, int, 0);
-
- if (connect_type == BT_RFCOMM_UUID) {
- result = _bt_rfcomm_connect_using_uuid(request_id,
- &address, input_string);
- } else {
- result = _bt_rfcomm_connect_using_channel(request_id,
- &address, input_string);
- }
-
- if (result != BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &address,
- sizeof(bluetooth_device_address_t));
- }
-#endif
- break;
- }
- case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
- result = _bt_rfcomm_cancel_connect();
- break;
- case BT_RFCOMM_CLIENT_IS_CONNECTED: {
- gboolean connected = FALSE;
- result = _bt_rfcomm_is_connected(&connected);
-
- g_array_append_vals(*out_param1, &connected, sizeof(gboolean));
- break;
- }
- case BT_RFCOMM_SOCKET_DISCONNECT: {
-#ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
- result = BLUETOOTH_ERROR_NONE;
-#else
- int socket_fd;
-
- socket_fd = g_array_index(in_param1, int, 0);
-
- result = _bt_rfcomm_disconnect(socket_fd);
-#endif
- break;
- }
- case BT_RFCOMM_SOCKET_WRITE: {
-#ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
- result = BLUETOOTH_ERROR_NONE;
-#else
- int socket_fd;
- int length;
- char *buffer;
-
- socket_fd = g_array_index(in_param1, int, 0);
- length = g_array_index(in_param2, int, 0);
- buffer = &g_array_index(in_param3, char, 0);
-
- result = _bt_rfcomm_write(socket_fd, buffer, length);
-#endif
- break;
- }
- case BT_RFCOMM_CREATE_SOCKET: {
-#ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
- result = BLUETOOTH_ERROR_NONE;
-#else
- char *sender;
- char *uuid;
- int socket_fd = -1;
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
- uuid = &g_array_index(in_param1, char, 0);
-
- result = _bt_rfcomm_create_socket(sender, uuid);
-
- if (result > 0) {
- socket_fd = result;
- result = BLUETOOTH_ERROR_NONE;
- }
-
- g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
-
- g_free(sender);
-#endif
- break;
- }
- case BT_RFCOMM_REMOVE_SOCKET: {
-#ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
- result = BLUETOOTH_ERROR_NONE;
-#else
- int socket_fd;
-
- socket_fd = g_array_index(in_param1, int, 0);
-
- result = _bt_rfcomm_remove_socket(socket_fd);
-#endif
- break;
- }
- case BT_RFCOMM_LISTEN: {
- int socket_fd;
- int pending;
- gboolean is_native;
-
- __bt_service_get_parameters(in_param1, &socket_fd,
- sizeof(int));
- __bt_service_get_parameters(in_param2, &pending,
- sizeof(int));
- __bt_service_get_parameters(in_param3, &is_native,
- sizeof(gboolean));
-
- result = _bt_rfcomm_listen(socket_fd, pending, is_native);
- break;
- }
- case BT_RFCOMM_IS_UUID_AVAILABLE: {
- gboolean available = TRUE;
- char *uuid;
-
- uuid = (char *)g_variant_get_data(in_param1);
-
- result = _bt_rfcomm_is_uuid_available(uuid, &available);
-
- g_array_append_vals(*out_param1, &available, sizeof(gboolean));
- break;
- }
- case BT_RFCOMM_ACCEPT_CONNECTION: {
- int socket_fd;
-
- __bt_service_get_parameters(in_param1, &socket_fd, sizeof(int));
- BT_DBG(" socket fd %d", socket_fd);
- result = _bt_rfcomm_accept_connection();
- break;
- }
- case BT_RFCOMM_REJECT_CONNECTION: {
- int socket_fd;
-
- __bt_service_get_parameters(in_param1, &socket_fd, sizeof(int));
- BT_DBG(" socket fd %d", socket_fd);
- result = _bt_rfcomm_reject_connection();
- break;
- }
- case BT_RFCOMM_CREATE_SOCKET_EX: {
- result = BLUETOOTH_ERROR_NONE;
- break;
- }
- case BT_RFCOMM_REMOVE_SOCKET_EX: {
- result = BLUETOOTH_ERROR_NONE;
- break;
- }
- case BT_CONNECT_LE: {
- bluetooth_device_address_t address = { {0} };
- gboolean auto_connect;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &auto_connect, sizeof(gboolean));
-
- result = _bt_connect_le_device(request_id, &address,
- auto_connect);
- if (result != BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &address,
- sizeof(bluetooth_device_address_t));
- }
-
- break;
- }
- case BT_DISCONNECT_LE: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
-
- result = _bt_disconnect_le_device(request_id, &address);
- if (result != BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &address,
- sizeof(bluetooth_device_address_t));
- }
-
- break;
- }
- case BT_SET_LE_PRIVACY: {
- gboolean set_privacy;
-
- __bt_service_get_parameters(in_param1, &set_privacy,
- sizeof(gboolean));
-
- result = _bt_set_le_privacy(set_privacy);
-
- break;
- }
- case BT_REQ_ATT_MTU: {
- bluetooth_device_address_t address = { {0} };
- unsigned int mtu;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &mtu, sizeof(unsigned int));
-
- result = _bt_request_att_mtu(request_id, &address, mtu);
- if (result != BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &address,
- sizeof(bluetooth_device_info_t));
- }
- break;
- }
- case BT_GET_ATT_MTU: {
- bluetooth_device_address_t address = { {0} };
- unsigned int mtu = 0;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_get_att_mtu(&address, &mtu);
- BT_DBG("MTU: %d", mtu);
- if (result == BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &mtu,
- sizeof(unsigned int));
- }
- break;
- }
- case BT_GET_DEVICE_IDA: {
- bluetooth_device_address_t address = { {0} };
- bluetooth_device_address_t id_addr = { {0} };
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = _bt_get_device_ida(&address, &id_addr);
-
- if (result == BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &id_addr,
- sizeof(bluetooth_device_address_t));
- }
- break;
- }
- case BT_SET_LE_STATIC_RANDOM_ADDRESS: {
- gboolean is_enable;
-
- __bt_service_get_parameters(in_param1, &is_enable,
- sizeof(gboolean));
-
- result = _bt_set_le_static_random_address(is_enable);
-
- break;
- }
- case BT_HDP_CONNECT:
- case BT_HDP_DISCONNECT:
- case BT_HDP_SEND_DATA:
-
- case BT_GATT_GET_PRIMARY_SERVICES:
- case BT_GATT_DISCOVER_CHARACTERISTICS:
- case BT_GATT_SET_PROPERTY_REQUEST:
- case BT_GATT_READ_CHARACTERISTIC:
- case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
-
- case BT_HID_DEVICE_ACTIVATE:
- case BT_HID_DEVICE_DEACTIVATE:
- case BT_HID_DEVICE_CONNECT:
- case BT_HID_DEVICE_DISCONNECT:
- case BT_HID_DEVICE_SEND_MOUSE_EVENT:
- case BT_HID_DEVICE_SEND_KEY_EVENT:
- case BT_HID_DEVICE_SEND_REPLY_TO_REPORT:
- /* Just call to check the privilege */
- break;
-#ifndef GATT_NO_RELAY
- case BT_GATT_WATCH_CHARACTERISTIC: {
- char *sender = NULL;
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
-
- result = _bt_insert_gatt_client_sender(sender);
-
- break;
- }
- case BT_GATT_UNWATCH_CHARACTERISTIC: {
- char *sender = NULL;
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
-
- result = _bt_delete_gatt_client_sender(sender);
-
- break;
- }
-#endif
- case BT_LE_IPSP_INIT:
- result = _bt_initialize_ipsp();
- break;
- case BT_LE_IPSP_DEINIT:
- result = _bt_deinitialize_ipsp();
- break;
- case BT_LE_IPSP_CONNECT: {
- bluetooth_device_address_t address = { {0} };
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
-
- result = _bt_connect_le_ipsp_device(&address);
- break;
- }
- case BT_LE_IPSP_DISCONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
-
- result = _bt_disconnect_le_ipsp_device(&address);
- break;
- }
- case BT_LE_READ_MAXIMUM_DATA_LENGTH: {
- bluetooth_le_read_maximum_data_length_t max_le_datalength = {0};
-
- result = _bt_le_read_maximum_data_length(&max_le_datalength);
-
- g_array_append_vals(*out_param1, &max_le_datalength,
- sizeof(bluetooth_le_read_maximum_data_length_t));
- break;
- }
- case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH: {
- unsigned int def_tx_Octects = 0;
- unsigned int def_tx_Time = 0;
-
- __bt_service_get_parameters(in_param1,
- &def_tx_Octects, sizeof(int));
- __bt_service_get_parameters(in_param2,
- &def_tx_Time, sizeof(int));
-
- result = _bt_le_write_host_suggested_default_data_length(
- def_tx_Octects, def_tx_Time);
- break;
- }
- case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH: {
- bluetooth_le_read_host_suggested_data_length_t def_data_length = {0};
-
- result = _bt_le_read_host_suggested_default_data_length(&def_data_length);
-
- g_array_append_vals(*out_param1, &def_data_length,
- sizeof(bluetooth_le_read_host_suggested_data_length_t));
-
- break;
- }
- case BT_LE_SET_DATA_LENGTH: {
- int max_tx_Octets = 0;
- int max_tx_Time = 0;
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &max_tx_Octets, sizeof(int));
- __bt_service_get_parameters(in_param3,
- &max_tx_Time, sizeof(int));
-
- result = _bt_le_set_data_length(&address, max_tx_Octets, max_tx_Time);
- break;
- }
- case BT_DPM_SET_ALLOW_BT_MODE: {
- dpm_bt_allow_t value = DPM_BT_ERROR;
-
- __bt_service_get_parameters(in_param1, &value,
- sizeof(int));
-
- result = _bt_dpm_set_allow_bluetooth_mode(value);
- break;
- }
- case BT_DPM_GET_ALLOW_BT_MODE: {
- dpm_bt_allow_t value = DPM_BT_ERROR;
-
- value = _bt_dpm_get_allow_bluetooth_mode();
- result = DPM_RESULT_SUCCESS;
- g_array_append_vals(*out_param1, &value, sizeof(int));
-
- break;
- }
- case BT_DPM_SET_DEVICE_RESTRITION: {
- dpm_status_t value = DPM_BT_ERROR;
-
- __bt_service_get_parameters(in_param1, &value,
- sizeof(int));
-
- result = _bt_dpm_activate_bluetooth_device_restriction(value);
- break;
- }
- case BT_DPM_GET_DEVICE_RESTRITION: {
- dpm_status_t value = DPM_BT_ERROR;
-
- value = _bt_dpm_is_bluetooth_device_restriction_active();
- result = DPM_RESULT_SUCCESS;
- g_array_append_vals(*out_param1, &value, sizeof(int));
-
- break;
- }
- case BT_DPM_SET_UUID_RESTRITION: {
- dpm_status_t value = DPM_BT_ERROR;
-
- __bt_service_get_parameters(in_param1, &value,
- sizeof(int));
-
- result = _bt_dpm_activate_bluetoooth_uuid_restriction(value);
- break;
- }
- case BT_DPM_GET_UUID_RESTRITION: {
- dpm_status_t value = DPM_BT_ERROR;
-
- value = _bt_dpm_is_bluetooth_uuid_restriction_active();
- result = DPM_RESULT_SUCCESS;
- g_array_append_vals(*out_param1, &value, sizeof(int));
-
- break;
- }
- case BT_DPM_ADD_DEVICES_BLACKLIST: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
-
- result = _bt_dpm_add_bluetooth_devices_to_blacklist(&address);
- break;
- }
- case BT_DPM_ADD_DEVICES_WHITELIST: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
-
- result = _bt_dpm_add_bluetooth_devices_to_whitelist(&address);
- break;
- }
- case BT_DPM_ADD_UUIDS_BLACKLIST: {
- const char *uuid = NULL;
-
- uuid = g_variant_get_data(in_param1);
-
- result = _bt_dpm_add_bluetooth_uuids_to_blacklist(uuid);
- break;
- }
- case BT_DPM_ADD_UUIDS_WHITELIST: {
- const char *uuid = NULL;
-
- uuid = g_variant_get_data(in_param1);
-
- result = _bt_dpm_add_bluetooth_uuids_to_whitelist(uuid);
- break;
- }
- case BT_DPM_CLEAR_DEVICES_BLACKLIST: {
- result = _bt_dpm_clear_bluetooth_devices_from_blacklist();
- break;
- }
- case BT_DPM_CLEAR_DEVICES_WHITELIST: {
- result = _bt_dpm_clear_bluetooth_devices_from_whitelist();
- break;
- }
- case BT_DPM_CLEAR_UUIDS_BLACKLIST: {
- result = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
- break;
- }
- case BT_DPM_CLEAR_UUIDS_WHITELIST: {
- result = _bt_dpm_clear_bluetooth_uuids_from_whitelist();
- break;
- }
- case BT_DPM_REMOVE_DEVICE_BLACKLIST: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
-
- result = _bt_dpm_remove_bluetooth_devices_from_blacklist(&address);
- break;
- }
- case BT_DPM_REMOVE_DEVICE_WHITELIST: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
-
- result = _bt_dpm_remove_bluetooth_devices_from_whitelist(&address);
- break;
- }
- case BT_DPM_REMOVE_UUID_BLACKLIST: {
- const char *uuid = NULL;
-
- uuid = g_variant_get_data(in_param1);
-
- result = _bt_dpm_remove_bluetooth_uuids_from_blacklist(uuid);
- break;
- }
- case BT_DPM_REMOVE_UUID_WHITELIST: {
- const char *uuid = NULL;
-
- uuid = g_variant_get_data(in_param1);
-
- result = _bt_dpm_remove_bluetooth_uuids_from_whitelist(uuid);
-
- break;
- }
- case BT_DPM_GET_DEVICES_BLACKLIST: {
- result = _bt_dpm_get_bluetooth_devices_from_blacklist(out_param1);
- break;
- }
- case BT_DPM_GET_DEVICES_WHITELIST: {
- result = _bt_dpm_get_bluetooth_devices_from_whitelist(out_param1);
- break;
- }
- case BT_DPM_GET_UUIDS_BLACKLIST: {
- result = _bt_dpm_get_bluetooth_uuids_from_blacklist(out_param1);
- break;
- }
- case BT_DPM_GET_UUIDS_WHITELIST: {
- result = _bt_dpm_get_bluetooth_uuids_from_whitelist(out_param1);
- break;
- }
- case BT_DPM_SET_ALLOW_OUTGOING_CALL: {
- dpm_status_t value = DPM_BT_ERROR;
-
- __bt_service_get_parameters(in_param1, &value,
- sizeof(int));
-
- result = _bt_dpm_set_allow_bluetooth_outgoing_call(value);
-
- break;
- }
- case BT_DPM_GET_ALLOW_OUTGOING_CALL: {
- dpm_status_t value = DPM_BT_ERROR;
-
- value = _bt_dpm_get_allow_bluetooth_outgoing_call();
- result = DPM_RESULT_SUCCESS;
- g_array_append_vals(*out_param1, &value, sizeof(int));
-
- break;
- }
- case BT_DPM_SET_PAIRING_STATE: {
- dpm_status_t value = DPM_BT_ERROR;
-
- __bt_service_get_parameters(in_param1, &value,
- sizeof(int));
-
- result = _bt_dpm_set_bluetooth_pairing_state(value);
-
- break;
- }
- case BT_DPM_GET_PAIRING_STATE: {
- dpm_status_t value = DPM_BT_ERROR;
-
- value = _bt_dpm_get_bluetooth_pairing_state();
- result = DPM_RESULT_SUCCESS;
- g_array_append_vals(*out_param1, &value, sizeof(int));
-
- break;
- }
- case BT_DPM_SET_PROFILE_STATE: {
- dpm_status_t value = DPM_BT_ERROR;
- dpm_profile_t profile = DPM_PROFILE_NONE;
-
- __bt_service_get_parameters(in_param1, &profile,
- sizeof(int));
- __bt_service_get_parameters(in_param2, &value,
- sizeof(int));
-
- result = _bt_dpm_set_bluetooth_profile_state(profile, value);
-
- break;
- }
- case BT_DPM_GET_PROFILE_STATE: {
- dpm_status_t value = DPM_BT_ERROR;
- dpm_profile_t profile = DPM_PROFILE_NONE;
-
- __bt_service_get_parameters(in_param2, &profile,
- sizeof(int));
-
- value = _bt_dpm_get_bluetooth_profile_state(profile);
- result = DPM_RESULT_SUCCESS;
- g_array_append_vals(*out_param1, &value, sizeof(int));
-
- break;
- }
- case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE: {
- dpm_status_t value = DPM_BT_ERROR;
-
- __bt_service_get_parameters(in_param1, &value,
- sizeof(int));
-
- result = _bt_dpm_set_bluetooth_desktop_connectivity_state(value);
-
- break;
- }
- case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE: {
- dpm_status_t value = DPM_BT_ERROR;
-
- value = _bt_dpm_get_bluetooth_desktop_connectivity_state();
- result = DPM_RESULT_SUCCESS;
- g_array_append_vals(*out_param1, &value, sizeof(int));
-
- break;
- }
- case BT_DPM_SET_DISCOVERABLE_STATE: {
- dpm_status_t value = DPM_BT_ERROR;
-
- __bt_service_get_parameters(in_param1, &value,
- sizeof(int));
-
- result = _bt_dpm_set_bluetooth_discoverable_state(value);
-
- break;
- }
- case BT_DPM_GET_DISCOVERABLE_STATE: {
- dpm_status_t value = DPM_BT_ERROR;
-
- value = _bt_dpm_get_bluetooth_discoverable_state();
- result = DPM_RESULT_SUCCESS;
- g_array_append_vals(*out_param1, &value, sizeof(int));
-
- break;
- }
- case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE: {
- dpm_status_t value = DPM_BT_ERROR;
-
- __bt_service_get_parameters(in_param1, &value,
- sizeof(int));
-
- result = _bt_dpm_set_bluetooth_limited_discoverable_state(value);
-
- break;
- }
- case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE: {
- dpm_status_t value = DPM_BT_ERROR;
-
- value = _bt_dpm_get_bluetooth_limited_discoverable_state();
- result = DPM_RESULT_SUCCESS;
- g_array_append_vals(*out_param1, &value, sizeof(int));
-
- break;
- }
- case BT_DPM_SET_DATA_TRANSFER_STATE: {
- dpm_status_t value = DPM_BT_ERROR;
-
- __bt_service_get_parameters(in_param1, &value,
- sizeof(int));
-
- result = _bt_dpm_set_bluetooth_data_transfer_state(value);
-
- break;
- }
- case BT_DPM_GET_DATA_TRANSFER_STATE: {
- dpm_status_t value = DPM_BT_ERROR;
-
- value = _bt_dpm_get_allow_bluetooth_data_transfer_state();
- result = DPM_RESULT_SUCCESS;
- g_array_append_vals(*out_param1, &value, sizeof(int));
-
- break;
- }
- case BT_PXP_SET_PROPERTY: {
- bluetooth_device_address_t address = { {0} };
- unsigned int property = 0;
- unsigned int value = 0;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &property, sizeof(int));
- __bt_service_get_parameters(in_param3,
- &value, sizeof(int));
-
- result = bt_set_proximity_property(&address, property, value);
- break;
- }
- case BT_PXP_GET_PROPERTY: {
- bluetooth_device_address_t address = { {0} };
- unsigned int property = 0;
- int value = 0;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2,
- &property, sizeof(unsigned int));
-
- result = bt_get_proximity_property(&address, property, &value);
- if (result == BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &value,
- sizeof(int));
- }
- break;
- }
- case BT_PXP_GET_SUPPORTED_SERIVCES: {
- bluetooth_device_address_t address = { {0} };
- unsigned int property = 0;
-
- __bt_service_get_parameters(in_param1,
- &address, sizeof(bluetooth_device_address_t));
-
- result = bt_get_proximity_supported_services(&address, &property);
- if (result == BLUETOOTH_ERROR_NONE) {
- g_array_append_vals(*out_param1, &property,
- sizeof(int));
- }
- break;
- }
- case BT_PXP_REGISTER_REPORTER: {
- result = bt_register_proximity_reporter();
- break;
- }
- case BT_PXP_UNREGISTER_REPORTER: {
- result = bt_unregister_proximity_reporter();
- break;
- }
- default:
- result = BLUETOOTH_ERROR_INTERNAL;
- break;
- }
-
- return result;
-}
-
-int __bt_obexd_request(int function_name,
- int request_type,
- int request_id,
- GDBusMethodInvocation *context,
- GVariant *in_param1,
- GVariant *in_param2,
- GVariant *in_param3,
- GVariant *in_param4,
- GArray **out_param1)
-{
- BT_DBG("+");
-
- int result;
-
- BT_DBG("function_name : %x", function_name);
-
- switch (function_name) {
- case BT_OPP_PUSH_FILES: {
- BT_DBG("BT_OPP_PUSH_FILES");
- int i;
- bluetooth_device_address_t address = { {0} };
- bt_file_path_t *path;
- char **file_path;
- int file_count;
- GArray *param2;
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param3, &file_count,
- sizeof(int));
-
- file_path = g_new0(char *, file_count + 1);
-
- param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
- __bt_fill_garray_from_variant(in_param2, param2);
-
- for (i = 0; i < file_count; i++) {
- path = &g_array_index(param2, bt_file_path_t, i);
- file_path[i] = g_strdup(path->path);
- }
- BT_DBG("_bt_opp_client_push_files");
- result = _bt_opp_client_push_files(request_id, context,
- &address, file_path,
- file_count);
-
- for (i = 0; i < file_count; i++)
- g_free(file_path[i]);
-
- g_free(file_path);
- g_array_free(param2, TRUE);
-
- break;
- }
- case BT_OPP_CANCEL_PUSH: {
- result = _bt_opp_client_cancel_push();
-
- break;
- }
- case BT_OPP_IS_PUSHING_FILES: {
- gboolean is_sending = FALSE;
-
- result = _bt_opp_client_is_sending(&is_sending);
-
- g_array_append_vals(*out_param1, &is_sending,
- sizeof(gboolean));
- break;
- }
- case BT_OPP_GET_TRANSFER_PROGRESS: {
- int direction;
- int transfer_id;
- guint8 progress = 0;
-
- __bt_service_get_parameters(in_param1, &direction,
- sizeof(int));
- __bt_service_get_parameters(in_param2, &transfer_id,
- sizeof(int));
- if (direction)
- result = _bt_opp_get_client_progress(&progress);
- else
- result = _bt_opp_get_server_progress(transfer_id, &progress);
-
- g_array_append_vals(*out_param1, &progress,
- sizeof(guint8));
-
- break;
- }
- case BT_OBEX_SERVER_ALLOCATE: {
- int app_pid;
- gboolean is_native;
- char *path;
- char *sender;
-
- sender = (char *)g_dbus_method_invocation_get_sender(context);
-
- path = (char *)g_variant_get_data(in_param1);
- __bt_service_get_parameters(in_param2, &is_native,
- sizeof(gboolean));
- __bt_service_get_parameters(in_param3, &app_pid,
- sizeof(int));
-
- result = _bt_obex_server_allocate(sender,
- path, app_pid, is_native);
-
- break;
- }
- case BT_OBEX_SERVER_DEALLOCATE: {
- int app_pid;
- gboolean is_native;
-
- __bt_service_get_parameters(in_param1, &is_native,
- sizeof(gboolean));
- __bt_service_get_parameters(in_param2, &app_pid,
- sizeof(int));
-
- result = _bt_obex_server_deallocate(app_pid, is_native);
- break;
- }
- case BT_OBEX_SERVER_IS_ACTIVATED: {
- gboolean is_activated = FALSE;
-
- result = _bt_obex_server_is_activated(&is_activated);
-
- g_array_append_vals(*out_param1, &is_activated,
- sizeof(gboolean));
-
- break;
- }
- case BT_OBEX_SERVER_ACCEPT_CONNECTION: {
- result = _bt_obex_server_accept_connection(request_id);
-
- break;
- }
- case BT_OBEX_SERVER_REJECT_CONNECTION: {
- result = _bt_obex_server_reject_connection();
-
- break;
- }
- case BT_OBEX_SERVER_ACCEPT_FILE: {
- char *file_name;
-
- file_name = (char *)g_variant_get_data(in_param1);
-
- result = _bt_obex_server_accept_authorize(file_name, TRUE);
-
- break;
- }
- case BT_OBEX_SERVER_REJECT_FILE: {
- result = _bt_obex_server_reject_authorize();
-
- break;
- }
- case BT_OBEX_SERVER_SET_PATH: {
- gboolean is_native;
- char *destination_path;
-
- destination_path = (char *)g_variant_get_data(in_param1);
- __bt_service_get_parameters(in_param2, &is_native,
- sizeof(gboolean));
-
- result = _bt_obex_server_set_destination_path(destination_path,
- is_native);
-
- break;
- }
- case BT_OBEX_SERVER_SET_ROOT: {
- char *root;
-
- root = (char *)g_variant_get_data(in_param1);
-
- result = _bt_obex_server_set_root(root);
-
- break;
- }
- case BT_OBEX_SERVER_CANCEL_TRANSFER: {
- int transfer_id;
-
- __bt_service_get_parameters(in_param1, &transfer_id,
- sizeof(int));
-
- result = _bt_obex_server_cancel_transfer(transfer_id);
-
- break;
- }
- case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS: {
- result = _bt_obex_server_cancel_all_transfers();
-
- break;
- }
- case BT_OBEX_SERVER_IS_RECEIVING: {
- gboolean is_receiving = FALSE;
-
- result = _bt_obex_server_is_receiving(&is_receiving);
-
- g_array_append_vals(*out_param1, &is_receiving,
- sizeof(gboolean));
- break;
- }
- case BT_PBAP_CONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
-
- result = _bt_pbap_connect(&address);
- break;
- }
- case BT_PBAP_DISCONNECT: {
- bluetooth_device_address_t address = { {0} };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
-
- result = _bt_pbap_disconnect(&address);
- break;
- }
- case BT_PBAP_GET_PHONEBOOK_SIZE: {
- bluetooth_device_address_t address = { {0} };
- bt_pbap_folder_t folder = { 0, };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2, &folder,
- sizeof(bt_pbap_folder_t));
-
- result = _bt_pbap_get_phonebook_size(&address,
- folder.addressbook, folder.folder_type);
- break;
- }
- case BT_PBAP_GET_PHONEBOOK: {
- bluetooth_device_address_t address = { {0} };
- bt_pbap_folder_t folder = { 0, };
- bt_pbap_pull_parameters_t app_param = { 0, };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2, &folder,
- sizeof(bt_pbap_folder_t));
- __bt_service_get_parameters(in_param3, &app_param,
- sizeof(bt_pbap_pull_parameters_t));
-
- result = _bt_pbap_get_phonebook(&address, folder.addressbook,
- folder.folder_type, &app_param);
- break;
- }
- case BT_PBAP_GET_LIST: {
- bluetooth_device_address_t address = { {0} };
- bt_pbap_folder_t folder = { 0, };
- bt_pbap_list_parameters_t app_param = { 0, };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2, &folder,
- sizeof(bt_pbap_folder_t));
- __bt_service_get_parameters(in_param3, &app_param,
- sizeof(bt_pbap_list_parameters_t));
-
- result = _bt_pbap_get_list(&address, folder.addressbook,
- folder.folder_type, &app_param);
- break;
- }
- case BT_PBAP_PULL_VCARD: {
- bluetooth_device_address_t address = { {0} };
- bt_pbap_folder_t folder = { 0, };
- bt_pbap_pull_vcard_parameters_t app_param = { 0, };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2, &folder,
- sizeof(bt_pbap_folder_t));
- __bt_service_get_parameters(in_param3, &app_param,
- sizeof(bt_pbap_pull_vcard_parameters_t));
-
- result = _bt_pbap_pull_vcard(&address, folder.addressbook,
- folder.folder_type, &app_param);
- break;
- }
- case BT_PBAP_PHONEBOOK_SEARCH: {
- bluetooth_device_address_t address = { {0} };
- bt_pbap_folder_t folder = { 0, };
- bt_pbap_search_parameters_t app_param = { 0, };
-
- __bt_service_get_parameters(in_param1, &address,
- sizeof(bluetooth_device_address_t));
- __bt_service_get_parameters(in_param2, &folder,
- sizeof(bt_pbap_folder_t));
- __bt_service_get_parameters(in_param3, &app_param,
- sizeof(bt_pbap_search_parameters_t));
-
- result = _bt_pbap_phonebook_search(&address, folder.addressbook,
- folder.folder_type, &app_param);
- break;
- }
-
- default:
- BT_ERR("Unknown function!");
- result = BLUETOOTH_ERROR_INTERNAL;
- break;
- }
-
- FN_END;
-
- return result;
-}
-
-int __bt_agent_request(int function_name,
- int request_type,
- int request_id,
- GDBusMethodInvocation *context,
- GVariant *in_param1,
- GVariant *in_param2,
- GVariant *in_param3,
- GVariant *in_param4,
- GArray **out_param1)
-{
- int result;
- switch (function_name) {
- case BT_SET_AUTHORIZATION: {
- int type;
- char *uuid;
- char *path;
- int fd;
-
- __bt_service_get_parameters(in_param1, &type, sizeof(int));
- uuid = (char *)g_variant_get_data(in_param2);
- path = (char *)g_variant_get_data(in_param3);
- __bt_service_get_parameters(in_param4, &fd, sizeof(int));
-
- result = _bt_register_osp_server_in_agent(type, uuid, path, fd);
- break;
- }
- case BT_UNSET_AUTHORIZATION: {
- int type;
- char *uuid;
-
- __bt_service_get_parameters(in_param1, &type, sizeof(int));
- uuid = (char *)g_variant_get_data(in_param2);
-
- result = _bt_unregister_osp_server_in_agent(type, uuid);
- break;
- }
- default:
- BT_ERR("Unknown function!");
- result = BLUETOOTH_ERROR_INTERNAL;
- break;
- }
-
- return result;
-}
-
-int __bt_core_request(int function_name,
- int request_type,
- int request_id,
- GDBusMethodInvocation *context,
- GVariant *in_param1)
-{
- int result;
-
- switch (function_name) {
- case BT_ENABLE_ADAPTER:
- {
- bt_status_t status;
-
- status = _bt_adapter_get_status();
-
- if (status == BT_ACTIVATING) {
- BT_DBG("Enabling in progress");
- result = BLUETOOTH_ERROR_IN_PROGRESS;
- } else if (status == BT_ACTIVATED) {
- BT_DBG("Already enabled");
- result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
- } else {
- _bt_adapter_set_status(BT_ACTIVATING);
- _bt_adapter_start_enable_timer();
- result = BLUETOOTH_ERROR_NONE;
- }
-
- break;
- }
- case BT_DISABLE_ADAPTER:
- {
- bt_status_t status;
-
- status = _bt_adapter_get_status();
- if (status == BT_DEACTIVATING) {
- BT_DBG("Disabling in progress");
- result = BLUETOOTH_ERROR_IN_PROGRESS;
- } else if (status == BT_DEACTIVATED) {
- BT_DBG("Already disabled");
- result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- } else {
- _bt_adapter_set_status(BT_DEACTIVATING);
- result = BLUETOOTH_ERROR_NONE;
- }
-
- break;
- }
- case BT_ENABLE_ADAPTER_LE:
- {
- bt_le_status_t le_status;
-
- le_status = _bt_adapter_get_le_status();
- if (le_status == BT_LE_ACTIVATING) {
- BT_DBG("Enabling in progress");
- result = BLUETOOTH_ERROR_IN_PROGRESS;
- } else if (le_status == BT_LE_ACTIVATED) {
- BT_DBG("Already enabled");
- result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
- } else {
- _bt_adapter_set_le_status(BT_LE_ACTIVATING);
- _bt_adapter_start_le_enable_timer();
- result = BLUETOOTH_ERROR_NONE;
- }
-
- break;
- }
- case BT_DISABLE_ADAPTER_LE:
- {
- bt_le_status_t le_status;
-
- le_status = _bt_adapter_get_le_status();
- if (le_status == BT_LE_DEACTIVATING) {
- BT_DBG("Disabling in progress");
- result = BLUETOOTH_ERROR_IN_PROGRESS;
- } else if (le_status == BT_LE_DEACTIVATED) {
- BT_DBG("Already disabled");
- result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- } else {
- _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
- result = BLUETOOTH_ERROR_NONE;
- }
-
- break;
- }
- default:
- BT_ERR("Unknown function!");
- result = BLUETOOTH_ERROR_INTERNAL;
- break;
- }
-
- return result;
-}
-
-gboolean __bt_service_check_privilege(int function_name,
- int service_type,
- const char *unique_name)
-{
- int ret_val;
- gboolean result = TRUE;
- char *client_creds = NULL;
- char *user_creds = NULL;
- char *client_session = "";
- enum cynara_client_creds client_creds_method = CLIENT_METHOD_SMACK;
- enum cynara_user_creds user_creds_method = USER_METHOD_UID;
- char err_msg[256] = {0, };
-
- retv_if(unique_name == NULL, FALSE);
- retv_if(bt_service_conn == NULL, FALSE);
-
- ret_val = cynara_creds_get_default_client_method(&client_creds_method);
- if (ret_val != CYNARA_API_SUCCESS) {
- cynara_strerror(ret_val, err_msg, sizeof(err_msg));
- BT_ERR("Fail to get default client method: %s", err_msg);
- return FALSE;
- }
-
- ret_val = cynara_creds_get_default_user_method(&user_creds_method);
- if (ret_val != CYNARA_API_SUCCESS) {
- cynara_strerror(ret_val, err_msg, sizeof(err_msg));
- BT_ERR("Fail to get default user method: %s", err_msg);
- return FALSE;
- }
-
- ret_val = cynara_creds_gdbus_get_client(bt_service_conn, unique_name, client_creds_method, &client_creds);
- if (ret_val != CYNARA_API_SUCCESS) {
- cynara_strerror(ret_val, err_msg, sizeof(err_msg));
- BT_ERR("Fail to get client credential: %s", err_msg);
- return FALSE;
- }
-
- ret_val = cynara_creds_gdbus_get_user(bt_service_conn, unique_name, user_creds_method, &user_creds);
- if (ret_val != CYNARA_API_SUCCESS) {
- cynara_strerror(ret_val, err_msg, sizeof(err_msg));
- BT_ERR("Fail to get user credential: %s", err_msg);
- if (client_creds)
- free(client_creds);
- return FALSE;
- }
-
- BT_DBG("%s, %s, %s", unique_name, client_creds, user_creds);
-
- switch (function_name) {
- case BT_SET_LOCAL_NAME:
- case BT_START_DISCOVERY:
- case BT_START_CUSTOM_DISCOVERY:
- case BT_CANCEL_DISCOVERY:
- case BT_OOB_ADD_REMOTE_DATA:
- case BT_OOB_REMOVE_REMOTE_DATA:
- case BT_SET_ADVERTISING:
- case BT_SET_CUSTOM_ADVERTISING:
- case BT_SET_ADVERTISING_PARAMETERS:
- case BT_START_LE_DISCOVERY:
- case BT_STOP_LE_DISCOVERY:
- case BT_SET_SCAN_PARAMETERS:
- case BT_SET_SCAN_TYPE:
-
- case BT_BOND_DEVICE:
- case BT_CANCEL_BONDING:
- case BT_UNBOND_DEVICE:
- case BT_SET_ALIAS:
- case BT_SET_AUTHORIZATION:
- case BT_UNSET_AUTHORIZATION:
- case BT_SEARCH_SERVICE:
-
- case BT_RFCOMM_CLIENT_CONNECT:
- case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
- case BT_RFCOMM_SOCKET_DISCONNECT:
- case BT_RFCOMM_SOCKET_WRITE:
- case BT_RFCOMM_CREATE_SOCKET:
- case BT_RFCOMM_REMOVE_SOCKET:
-
- case BT_OPP_PUSH_FILES:
- case BT_OPP_CANCEL_PUSH:
-
- case BT_OBEX_SERVER_ACCEPT_CONNECTION:
- case BT_OBEX_SERVER_REJECT_CONNECTION:
- case BT_OBEX_SERVER_ACCEPT_FILE:
- case BT_OBEX_SERVER_REJECT_FILE:
- case BT_OBEX_SERVER_SET_PATH:
- case BT_OBEX_SERVER_SET_ROOT:
- case BT_OBEX_SERVER_CANCEL_TRANSFER:
- case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS:
-
- case BT_AUDIO_CONNECT:
- case BT_AUDIO_DISCONNECT:
- case BT_AG_CONNECT:
- case BT_AG_DISCONNECT:
- case BT_AV_CONNECT:
- case BT_AV_DISCONNECT:
- case BT_AV_SOURCE_CONNECT:
- case BT_AV_SOURCE_DISCONNECT:
- case BT_AVRCP_CONTROL_CONNECT:
- case BT_AVRCP_CONTROL_DISCONNECT:
- case BT_AVRCP_HANDLE_CONTROL:
- case BT_AVRCP_SET_TRACK_INFO:
- case BT_AVRCP_SET_PROPERTY:
- case BT_AVRCP_SET_PROPERTIES:
- case BT_AVRCP_CONTROL_SET_PROPERTY:
-
- case BT_HF_CONNECT:
- case BT_HF_DISCONNECT:
-
- case BT_HID_CONNECT:
- case BT_HID_DISCONNECT:
-
- case BT_HID_DEVICE_ACTIVATE:
- case BT_HID_DEVICE_DEACTIVATE:
- case BT_HID_DEVICE_CONNECT:
- case BT_HID_DEVICE_DISCONNECT:
- case BT_HID_DEVICE_SEND_MOUSE_EVENT:
- case BT_HID_DEVICE_SEND_KEY_EVENT:
- case BT_HID_DEVICE_SEND_REPLY_TO_REPORT:
- case BT_HID_DEVICE_SEND_CUSTOM_EVENT:
-
- case BT_CONNECT_LE:
- case BT_DISCONNECT_LE:
-
- case BT_SET_ADVERTISING_DATA:
- case BT_SET_SCAN_RESPONSE_DATA:
-
- case BT_HDP_CONNECT:
- case BT_HDP_DISCONNECT:
- case BT_HDP_SEND_DATA:
- case BT_HDP_REGISTER_SINK_APP:
- case BT_HDP_UNREGISTER_SINK_APP:
-
- case BT_DPM_SET_ALLOW_BT_MODE:
- case BT_DPM_GET_ALLOW_BT_MODE:
- case BT_DPM_SET_DEVICE_RESTRITION:
- case BT_DPM_GET_DEVICE_RESTRITION:
- case BT_DPM_SET_UUID_RESTRITION:
- case BT_DPM_GET_UUID_RESTRITION:
- case BT_DPM_ADD_DEVICES_BLACKLIST:
- case BT_DPM_ADD_DEVICES_WHITELIST:
- case BT_DPM_ADD_UUIDS_BLACKLIST:
- case BT_DPM_ADD_UUIDS_WHITELIST:
- case BT_DPM_CLEAR_DEVICES_BLACKLIST:
- case BT_DPM_CLEAR_DEVICES_WHITELIST:
- case BT_DPM_CLEAR_UUIDS_BLACKLIST:
- case BT_DPM_CLEAR_UUIDS_WHITELIST:
- case BT_DPM_REMOVE_DEVICE_BLACKLIST:
- case BT_DPM_REMOVE_DEVICE_WHITELIST:
- case BT_DPM_REMOVE_UUID_BLACKLIST:
- case BT_DPM_REMOVE_UUID_WHITELIST:
- case BT_DPM_GET_DEVICES_BLACKLIST:
- case BT_DPM_GET_DEVICES_WHITELIST:
- case BT_DPM_GET_UUIDS_BLACKLIST:
- case BT_DPM_GET_UUIDS_WHITELIST:
- case BT_DPM_SET_ALLOW_OUTGOING_CALL:
- case BT_DPM_GET_ALLOW_OUTGOING_CALL:
- case BT_DPM_SET_PAIRING_STATE:
- case BT_DPM_GET_PAIRING_STATE:
- case BT_DPM_SET_PROFILE_STATE:
- case BT_DPM_GET_PROFILE_STATE:
- case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE:
- case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE:
- case BT_DPM_SET_DISCOVERABLE_STATE:
- case BT_DPM_GET_DISCOVERABLE_STATE:
- case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE:
- case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE:
- case BT_DPM_SET_DATA_TRANSFER_STATE:
- case BT_DPM_GET_DATA_TRANSFER_STATE:
-
- case BT_NETWORK_ACTIVATE:
- case BT_NETWORK_DEACTIVATE:
- case BT_NETWORK_CONNECT:
- case BT_NETWORK_DISCONNECT:
- case BT_NETWORK_SERVER_DISCONNECT:
-
- case BT_GATT_GET_PRIMARY_SERVICES:
- case BT_GATT_DISCOVER_CHARACTERISTICS:
- case BT_GATT_SET_PROPERTY_REQUEST:
- case BT_GATT_READ_CHARACTERISTIC:
- case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
- case BT_GATT_REGISTER_APPLICATION:
- case BT_GATT_REGISTER_SERVICE:
- case BT_GATT_SEND_RESPONSE:
-
- case BT_REQ_ATT_MTU:
- case BT_PBAP_CONNECT:
- case BT_PBAP_DISCONNECT:
- case BT_PBAP_GET_PHONEBOOK_SIZE:
- case BT_PBAP_GET_PHONEBOOK:
- case BT_PBAP_GET_LIST:
- case BT_PBAP_PULL_VCARD:
- case BT_PBAP_PHONEBOOK_SEARCH:
- case BT_AUDIO_SELECT_ROLE:
-
- ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
- BT_PRIVILEGE_PUBLIC);
-
- if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
- BT_ERR("Fail to access: %s", BT_PRIVILEGE_PUBLIC);
- result = FALSE;
- }
-
- /* Need to check mediastorage privilege */
- if (function_name == BT_PBAP_GET_PHONEBOOK ||
- function_name == BT_PBAP_PULL_VCARD) {
- ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
- MEDIASTORAGE_PRIVILEGE);
-
- if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
- BT_ERR("Fail to access: %s", MEDIASTORAGE_PRIVILEGE);
- result = FALSE;
- }
- }
- break;
-
- case BT_ENABLE_ADAPTER:
- case BT_DISABLE_ADAPTER:
- case BT_RESET_ADAPTER:
- case BT_RECOVER_ADAPTER:
- case BT_ENABLE_ADAPTER_LE:
- case BT_DISABLE_ADAPTER_LE:
- case BT_SET_CONNECTABLE:
- case BT_SET_DISCOVERABLE_MODE:
- case BT_ADD_WHITE_LIST:
- case BT_REMOVE_WHITE_LIST:
- case BT_CLEAR_WHITE_LIST:
- case BT_SET_MANUFACTURER_DATA:
- case BT_SET_PASSKEY_NOTIFICATION:
- case BT_SET_PROFILE_RESTRICTED:
-
- case BT_DISCONNECT_DEVICE:
- case BT_CANCEL_SEARCH_SERVICE:
- case BT_ENABLE_RSSI:
-
- case BT_RFCOMM_ACCEPT_CONNECTION:
- case BT_RFCOMM_REJECT_CONNECTION:
- case BT_RFCOMM_LISTEN:
- case BT_RFCOMM_CREATE_SOCKET_EX:
- case BT_RFCOMM_REMOVE_SOCKET_EX:
-
- case BT_HID_ENABLE_BARCODE_FEATURE:
-
- case BT_AVRCP_CONTROL_GET_PROPERTY:
- case BT_AVRCP_GET_TRACK_INFO:
- case BT_AVRCP_TRANSPORT_SET_PROPERTY:
-
-
- case BT_SET_CONTENT_PROTECT:
- case BT_BOND_DEVICE_BY_TYPE:
- case BT_SET_LE_PRIVACY:
- case BT_SET_LE_STATIC_RANDOM_ADDRESS:
- case BT_LE_CONN_UPDATE:
- case BT_UPDATE_LE_CONNECTION_MODE:
- case BT_GET_DEVICE_IDA:
- case BT_ENABLE_FORCE_HCI_DUMP:
- case BT_LE_READ_MAXIMUM_DATA_LENGTH:
- case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH:
- case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH:
- case BT_LE_SET_DATA_LENGTH:
- case BT_LE_OOB_READ_LOCAL_DATA:
- case BT_LE_OOB_ADD_REMOTE_DATA:
-
- case BT_LE_IPSP_INIT:
- case BT_LE_IPSP_DEINIT:
- case BT_LE_IPSP_CONNECT:
- case BT_LE_IPSP_DISCONNECT:
- case BT_PXP_SET_PROPERTY:
- case BT_PXP_GET_PROPERTY:
- case BT_PXP_GET_SUPPORTED_SERIVCES:
- case BT_PXP_REGISTER_REPORTER:
- case BT_PXP_UNREGISTER_REPORTER:
- ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
- BT_PRIVILEGE_PLATFORM);
-
- if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
- BT_ERR("Fail to access: %s", BT_PRIVILEGE_PLATFORM);
- result = FALSE;
- }
- break;
-
- case BT_CHECK_ADAPTER:
- case BT_GET_RSSI:
-
- case BT_GET_LOCAL_NAME:
- case BT_GET_LOCAL_ADDRESS:
- case BT_GET_LOCAL_VERSION:
- case BT_IS_SERVICE_USED:
- case BT_GET_DISCOVERABLE_MODE:
- case BT_GET_DISCOVERABLE_TIME:
- case BT_IS_DISCOVERYING:
- case BT_IS_LE_DISCOVERYING:
- case BT_IS_CONNECTABLE:
- case BT_GET_BONDED_DEVICES:
- case BT_GET_PROFILE_CONNECTED_DEVICES:
- case BT_GET_BONDED_DEVICE:
- case BT_PASSKEY_REPLY:
- case BT_PASSKEY_CONFIRMATION_REPLY:
- case BT_GET_IS_ALIAS_SET:
- case BT_IS_DEVICE_CONNECTED:
- case BT_GET_CONNECTED_LINK_TYPE:
- case BT_SET_PROFILE_TRUSTED:
- case BT_GET_PROFILE_TRUSTED:
- case BT_GET_SPEAKER_GAIN:
- case BT_SET_SPEAKER_GAIN:
- case BT_OOB_READ_LOCAL_DATA:
- case BT_RFCOMM_CLIENT_IS_CONNECTED:
- case BT_RFCOMM_IS_UUID_AVAILABLE:
- case BT_GET_ADVERTISING_DATA:
- case BT_GET_SCAN_RESPONSE_DATA:
- case BT_IS_ADVERTISING:
- case BT_REGISTER_SCAN_FILTER:
- case BT_IS_SCAN_FILTER_SUPPORTED:
- case BT_GET_PROFILE_RESTRICTED:
- case BT_GET_ATT_MTU:
-
- case BT_OBEX_SERVER_ALLOCATE:
- case BT_OBEX_SERVER_DEALLOCATE:
- case BT_OBEX_SERVER_IS_ACTIVATED:
- case BT_OPP_GET_TRANSFER_PROGRESS:
- /* Non-privilege control */
- break;
- default:
- BT_ERR("Unknown function!");
- result = FALSE;
- break;
- }
-
- if (client_creds)
- free(client_creds);
-
- if (user_creds)
- free(user_creds);
-
- return result;
-}
-
-GDBusNodeInfo *__bt_service_create_method_node_info
- (const gchar *introspection_data)
-{
- GError *err = NULL;
- GDBusNodeInfo *node_info = NULL;
-
- if (introspection_data == NULL) {
- ERR("Introspection XML not present");
- return NULL;
- }
-
- node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
-
- if (err) {
- ERR("Unable to create node: %s", err->message);
- g_clear_error(&err);
- }
- return node_info;
-}
-
-int __bt_service_register_object(GDBusConnection *conn,
- GDBusNodeInfo *node_info, gboolean reg)
-{
- static guint service_id = 0;
- GError *error = NULL;
-
- if (reg) {
- if (node_info == NULL)
- return -1;
-
- service_id = g_dbus_connection_register_object(conn,
- BT_SERVICE_PATH,
- node_info->interfaces[0],
- &method_table,
- NULL, NULL, &error);
- if (service_id == 0)
- return -1;
- } else {
- if (service_id > 0) {
- g_dbus_connection_unregister_object(conn,
- service_id);
- service_id = 0;
- }
- }
-
- return 0;
-}
-
-static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
- const gchar *name, gpointer user_data)
-{
- GDBusNodeInfo *node_info = NULL;
-
- BT_INFO("bus acquired");
-
- ret_if(connection == NULL);
-
- node_info = __bt_service_create_method_node_info(
- bt_service_introspection_xml);
- ret_if(node_info == NULL);
-
- __bt_service_register_object(connection, node_info, TRUE);
- g_dbus_node_info_unref(node_info);
-
- bt_service_conn = connection;
-}
-
-static void __bt_service_name_acquired_handler(GDBusConnection *connection,
- const gchar *name, gpointer user_data)
-{
- BT_INFO("name acquired");
- name_acquired = TRUE;
-}
-
-static void __bt_service_name_lost_handler(GDBusConnection *connection,
- const gchar *name, gpointer user_data)
-{
- BT_INFO("name lost");
- name_acquired = FALSE;
-}
-
-gboolean _is_name_acquired(void)
-{
- return name_acquired;
-}
-
-int _bt_service_register(void)
-{
- GDBusConnection *conn;
- GError *err = NULL;
-
- conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
- bt_service_conn = conn;
-
- owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- BT_SERVICE_NAME,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- __bt_service_bus_acquired_handler,
- __bt_service_name_acquired_handler,
- __bt_service_name_lost_handler,
- NULL, NULL);
- BT_DBG("owner_id is [%d]", owner_id);
- if (owner_id == 0)
- goto fail;
-
- return BLUETOOTH_ERROR_NONE;
-
-fail:
- if (bt_service_conn) {
- g_object_unref(bt_service_conn);
- bt_service_conn = NULL;
- }
-
- return BLUETOOTH_ERROR_INTERNAL;
-}
-
-void _bt_service_unregister(void)
-{
- if (bt_service_conn) {
- __bt_service_register_object(bt_service_conn, NULL, FALSE);
- if (bt_service_conn) {
- g_object_unref(bt_service_conn);
- bt_service_conn = NULL;
- }
- if (owner_id > 0) {
- g_bus_unown_name(owner_id);
- owner_id = 0;
- }
- }
-}
-
-int _bt_service_cynara_init(void)
-{
- int result;
- char err_msg[256] = {0, };
-
- retv_if(p_cynara != NULL, BLUETOOTH_ERROR_ALREADY_INITIALIZED);
-
- result = cynara_initialize(&p_cynara, conf);
-
- if (result != CYNARA_API_SUCCESS) {
- cynara_strerror(result, err_msg, sizeof(err_msg));
- BT_ERR("Fail to initialize cynara: [%s]", err_msg);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_service_cynara_deinit(void)
-{
- int result;
- char err_msg[256] = {0, };
-
- ret_if(p_cynara == NULL);
-
- result = cynara_finish(p_cynara);
-
- if (result != CYNARA_API_SUCCESS) {
- cynara_strerror(result, err_msg, sizeof(err_msg));
- BT_ERR("Fail to finish cynara: [%s]", err_msg);
- return;
- }
-
- p_cynara = NULL;
- conf = NULL;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <dbus/dbus.h>
-#include <gio/gio.h>
-#include <glib.h>
-#include <dlog.h>
-#include <string.h>
-#include <vconf.h>
-#include <syspopup_caller.h>
-#include <aul.h>
-
-#include "bt-internal-types.h"
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-#include "bt-service-adapter.h"
-#include "bt-service-adapter-le.h"
-#include "bt-service-util.h"
-
-
-#define BT_ADV_INTERVAL_MIN 20 /* msec */
-#define BT_ADV_INTERVAL_MAX 10240
-#define BT_ADV_INTERVAL_SPLIT 0.625
-#define BT_DEFAULT_ADV_MIN_INTERVAL 500
-#define BT_DEFAULT_ADV_MAX_INTERVAL 500
-#define BT_ADV_FILTER_POLICY_DEFAULT 0x00
-#define BT_ADV_TYPE_DEFAULT 0x00
-#define BT_ADV_FILTER_POLICY_ALLOW_SCAN_CONN_WL_ONLY 0x03
-#define BT_SCAN_INTERVAL_SPLIT 0.625
-
-
-typedef struct {
- int adv_inst_max;
- int rpa_offloading;
- int max_filter;
-} bt_adapter_le_feature_info_t;
-
-typedef struct {
- char *sender;
- int adv_handle;
- gboolean is_advertising;
- guint hold_timer_id;
-} bt_adapter_le_adv_slot_t;
-
-typedef struct {
- char *sender;
- GSList *filter_list;
- gboolean is_scanning;
-} bt_adapter_le_scanner_t;
-
-static bluetooth_advertising_params_t adv_params = {
- BT_DEFAULT_ADV_MIN_INTERVAL,
- BT_DEFAULT_ADV_MAX_INTERVAL,
- BT_ADV_FILTER_POLICY_DEFAULT,
- BT_ADV_TYPE_DEFAULT};
-static bluetooth_advertising_data_t adv_data = { {0} };
-static int adv_data_len;
-static bluetooth_scan_resp_data_t resp_data = { {0} };
-static int resp_data_len;
-
-static bt_adapter_le_feature_info_t le_feature_info = { 1, 0, 0 };
-static bt_adapter_le_adv_slot_t *le_adv_slot = NULL;
-
-GSList *scanner_list = NULL;
-static gboolean is_le_set_scan_parameter = FALSE;
-static gboolean is_le_scanning = FALSE;
-static gboolean scan_filter_enabled = FALSE;
-static bt_le_scan_type_t le_scan_type = BT_LE_ACTIVE_SCAN;
-static bluetooth_le_scan_params_t le_scan_params = { BT_LE_ACTIVE_SCAN, 0, 0 };
-
-static GSList *gatt_client_senders = NULL;
-
-
-gboolean _bt_is_set_scan_parameter(void)
-{
- return is_le_set_scan_parameter;
-}
-
-void _bt_init_gatt_client_senders(void)
-{
- _bt_clear_request_list();
-}
-
-int _bt_insert_gatt_client_sender(char *sender)
-{
- char *info;
-
- retv_if(sender == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
-
- info = g_strdup(sender);
- retv_if(info == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION);
-
- gatt_client_senders = g_slist_append(gatt_client_senders, info);
-
- BT_DBG("insert sender: %s", sender);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_delete_gatt_client_sender(char *sender)
-{
- GSList *l;
- char *info;
-
- BT_DBG("remove sender: %s", sender);
-
- for (l = gatt_client_senders; l != NULL; l = g_slist_next(l)) {
- info = l->data;
- if (info == NULL)
- continue;
-
- if (g_strcmp0(info, sender) == 0) {
- BT_DBG("remove info");
- gatt_client_senders = g_slist_remove(gatt_client_senders, info);
- g_free(info);
- return BLUETOOTH_ERROR_NONE;
- }
- }
-
- return BLUETOOTH_ERROR_NOT_FOUND;
-}
-
-void _bt_clear_gatt_client_senders(void)
-{
- if (gatt_client_senders) {
- g_slist_foreach(gatt_client_senders, (GFunc)g_free, NULL);
- g_slist_free(gatt_client_senders);
- gatt_client_senders = NULL;
- }
-}
-#if 0
-static void __bt_send_foreach_event(gpointer data, gpointer user_data)
-{
- char *sender = data;
- GVariant *param = user_data;
-
- _bt_send_event_to_dest(sender, BT_DEVICE_EVENT, BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
- param);
-}
-#endif
-void _bt_send_char_value_changed_event(void *param)
-{
-#if 0
- g_slist_foreach(gatt_client_senders, __bt_send_foreach_event,
- (gpointer)param);
-#else
- _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED, param);
-#endif
-}
-
-void __bt_free_le_adv_slot(void)
-{
- int i;
-
- if (le_adv_slot == NULL)
- return;
-
- for (i = 0; i < le_feature_info.adv_inst_max; i++) {
- if (le_adv_slot[i].sender)
- g_free(le_adv_slot[i].sender);
- if (le_adv_slot[i].hold_timer_id > 0)
- g_source_remove(le_adv_slot[i].hold_timer_id);
- }
- g_free(le_adv_slot);
- le_adv_slot = NULL;
-}
-
-static void __bt_free_le_scanner(bt_adapter_le_scanner_t *scanner)
-{
- g_free(scanner->sender);
- g_slist_free_full(scanner->filter_list, g_free);
- g_free(scanner);
-}
-
-static void __bt_free_le_scanner_all(void)
-{
- g_slist_free_full(scanner_list, (GDestroyNotify)__bt_free_le_scanner);
- scanner_list = NULL;
-
- scan_filter_enabled = FALSE;
- is_le_scanning = FALSE;
- is_le_set_scan_parameter = FALSE;
- le_scan_params.type = BT_LE_ACTIVE_SCAN;
- le_scan_params.interval = 0;
- le_scan_params.window = 0;
-}
-
-int _bt_le_set_max_packet_len(void)
-{
- int result = BLUETOOTH_ERROR_NONE;
- int tx_octets, tx_time;
- bluetooth_le_read_maximum_data_length_t max_len = {0};
-
- if (BLUETOOTH_ERROR_NONE != _bt_le_read_maximum_data_length(&max_len))
- return BLUETOOTH_ERROR_INTERNAL;
-
- if (max_len.max_tx_octets > BT_LE_TX_LEN_DEFAULT) {
- tx_octets = max_len.max_tx_octets > BT_LE_TX_LEN_MAX ?
- BT_LE_TX_LEN_MAX : max_len.max_tx_octets;
- tx_time = BT_LE_TX_TIME_MAX;
-
- result = _bt_le_write_host_suggested_default_data_length(tx_octets, tx_time);
-
- BT_DBG("Wrote max packet size : result[%d], MAX[%d], set[%d]",
- result, max_len.max_tx_octets, tx_octets);
- }
-
- return result;
-}
-
-gboolean _bt_update_le_feature_support(const char *item, const char *value)
-{
- if (item == NULL || value == NULL)
- return FALSE;
-
- if (!le_adv_slot)
- _bt_service_adapter_le_init();
-
- if (g_strcmp0(item, "adv_inst_max") == 0) {
- int slot_num;
-
- slot_num = atoi(value);
- retv_if(slot_num < 0, FALSE);
-
- if (slot_num != le_feature_info.adv_inst_max) {
- __bt_free_le_adv_slot();
- le_feature_info.adv_inst_max = slot_num;
- BT_INFO("Advertising instance max : %d", le_feature_info.adv_inst_max);
- le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max);
- }
- } else if (g_strcmp0(item, "rpa_offloading") == 0) {
- le_feature_info.rpa_offloading = atoi(value);
- BT_INFO("RPA offloading : %d", le_feature_info.rpa_offloading);
- } else if (g_strcmp0(item, "max_filter") == 0) {
- le_feature_info.max_filter = atoi(value);
- BT_INFO("BLE Scan max filter : %d", le_feature_info.max_filter);
- } else {
- BT_DBG("No registered item");
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean __bt_is_factory_test_mode(void)
-{
- int mode = 0;
-
- if (vconf_get_bool(VCONFKEY_BT_DUT_MODE, &mode)) {
- BT_ERR("Get the DUT Mode fail");
- return TRUE;
- }
-
- if (mode != FALSE) {
- BT_INFO("DUT Test Mode !!");
- return TRUE;
- }
-
- return FALSE;
-}
-
-int __bt_get_available_adv_slot_id(const char *sender, int adv_handle, gboolean use_reserved_slot)
-{
- int i;
-
- if (le_adv_slot == NULL) {
- BT_ERR("le_adv_slot is NULL");
- return -1;
- }
-
- BT_DBG("adv_inst_max : %d", le_feature_info.adv_inst_max);
-
- for (i = 0; i < le_feature_info.adv_inst_max; i++) {
- if (le_adv_slot[i].sender == NULL)
- continue;
- if ((g_strcmp0(le_adv_slot[i].sender, sender) == 0) && (le_adv_slot[i].adv_handle == adv_handle))
- return i;
- }
-
- if (le_feature_info.adv_inst_max <= 1)
- i = 0;
- else if (use_reserved_slot == TRUE)
- i = 1;
- else
- i = 2;
-
- for (; i < le_feature_info.adv_inst_max; i++) {
- if (le_adv_slot[i].sender == NULL)
- return i;
- }
-
- return -1;
-}
-
-static void __bt_register_adv_slot_owner(const char *sender, int adv_handle, int slot_id)
-{
- if (le_adv_slot[slot_id].sender == NULL) {
- le_adv_slot[slot_id].sender = strdup(sender);
- le_adv_slot[slot_id].adv_handle = adv_handle;
- }
-}
-
-void _bt_unregister_adv_slot_owner(int slot_id)
-{
- if (le_adv_slot[slot_id].hold_timer_id > 0) {
- BT_INFO("Hold state adv is not unregistered");
- return;
- }
-
- g_free(le_adv_slot[slot_id].sender);
- le_adv_slot[slot_id].sender = NULL;
- le_adv_slot[slot_id].adv_handle = 0;
-}
-
-const char* _bt_get_adv_slot_owner(int slot_id)
-{
- if (le_adv_slot == NULL)
- return NULL;
-
- return le_adv_slot[slot_id].sender;
-}
-
-int _bt_get_adv_slot_adv_handle(int slot_id)
-{
- if (le_adv_slot == NULL)
- return 0;
-
- return le_adv_slot[slot_id].adv_handle;
-}
-
-void _bt_set_advertising_status(int slot_id, gboolean mode)
-{
- le_adv_slot[slot_id].is_advertising = mode;
-}
-
-gboolean _bt_is_advertising(void)
-{
- gboolean status = FALSE;
- int i;
-
- if (le_adv_slot == NULL)
- return FALSE;
-
- for (i = 0; i < le_feature_info.adv_inst_max; i++) {
- if (le_adv_slot[i].is_advertising == TRUE)
- status = TRUE;
- }
-
- return status;
-}
-
-void _bt_stop_advertising_by_terminated_process(const char* terminated_name)
-{
- int i;
-
- if (le_adv_slot == NULL)
- return;
-
- for (i = 0; i < le_feature_info.adv_inst_max; i++) {
- if (le_adv_slot[i].sender != NULL) {
- if (strcasecmp(terminated_name, le_adv_slot[i].sender) == 0) {
- BT_ERR("Stop advertising by terminated process(%s).", terminated_name);
- _bt_set_advertising(terminated_name, le_adv_slot[i].adv_handle, FALSE, FALSE);
- }
- }
- }
-}
-
-gboolean _bt_get_advertising_params(bluetooth_advertising_params_t *params)
-{
- if (params == NULL)
- return FALSE;
-
- memcpy(params, &adv_params, sizeof(bluetooth_advertising_params_t));
-
- return TRUE;
-}
-
-int _bt_set_advertising(const char *sender, int adv_handle, gboolean enable, gboolean use_reserved_slot)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret;
- int slot_id;
-
- if (__bt_is_factory_test_mode()) {
- BT_ERR("Unable to start advertising in factory binary !!");
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- if (_bt_adapter_get_status() != BT_ACTIVATED &&
- _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- slot_id = __bt_get_available_adv_slot_id(sender, adv_handle, use_reserved_slot);
- if (slot_id == -1) {
- BT_ERR("There is NO available slot!!");
- return BLUETOOTH_ERROR_NO_RESOURCES;
- }
-
- if (le_adv_slot[slot_id].is_advertising == TRUE && enable == TRUE)
- return BLUETOOTH_ERROR_IN_PROGRESS;
-
- if (le_adv_slot[slot_id].hold_timer_id > 0) {
- g_source_remove(le_adv_slot[slot_id].hold_timer_id);
- le_adv_slot[slot_id].hold_timer_id = 0;
- _bt_unregister_adv_slot_owner(slot_id);
- }
-
- if (le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
- return BLUETOOTH_ERROR_NOT_IN_OPERATION;
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- ret = g_dbus_proxy_call_sync(proxy, "SetAdvertising",
- g_variant_new("(bi)", enable, slot_id),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error) {
- BT_INFO("SetAdvertising %d, slot_id %d", enable, slot_id);
- BT_ERR("SetAdvertising Fail: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (enable == TRUE)
- __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
-
- le_adv_slot[slot_id].is_advertising = enable;
- BT_INFO_C("### Set advertising [%d], Slot id [%d]", enable, slot_id);
-
- if (ret)
- g_variant_unref(ret);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_set_custom_advertising(const char *sender, int adv_handle,
- gboolean enable, bluetooth_advertising_params_t *params, gboolean use_reserved_slot)
-{
- GDBusProxy *proxy;
- GVariant *ret;
- GError *error = NULL;
- guint32 min = 0;
- guint32 max = 0;
- int slot_id;
-
- BT_CHECK_PARAMETER(params, return);
-
- if (__bt_is_factory_test_mode()) {
- BT_ERR("Unable to start advertising in factory binary !!");
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- if (_bt_adapter_get_status() != BT_ACTIVATED &&
- _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- slot_id = __bt_get_available_adv_slot_id(sender, adv_handle, use_reserved_slot);
- if (slot_id == -1) {
- BT_ERR("There is NO available slot!!");
- return BLUETOOTH_ERROR_NO_RESOURCES;
- }
-
- if (le_adv_slot[slot_id].is_advertising == TRUE && enable == TRUE)
- return BLUETOOTH_ERROR_IN_PROGRESS;
-
- if (le_adv_slot[slot_id].hold_timer_id > 0) {
- g_source_remove(le_adv_slot[slot_id].hold_timer_id);
- le_adv_slot[slot_id].hold_timer_id = 0;
- _bt_unregister_adv_slot_owner(slot_id);
- }
-
- if (le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
- return BLUETOOTH_ERROR_NOT_IN_OPERATION;
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- if (params->interval_min > params->interval_max ||
- params->interval_min < BT_ADV_INTERVAL_MIN ||
- params->interval_max > BT_ADV_INTERVAL_MAX)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- if (params->filter_policy > BLUETOOTH_ALLOW_SCAN_CONN_WHITE_LIST)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- if (params->type == BLUETOOTH_ADV_CONNECTABLE_DIRECT_HIGH ||
- params->type == BLUETOOTH_ADV_CONNECTABLE_DIRECT_LOW ||
- params->type == BLUETOOTH_ADV_NON_CONNECTABLE)
- return BLUETOOTH_ERROR_NOT_SUPPORT;
-
- if (params->tx_power_level > 1 ||
- params->tx_power_level < -127)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- min = params->interval_min / BT_ADV_INTERVAL_SPLIT;
- max = params->interval_max / BT_ADV_INTERVAL_SPLIT;
-
- ret = g_dbus_proxy_call_sync(proxy, "SetAdvertisingParameters",
- g_variant_new("(uuuuii)", min, max,
- params->filter_policy, params->type,
- params->tx_power_level, slot_id),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- if (error) {
- BT_ERR("SetAdvertisingParameters Fail: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- adv_params.interval_min = params->interval_min;
- adv_params.interval_max = params->interval_max;
- adv_params.filter_policy = params->filter_policy;
- adv_params.type = params->type;
- adv_params.tx_power_level = params->tx_power_level;
-
- if (ret)
- g_variant_unref(ret);
-
- ret = g_dbus_proxy_call_sync(proxy, "SetAdvertising",
- g_variant_new("(bi)", enable, slot_id),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error) {
- BT_ERR("SetAdvertising Fail: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (enable == TRUE)
- __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
-
- le_adv_slot[slot_id].is_advertising = enable;
- BT_INFO_C("### Set advertising [%d], Slot id [%d]", enable, slot_id);
- if (ret)
- g_variant_unref(ret);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-static gboolean __bt_hold_current_advertising_timeout_cb(gpointer user_data)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret;
-
- BT_INFO("Restart advertising stopped by bt-service");
-
- le_adv_slot[0].hold_timer_id = 0;
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, FALSE);
-
- ret = g_dbus_proxy_call_sync(proxy, "SetAdvertising",
- g_variant_new("(bi)", TRUE, 0),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error) {
- BT_ERR("SetAdvertising Fail: %s", error->message);
- g_clear_error(&error);
- return FALSE;
- }
-
- if (ret)
- g_variant_unref(ret);
-
- return FALSE;
-}
-
-int _bt_hold_current_advertising(void)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret;
-
- if (le_adv_slot[0].sender && le_adv_slot[0].is_advertising == TRUE) {
- BT_INFO("Stop current advertising by bt-service");
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- ret = g_dbus_proxy_call_sync(proxy, "SetAdvertising",
- g_variant_new("(bi)", FALSE, 0),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error) {
- BT_ERR("SetAdvertising Fail: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (ret)
- g_variant_unref(ret);
-
- le_adv_slot[0].hold_timer_id = g_timeout_add(2000,
- __bt_hold_current_advertising_timeout_cb, NULL);
- } else {
- BT_INFO("It's NOT advertising");
- return BLUETOOTH_ERROR_NOT_IN_OPERATION;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-static int __bt_get_ad_data_by_type(char *in_data, int in_len,
- char in_type, char **data, int *data_len)
-{
- if (in_data == NULL || data == NULL || data_len == NULL)
- return BLUETOOTH_ERROR_INTERNAL;
-
- if (in_len < 0)
- return BLUETOOTH_ERROR_INTERNAL;
-
- int i;
- int len = 0;
- int type = 0;
-
- for (i = 0; i < in_len; i++) {
- len = in_data[i];
- if (len <= 0 || i + 1 >= in_len) {
- BT_ERR("Invalid advertising data");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- type = in_data[i + 1];
- if (type == in_type) {
- i = i + 2;
- len--;
- break;
- }
-
- i += len;
- len = 0;
- }
-
- if (i + len > in_len) {
- BT_ERR("Invalid advertising data");
- return BLUETOOTH_ERROR_INTERNAL;
- } else if (len == 0) {
- BT_DBG("AD Type 0x%02x data is not set", in_type);
- *data = NULL;
- *data_len = 0;
- return BLUETOOTH_ERROR_NONE;
- }
-
- *data = g_memdup(&in_data[i], len);
- if (*data == NULL)
- return BLUETOOTH_ERROR_OUT_OF_MEMORY;
- *data_len = len;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_get_advertising_data(bluetooth_advertising_data_t *adv, int *length)
-{
- BT_CHECK_PARAMETER(adv, return);
- BT_CHECK_PARAMETER(length, return);
-
- memcpy(adv, &adv_data, sizeof(adv_data));
- *length = adv_data_len;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_set_advertising_data(const char *sender, int adv_handle,
- bluetooth_advertising_data_t *adv, int length, gboolean use_reserved_slot)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret, *ad_data, *param = NULL;
- GVariant *temp = NULL;
- GVariantBuilder *builder;
- int i;
- char *old_mdata = NULL;
- char *new_mdata = NULL;
- int old_len = 0;
- int new_len = 0;
- int slot_id;
-
- if (__bt_is_factory_test_mode()) {
- BT_ERR("Unable to set advertising data in factory binary !!");
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- BT_CHECK_PARAMETER(adv, return);
-
- if (_bt_adapter_get_status() != BT_ACTIVATED &&
- _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- slot_id = __bt_get_available_adv_slot_id(sender, adv_handle, use_reserved_slot);
- if (slot_id == -1) {
- BT_ERR("There is NO available slot!!");
- return BLUETOOTH_ERROR_NO_RESOURCES;
- }
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
- for (i = 0; i < length; i++)
- g_variant_builder_add(builder, "y", adv->data[i]);
-
- temp = g_variant_new("ay", builder);
- g_variant_builder_unref(builder);
- ret = g_dbus_proxy_call_sync(proxy, "SetAdvertisingData",
- g_variant_new("(@ayi)", temp, slot_id),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("SetAdvertisingData Fail: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
-
- __bt_get_ad_data_by_type((char *)adv_data.data, adv_data_len, 0xff,
- &old_mdata, &old_len);
- __bt_get_ad_data_by_type((char *)adv->data, length, 0xff,
- &new_mdata, &new_len);
- if (old_len != new_len ||
- (old_mdata && new_mdata &&
- memcmp(old_mdata, new_mdata, new_len))) {
- ad_data = g_variant_new_from_data((const GVariantType *)"ay",
- new_mdata, new_len, TRUE, NULL, NULL);
- param = g_variant_new("(@ay)", ad_data);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_ADVERTISING_MANUFACTURER_DATA_CHANGED,
- param);
- }
- g_free(new_mdata);
- g_free(old_mdata);
-
- memset(&adv_data, 0x00, sizeof(bluetooth_advertising_data_t));
- memcpy(&adv_data, adv, length);
- adv_data_len = length;
-
- BT_INFO("Set advertising data");
- if (ret)
- g_variant_unref(ret);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_get_scan_response_data(bluetooth_scan_resp_data_t *response, int *length)
-{
- BT_CHECK_PARAMETER(response, return);
- BT_CHECK_PARAMETER(length, return);
-
- memcpy(response, &resp_data, sizeof(resp_data));
- *length = resp_data_len;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_set_scan_response_data(const char *sender, int adv_handle,
- bluetooth_scan_resp_data_t *response, int length, gboolean use_reserved_slot)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret, *scan_data, *param = NULL;
- GVariant *temp = NULL;
- GVariantBuilder *builder;
- int i;
- char *old_mdata = NULL;
- char *new_mdata = NULL;
- int old_len = 0;
- int new_len = 0;
- int slot_id;
-
- if (__bt_is_factory_test_mode()) {
- BT_ERR("Unable to set scan response list in factory binary !!");
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- BT_CHECK_PARAMETER(response, return);
-
- if (_bt_adapter_get_status() != BT_ACTIVATED &&
- _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- slot_id = __bt_get_available_adv_slot_id(sender, adv_handle, use_reserved_slot);
- if (slot_id == -1) {
- BT_ERR("There is NO available slot!!");
- return BLUETOOTH_ERROR_NO_RESOURCES;
- }
- builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
- for (i = 0; i < length; i++)
- g_variant_builder_add(builder, "y", response->data[i]);
-
- temp = g_variant_new("ay", builder);
- g_variant_builder_unref(builder);
- ret = g_dbus_proxy_call_sync(proxy, "SetScanRespData",
- g_variant_new("(@ayi)", temp, slot_id),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("SetScanRespData Fail: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
-
- /* Compare with previous scan resp data */
- __bt_get_ad_data_by_type((char *)resp_data.data, resp_data_len, 0xff,
- &old_mdata, &old_len);
- __bt_get_ad_data_by_type((char *)response->data, length, 0xff,
- &new_mdata, &new_len);
- if (old_len != new_len ||
- (old_mdata && new_mdata &&
- memcmp(old_mdata, new_mdata, new_len))) {
- scan_data = g_variant_new_from_data((const GVariantType *)"ay",
- new_mdata, new_len, TRUE, NULL, NULL);
- param = g_variant_new("(@ay)", scan_data);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_SCAN_RESPONSE_MANUFACTURER_DATA_CHANGED,
- param);
- }
- g_free(new_mdata);
- g_free(old_mdata);
-
- memset(&resp_data, 0x00, sizeof(bluetooth_scan_resp_data_t));
- memcpy(&resp_data, response, length);
- resp_data_len = length;
-
- if (ret)
- g_variant_unref(ret);
- BT_INFO("Set scan response data");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_set_scan_parameters(bluetooth_le_scan_params_t *params)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret;
- guint32 itv = 0;
- guint32 win = 0;
-
- BT_CHECK_PARAMETER(params, return);
-
- if (_bt_adapter_get_status() != BT_ACTIVATED &&
- _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- BT_DBG("inteval %f, win %f, type %d", params->interval, params->window, params->type);
-
- if (params->interval < BT_LE_SCAN_INTERVAL_MIN || params->interval > BT_LE_SCAN_INTERVAL_MAX)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- if (params->window < BT_LE_SCAN_WINDOW_MIN || params->window > BT_LE_SCAN_WINDOW_MAX)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- if (params->window > params->interval)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- itv = params->interval / BT_SCAN_INTERVAL_SPLIT;
- win = params->window / BT_SCAN_INTERVAL_SPLIT;
-
- ret = g_dbus_proxy_call_sync(proxy, "SetScanParameters",
- g_variant_new("(uuu)", params->type, itv, win),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
-
- if (error) {
- BT_ERR("SetScanParameters Fail: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- _bt_set_le_scan_type(params->type);
-
- is_le_set_scan_parameter = TRUE;
-
- if (ret)
- g_variant_unref(ret);
- BT_INFO("Set scan parameters inteval %f, win %f, type %d",
- itv * BT_SCAN_INTERVAL_SPLIT, win * BT_SCAN_INTERVAL_SPLIT, params->type);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_prepare_scan_parameters(bluetooth_le_scan_params_t *params, int scan_type)
-{
- if (_bt_adapter_get_status() != BT_ACTIVATED &&
- _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- if (params)
- BT_DBG("inteval %f, win %f", params->interval, params->window);
- else
- BT_DBG("type %d", scan_type);
-
- if (params) {
- if (params->interval < BT_LE_SCAN_INTERVAL_MIN || params->interval > BT_LE_SCAN_INTERVAL_MAX)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- if (params->window < BT_LE_SCAN_WINDOW_MIN || params->window > BT_LE_SCAN_WINDOW_MAX)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- if (params->window > params->interval)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- le_scan_params.interval = params->interval;
- le_scan_params.window = params->window;
- } else {
- le_scan_params.type = scan_type;
- if (le_scan_params.interval == 0) {
- /* Set default scan interval same with BT_ADAPTER_LE_SCAN_MODE_LOW_ENERGY */
- le_scan_params.interval = 5120;
- le_scan_params.window = 512;
- }
- }
-
- is_le_set_scan_parameter = TRUE;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-bt_adapter_le_scanner_t* __bt_find_scanner_from_list(const char *sender)
-{
- GSList *l;
- bt_adapter_le_scanner_t *scanner;
-
- for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
- scanner = l->data;
- if (g_strcmp0(scanner->sender, sender) == 0)
- return scanner;
- }
-
- return NULL;
-}
-
-static int __bt_get_available_scan_filter_slot_id(void)
-{
- GSList *l;
- bt_adapter_le_scanner_t *scanner;
- GSList *fl;
- bluetooth_le_scan_filter_t *filter_data;
- gboolean *slot_check_list = NULL;
- int i;
-
- if (le_feature_info.max_filter == 0) {
- BT_ERR("Scan filter is NOT Supported");
- return -1;
- }
- slot_check_list = g_malloc0(sizeof(gboolean) * le_feature_info.max_filter);
-
- for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
- scanner = l->data;
- for (fl = scanner->filter_list; fl != NULL; fl = g_slist_next(fl)) {
- filter_data = fl->data;
- if (filter_data->slot_id < le_feature_info.max_filter)
- slot_check_list[filter_data->slot_id] = TRUE;
- }
- }
-
- for (i = 0; i < le_feature_info.max_filter; i++) {
- if (slot_check_list[i] == FALSE) {
- g_free(slot_check_list);
- return i;
- }
- }
-
- BT_ERR("There is NO available slot for scan filter.");
- g_free(slot_check_list);
- return -1;
-}
-
-gboolean _bt_is_scan_filter_supported(void)
-{
- if (le_feature_info.max_filter > 0)
- return TRUE;
-
- return FALSE;
-}
-
-int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *filter)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret, *param;
- GVariant *arr_uuid_param = NULL, *arr_uuid_mask_param = NULL;
- GVariant *arr_data_param = NULL, *arr_data_mask_param = NULL;
- GArray *arr_uuid = NULL;
- GArray *arr_uuid_mask = NULL;
- GArray *arr_data = NULL;
- GArray *arr_data_mask = NULL;
- bt_adapter_le_scanner_t *scanner = NULL;
- bluetooth_le_scan_filter_t *filter_data = NULL;
- int feature_selection = 0;
- int slot_id;
-
- slot_id = __bt_get_available_scan_filter_slot_id();
- if (slot_id == -1)
- return BLUETOOTH_ERROR_NO_RESOURCES;
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS) {
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS;
-
- _bt_convert_addr_type_to_string(address, filter->device_address.addr);
-
- arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
- arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
- arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
- arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
-
- param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
- 0, // client_if
- 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
- BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS, // filter_type
- slot_id, // filter_index
- 0, // company_id
- 0, // company_id_mask
- arr_uuid_param, // p_uuid
- arr_uuid_mask_param, // p_uuid_mask
- address, // string
- 0, // address_type
- arr_data_param, // p_data
- arr_data_mask_param); // p_mask
-
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove",
- param, G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_add_remove Fail: %s", error->message);
- g_clear_error(&error);
- }
- if (ret)
- g_variant_unref(ret);
- }
-
- if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME) {
- feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME;
-
- arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
- arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
- arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
- arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
-
- param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
- 0, // client_if
- 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
- BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME, // filter_type
- slot_id, // filter_index
- 0, // company_id
- 0, // company_id_mask
- arr_uuid_param, // p_uuid
- arr_uuid_mask_param, // p_uuid_mask
- filter->device_name, // string
- 0, // address_type
- arr_data_param, // p_data
- arr_data_mask_param);
-
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove",
- param, G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_add_remove Fail: %s", error->message);
- g_clear_error(&error);
- }
- if (ret)
- g_variant_unref(ret);
- }
-
- if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID) {
- feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID;
-
- arr_uuid = g_array_new(TRUE, TRUE, sizeof(guint8));
- arr_uuid_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
-
- g_array_append_vals(arr_uuid, filter->service_uuid.data.data, filter->service_uuid.data_len * sizeof(guint8));
- g_array_append_vals(arr_uuid_mask, filter->service_uuid_mask.data.data, filter->service_uuid_mask.data_len * sizeof(guint8));
-
- arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid->data, arr_uuid->len, TRUE, NULL, NULL);
- arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid_mask->data, arr_uuid_mask->len, TRUE, NULL, NULL);
- arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
- arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
-
- param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
- 0, // client_if
- 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
- BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID, // filter_type
- slot_id, // filter_index
- 0, // company_id
- 0, // company_id_mask
- arr_uuid_param, // p_uuid
- arr_uuid_mask_param, // p_uuid_mask
- "", // string
- 0, // address_type
- arr_data_param, // p_data
- arr_data_mask_param);
-
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove",
- param, G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_add_remove Fail: %s", error->message);
- g_clear_error(&error);
- }
- if (ret)
- g_variant_unref(ret);
-
- g_array_free(arr_uuid, TRUE);
- g_array_free(arr_uuid_mask, TRUE);
- }
-
- if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID) {
- feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID;
-
- arr_uuid = g_array_new(TRUE, TRUE, sizeof(guint8));
- arr_uuid_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
-
- g_array_append_vals(arr_uuid, filter->service_solicitation_uuid.data.data, filter->service_solicitation_uuid.data_len * sizeof(guint8));
- g_array_append_vals(arr_uuid_mask, filter->service_solicitation_uuid_mask.data.data, filter->service_solicitation_uuid_mask.data_len * sizeof(guint8));
-
- arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid->data, arr_uuid->len, TRUE, NULL, NULL);
- arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid_mask->data, arr_uuid_mask->len, TRUE, NULL, NULL);
- arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
- arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
-
- param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
- 0, // client_if
- 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
- BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID, // filter_type
- slot_id, // filter_index
- 0, // company_id
- 0, // company_id_mask
- arr_uuid_param, // p_uuid
- arr_uuid_mask_param, // p_uuid_mask
- "", // string
- 0, // address_type
- arr_data_param, // p_data
- arr_data_mask_param);
-
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove", param,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_add_remove Fail: %s", error->message);
- g_clear_error(&error);
- }
- if (ret)
- g_variant_unref(ret);
-
- g_array_free(arr_uuid, TRUE);
- g_array_free(arr_uuid_mask, TRUE);
- }
-
- if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA) {
- feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA;
-
- arr_data = g_array_new(TRUE, TRUE, sizeof(guint8));
- arr_data_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
-
- g_array_append_vals(arr_data, filter->service_data.data.data, filter->service_data.data_len * sizeof(guint8));
- g_array_append_vals(arr_data_mask, filter->service_data_mask.data.data, filter->service_data_mask.data_len * sizeof(guint8));
-
- arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
- arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
- arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_data->data, arr_data->len, TRUE, NULL, NULL);
- arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_data_mask->data, arr_data_mask->len, TRUE, NULL, NULL);
-
- param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
- 0, // client_if
- 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
- BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA, // filter_type
- slot_id, // filter_index
- 0, // company_id
- 0, // company_id_mask
- arr_uuid_param, // p_uuid
- arr_uuid_mask_param, // p_uuid_mask
- "", // string
- 0, // address_type
- arr_data_param, // p_data
- arr_data_mask_param);
-
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove", param,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_add_remove Fail: %s", error->message);
- g_clear_error(&error);
- }
- if (ret)
- g_variant_unref(ret);
-
- g_array_free(arr_data, TRUE);
- g_array_free(arr_data_mask, TRUE);
- }
-
- if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA) {
- feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA;
-
- arr_data = g_array_new(TRUE, TRUE, sizeof(guint8));
- arr_data_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
-
- g_array_append_vals(arr_data, filter->manufacturer_data.data.data, filter->manufacturer_data.data_len * sizeof(guint8));
- g_array_append_vals(arr_data_mask, filter->manufacturer_data_mask.data.data, filter->manufacturer_data_mask.data_len * sizeof(guint8));
-
- arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
- arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- NULL, 0, TRUE, NULL, NULL);
- arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_data->data, arr_data->len, TRUE, NULL, NULL);
- arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_data_mask->data, arr_data_mask->len, TRUE, NULL, NULL);
-
- param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
- 0, // client_if
- 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
- BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA, // filter_type
- slot_id, // filter_index
- filter->manufacturer_id, // company_id
- 0xFFFF, // company_id_mask
- arr_uuid_param, // p_uuid
- arr_uuid_mask_param, // p_uuid_mask
- "", // string
- 0, // address_type
- arr_data_param, // p_data
- arr_data_mask_param);
-
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_add_remove", param,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_add_remove Fail: %s", error->message);
- g_clear_error(&error);
- }
- if (ret)
- g_variant_unref(ret);
-
- g_array_free(arr_data, TRUE);
- g_array_free(arr_data_mask, TRUE);
- }
-
- BT_DBG("Filter selection %.2x", feature_selection);
-
- param = g_variant_new("(iiiiiiiiiiii)",
- 0, // client_if
- 0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
- slot_id, // filter_index
- feature_selection, // feat_seln
- 0, // list_logic_type (OR - 0x00, AND - 0x01)
- 1, // filt_logic_type (OR - 0x00, AND - 0x01)
- -127, // rssi_high_thres
- -127, // rssi_low_thres
- 0, // dely_mode (Immediate - 0x00, on found - 0x01, batched - 0x02)
- 0, // found_timeout
- 0, // lost_timeout
- 0); // found_timeout_cnt
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_param_setup",
- param, G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_add_remove Fail: %s", error->message);
- g_clear_error(&error);
- }
-
- scanner = __bt_find_scanner_from_list(sender);
- if (scanner == NULL) {
- scanner = g_malloc0(sizeof(bt_adapter_le_scanner_t));
- scanner->sender = g_strdup(sender);
- scanner_list = g_slist_append(scanner_list, scanner);
- }
-
-
- if (scanner) {
- filter_data = g_malloc0(sizeof(bluetooth_le_scan_filter_t));
- memcpy(filter_data, filter, sizeof(bluetooth_le_scan_filter_t));
- filter_data->slot_id = slot_id;
-
- scanner->filter_list = g_slist_append(scanner->filter_list, filter_data);
- }
-
- if (ret)
- g_variant_unref(ret);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_unregister_all_scan_filters(const char *sender)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret;
- bt_adapter_le_scanner_t *scanner = NULL;
- bluetooth_le_scan_filter_t *filter_data = NULL;
- GSList *l;
-
- scanner = __bt_find_scanner_from_list(sender);
- if (scanner == NULL) {
- BT_ERR("There is NO available scanner.");
- return BLUETOOTH_ERROR_NOT_FOUND;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- for (l = scanner->filter_list; l != NULL; l = g_slist_next(l)) {
- filter_data = l->data;
-
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_clear",
- g_variant_new("(ii)", 0, filter_data->slot_id),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_clear Fail: %s", error->message);
- g_clear_error(&error);
- }
- if (ret)
- g_variant_unref(ret);
- }
-
- g_slist_free_full(scanner->filter_list, g_free);
- scanner->filter_list = NULL;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_start_le_scan(const char *sender)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret;
- bt_adapter_le_scanner_t *scanner = __bt_find_scanner_from_list(sender);
-
- if (scanner == NULL) {
- scanner = g_malloc0(sizeof(bt_adapter_le_scanner_t));
- scanner->sender = g_strdup(sender);
- scanner_list = g_slist_append(scanner_list, scanner);
- }
-
- if (scanner->is_scanning == TRUE) {
- BT_ERR("BT is already in LE scanning");
- return BLUETOOTH_ERROR_IN_PROGRESS;
- }
- scanner->is_scanning = TRUE;
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- if (_bt_is_le_scanning()) {
- if (scan_filter_enabled == TRUE) {
- if (scanner->filter_list == NULL) {
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_enable",
- g_variant_new("(ib)", 0, FALSE),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_enable Fail: %s", error->message);
- g_clear_error(&error);
- }
-
- if (ret)
- g_variant_unref(ret);
- BT_INFO("Disable LE Scan Filter");
- scan_filter_enabled = FALSE;
- } else {
- BT_INFO("LE Filter Scan is continue");
- }
- } else {
- BT_INFO("LE Full Scan is already on progress");
- }
- return BLUETOOTH_ERROR_NONE;
- } else {
- if (is_le_set_scan_parameter == FALSE) {
- /* Set default scan parameter same with BT_ADAPTER_LE_SCAN_MODE_LOW_ENERGY */
- bluetooth_le_scan_params_t scan_params;
- scan_params.type = BT_LE_ACTIVE_SCAN;
- scan_params.interval = 5120;
- scan_params.window = 512;
- _bt_set_scan_parameters(&scan_params);
- } else
- _bt_set_scan_parameters(&le_scan_params);
-
- if (scanner->filter_list == NULL) {
- BT_INFO("Start LE Full Scan");
- scan_filter_enabled = FALSE;
- } else {
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_enable",
- g_variant_new("(ib)", 0, TRUE),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_enable Fail: %s", error->message);
- g_clear_error(&error);
- }
-
- if (ret)
- g_variant_unref(ret);
- BT_INFO("Enable LE Scan Filter");
- scan_filter_enabled = TRUE;
- }
- }
-
- ret = g_dbus_proxy_call_sync(proxy, "StartLEDiscovery",
- NULL, G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("StartLEDiscovery Fail: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (ret)
- g_variant_unref(ret);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_stop_le_scan(const char *sender)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret;
- bt_adapter_le_scanner_t *scanner = __bt_find_scanner_from_list(sender);
- GSList *l;
- gboolean next_scanning = FALSE;
- gboolean need_scan_filter = TRUE;
-
- if (scanner == NULL || scanner->is_scanning == FALSE)
- return BLUETOOTH_ERROR_NOT_IN_OPERATION;
-
- _bt_unregister_all_scan_filters(sender);
-
- scanner_list = g_slist_remove(scanner_list, scanner);
- __bt_free_le_scanner(scanner);
-
- for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
- scanner = l->data;
- if (scanner->is_scanning == TRUE) {
- next_scanning = TRUE;
- if (scanner->filter_list == NULL)
- need_scan_filter = FALSE;
- }
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- if (next_scanning == TRUE) {
- if (scan_filter_enabled == FALSE && need_scan_filter == TRUE) {
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_enable",
- g_variant_new("(ib)", 0, TRUE),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_enable Fail: %s", error->message);
- g_clear_error(&error);
- }
-
- if (ret)
- g_variant_unref(ret);
- BT_INFO("Enable LE Scan Filter");
- scan_filter_enabled = TRUE;
- }
- BT_INFO("next_scanning exists. Keep the LE scanning");
- return BLUETOOTH_ERROR_NONE;
- } else {
- if (scan_filter_enabled == TRUE) {
- ret = g_dbus_proxy_call_sync(proxy, "scan_filter_enable",
- g_variant_new("(ib)", 0, FALSE),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("scan_filter_enable Fail: %s", error->message);
- g_clear_error(&error);
- }
-
- if (ret)
- g_variant_unref(ret);
- BT_INFO("Disable LE Scan Filter");
- } else {
- BT_INFO("Just stop LE scan");
- }
- }
-
- ret = g_dbus_proxy_call_sync(proxy, "StopLEDiscovery",
- NULL, G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
- if (error) {
- BT_ERR("StopLEDiscovery Fail: %s", error->message);
- g_clear_error(&error);
- }
-
- if (ret == NULL) {
- BT_ERR("LE Scan stop failed");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- scan_filter_enabled = FALSE;
- is_le_set_scan_parameter = FALSE;
- le_scan_params.type = BT_LE_ACTIVE_SCAN;
- le_scan_params.interval = 0;
- le_scan_params.window = 0;
- if (ret)
- g_variant_unref(ret);
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_disable_all_scanner_status(void)
-{
- GSList *l;
- bt_adapter_le_scanner_t *scanner;
-
- for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
- scanner = l->data;
- scanner->is_scanning = FALSE;
- }
-}
-
-void _bt_set_le_scan_status(gboolean mode)
-{
- BT_DBG("set is_le_scanning : %d -> %d", is_le_scanning, mode);
- is_le_scanning = mode;
-}
-
-gboolean _bt_is_le_scanning(void)
-{
- return is_le_scanning;
-}
-
-void _bt_set_le_scan_type(bt_le_scan_type_t type)
-{
- le_scan_type = type;
-}
-
-bt_le_scan_type_t _bt_get_le_scan_type(void)
-{
- return le_scan_type;
-}
-
-static gboolean __bt_check_scan_result_uuid(const char *adv_data,
- int adv_data_len, const char *svc_uuid, int uuid_len,
- const char *uuid_mask, char ad_type)
-{
- char *data = NULL;
- int data_len = 0;
- int i;
-
- __bt_get_ad_data_by_type((char*)adv_data, adv_data_len,
- ad_type, &data, &data_len);
- if (data != NULL) {
- for (i = 0; i < data_len; i += uuid_len) {
- if (uuid_len > (data_len - i))
- break;
-
- if (_bt_byte_arr_cmp_with_mask(data + i,
- svc_uuid, uuid_mask, uuid_len) == 0) {
- g_free(data);
- return TRUE;
- }
- }
- g_free(data);
- }
-
- return FALSE;
-}
-
-static gboolean __bt_check_scan_result_with_filter(const char *device_address,
- const char *adv_data, int adv_data_len,
- const char *scan_data, int scan_data_len,
- const bt_adapter_le_scanner_t *scanner)
-{
- GSList *l;
- bluetooth_le_scan_filter_t *filter_data = NULL;
- char *data = NULL;
- int data_len = 0;
- gboolean is_matched = FALSE;
-
- if (scanner->filter_list == NULL) {
- BT_INFO("This scanner is on Full Scan.");
- return TRUE;
- }
-
- for (l = scanner->filter_list; l != NULL; l = g_slist_next(l)) {
- filter_data = l->data;
-
- if (filter_data->added_features &
- BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS) {
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
-
- _bt_convert_addr_type_to_string(address,
- filter_data->device_address.addr);
- if (strncmp(address, device_address,
- BT_ADDRESS_STRING_SIZE) != 0)
- continue;
- }
-
- if (filter_data->added_features &
- BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID) {
- is_matched = FALSE;
-
- if (__bt_check_scan_result_uuid(adv_data,
- adv_data_len,
- (char*)filter_data->service_uuid.data.data,
- filter_data->service_uuid.data_len,
- (char*)filter_data->service_uuid_mask.data.data,
- BT_LE_AD_TYPE_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS)
- == TRUE)
- is_matched = TRUE;
- if (__bt_check_scan_result_uuid(adv_data,
- adv_data_len,
- (char*)filter_data->service_uuid.data.data,
- filter_data->service_uuid.data_len,
- (char*)filter_data->service_uuid_mask.data.data,
- BT_LE_AD_TYPE_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS)
- == TRUE)
- is_matched = TRUE;
- if (__bt_check_scan_result_uuid(adv_data,
- adv_data_len,
- (char*)filter_data->service_uuid.data.data,
- filter_data->service_uuid.data_len,
- (char*)filter_data->service_uuid_mask.data.data,
- BT_LE_AD_TYPE_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS)
- == TRUE)
- is_matched = TRUE;
- if (__bt_check_scan_result_uuid(adv_data,
- adv_data_len,
- (char*)filter_data->service_uuid.data.data,
- filter_data->service_uuid.data_len,
- (char*)filter_data->service_uuid_mask.data.data,
- BT_LE_AD_TYPE_COMP_LIST_128_BIT_SERVICE_CLASS_UUIDS)
- == TRUE)
- is_matched = TRUE;
- if (__bt_check_scan_result_uuid(scan_data,
- scan_data_len,
- (char*)filter_data->service_uuid.data.data,
- filter_data->service_uuid.data_len,
- (char*)filter_data->service_uuid_mask.data.data,
- BT_LE_AD_TYPE_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS)
- == TRUE)
- is_matched = TRUE;
- if (__bt_check_scan_result_uuid(scan_data,
- scan_data_len,
- (char*)filter_data->service_uuid.data.data,
- filter_data->service_uuid.data_len,
- (char*)filter_data->service_uuid_mask.data.data,
- BT_LE_AD_TYPE_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS)
- == TRUE)
- is_matched = TRUE;
- if (__bt_check_scan_result_uuid(scan_data,
- scan_data_len,
- (char*)filter_data->service_uuid.data.data,
- filter_data->service_uuid.data_len,
- (char*)filter_data->service_uuid_mask.data.data,
- BT_LE_AD_TYPE_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS)
- == TRUE)
- is_matched = TRUE;
- if (__bt_check_scan_result_uuid(scan_data,
- scan_data_len,
- (char*)filter_data->service_uuid.data.data,
- filter_data->service_uuid.data_len,
- (char*)filter_data->service_uuid_mask.data.data,
- BT_LE_AD_TYPE_COMP_LIST_128_BIT_SERVICE_CLASS_UUIDS)
- == TRUE)
- is_matched = TRUE;
-
- if (is_matched == FALSE)
- continue;
- }
- if (filter_data->added_features &
- BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID) {
- is_matched = FALSE;
-
- if (__bt_check_scan_result_uuid(adv_data,
- adv_data_len,
- (char*)filter_data->service_solicitation_uuid.data.data,
- filter_data->service_solicitation_uuid.data_len,
- (char*)filter_data->service_solicitation_uuid_mask.data.data,
- BT_LE_AD_TYPE_LIST_16_BIT_SERVICE_SOLICITATION_UUIDS)
- == TRUE)
- is_matched = TRUE;
- if (__bt_check_scan_result_uuid(adv_data,
- adv_data_len,
- (char*)filter_data->service_solicitation_uuid.data.data,
- filter_data->service_solicitation_uuid.data_len,
- (char*)filter_data->service_solicitation_uuid_mask.data.data,
- BT_LE_AD_TYPE_LIST_128_BIT_SERVICE_SOLICITATION_UUIDS)
- == TRUE)
- is_matched = TRUE;
- if (__bt_check_scan_result_uuid(scan_data,
- scan_data_len,
- (char*)filter_data->service_solicitation_uuid.data.data,
- filter_data->service_solicitation_uuid.data_len,
- (char*)filter_data->service_solicitation_uuid_mask.data.data,
- BT_LE_AD_TYPE_LIST_16_BIT_SERVICE_SOLICITATION_UUIDS)
- == TRUE)
- is_matched = TRUE;
- if (__bt_check_scan_result_uuid(scan_data,
- scan_data_len,
- (char*)filter_data->service_solicitation_uuid.data.data,
- filter_data->service_solicitation_uuid.data_len,
- (char*)filter_data->service_solicitation_uuid_mask.data.data,
- BT_LE_AD_TYPE_LIST_128_BIT_SERVICE_SOLICITATION_UUIDS)
- == TRUE)
- is_matched = TRUE;
-
- if (is_matched == FALSE)
- continue;
- }
- if (filter_data->added_features &
- BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME) {
- char name[BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX] = {0, };
- data = NULL;
- data_len = 0;
- is_matched = FALSE;
-
- __bt_get_ad_data_by_type((char*)adv_data, adv_data_len,
- BT_LE_AD_TYPE_COMPLETE_LOCAL_NAME,
- &data, &data_len);
- if (data != NULL) {
- if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
- data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
- memcpy(name, data, data_len);
- name[data_len] = '\0';
- g_free(data);
- data = NULL;
- if (strncmp(filter_data->device_name,
- name, data_len) == 0)
- is_matched = TRUE;
- }
- __bt_get_ad_data_by_type((char*)scan_data,
- scan_data_len,
- BT_LE_AD_TYPE_COMPLETE_LOCAL_NAME,
- &data, &data_len);
- if (data != NULL) {
- if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
- data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
- memcpy(name, data, data_len);
- name[data_len] = '\0';
- g_free(data);
- data = NULL;
- if (strncmp(filter_data->device_name,
- name, data_len) == 0)
- is_matched = TRUE;
- }
-
- if (is_matched == FALSE)
- continue;
- }
- if (filter_data->added_features &
- BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA) {
- data = NULL;
- data_len = 0;
- is_matched = FALSE;
-
- __bt_get_ad_data_by_type((char*)adv_data,
- adv_data_len,
- BT_LE_AD_TYPE_MANUFACTURER_SPECIFIC_DATA,
- &data, &data_len);
-
- if (data != NULL) {
- int manufacturer_id;
- manufacturer_id = (data[1] << 8) + data[0];
-
- if (filter_data->manufacturer_id == manufacturer_id) {
- if (filter_data->manufacturer_data.data_len == 0) {
- is_matched = TRUE;
- } else {
- if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
- data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
- if (_bt_byte_arr_cmp_with_mask(data + 2,
- (char*)filter_data->manufacturer_data.data.data,
- (char*)filter_data->manufacturer_data_mask.data.data,
- data_len - 2) == 0) {
- is_matched = TRUE;
- }
- }
- }
- g_free(data);
- data = NULL;
- }
- __bt_get_ad_data_by_type((char*)scan_data,
- scan_data_len,
- BT_LE_AD_TYPE_MANUFACTURER_SPECIFIC_DATA,
- &data, &data_len);
-
- if (data != NULL) {
- int manufacturer_id;
- manufacturer_id = (data[1] << 8) + data[0];
-
- if (filter_data->manufacturer_id == manufacturer_id) {
- if (filter_data->manufacturer_data.data_len == 0) {
- is_matched = TRUE;
- } else {
- if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
- data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
- if (_bt_byte_arr_cmp_with_mask(data + 2,
- (char*)filter_data->manufacturer_data.data.data,
- (char*)filter_data->manufacturer_data_mask.data.data,
- data_len - 2) == 0) {
- is_matched = TRUE;
- }
- }
- }
- g_free(data);
- data = NULL;
- }
-
- if (is_matched == FALSE)
- continue;
- }
- if (filter_data->added_features &
- BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA) {
- data = NULL;
- data_len = 0;
- is_matched = FALSE;
-
- __bt_get_ad_data_by_type((char*)adv_data,
- adv_data_len,
- BT_LE_AD_TYPE_SERVICE_DATA,
- &data, &data_len);
- if (data != NULL) {
- if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
- data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
- if (_bt_byte_arr_cmp_with_mask(data,
- (char*)filter_data->service_data.data.data,
- (char*)filter_data->service_data_mask.data.data,
- data_len) == 0) {
- is_matched = TRUE;
- }
- g_free(data);
- data = NULL;
- }
- __bt_get_ad_data_by_type((char*)scan_data,
- scan_data_len,
- BT_LE_AD_TYPE_SERVICE_DATA,
- &data, &data_len);
- if (data != NULL) {
- if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
- data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
- if (_bt_byte_arr_cmp_with_mask(data,
- (char*)filter_data->service_data.data.data,
- (char*)filter_data->service_data_mask.data.data,
- data_len) == 0) {
- is_matched = TRUE;
- }
- g_free(data);
- data = NULL;
- }
-
- if (is_matched == FALSE)
- continue;
- }
-
- BT_INFO("The scan result is conformable.");
- return TRUE;
- }
-
- BT_INFO("The scan result is NOT conformable.");
- return FALSE;
-}
-
-void _bt_send_scan_result_event(const bt_remote_le_dev_info_t *le_dev_info,
- const bt_le_adv_info_t *adv_info)
-{
- int result = BLUETOOTH_ERROR_NONE;
- GSList *l;
- GVariant *scan_data_param, *adv_data_param;
- GVariant *param;
- bt_adapter_le_scanner_t *scanner = NULL;
- const char *adv_data = NULL;
- int adv_data_len = 0;
- const char *scan_data = NULL;
- int scan_data_len = 0;
-
- ret_if(le_dev_info == NULL);
-
- if (adv_info == NULL) { /* Not received scan response data within 1 sec */
- adv_data = le_dev_info->adv_data;
- adv_data_len = le_dev_info->adv_data_len;
- scan_data = le_dev_info->adv_data;
- scan_data_len = 0;
- } else {
- adv_data = adv_info->data;
- adv_data_len = adv_info->data_len;
- scan_data = le_dev_info->adv_data;
- scan_data_len = le_dev_info->adv_data_len;
- }
-
- for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
- scanner = l->data;
- if (scanner->is_scanning == FALSE)
- continue;
-
- if (__bt_check_scan_result_with_filter(le_dev_info->address,
- adv_data, adv_data_len, scan_data, scan_data_len,
- scanner) == FALSE)
- continue;
-
- adv_data_param = g_variant_new_from_data((const GVariantType *)"ay",
- adv_data, adv_data_len, TRUE, NULL, NULL);
- scan_data_param = g_variant_new_from_data((const GVariantType *)"ay",
- scan_data, scan_data_len, TRUE, NULL, NULL);
-
- param = g_variant_new("(isnnn@ayn@ay)",
- result,
- le_dev_info->address,
- le_dev_info->addr_type,
- le_dev_info->rssi,
- adv_data_len,
- adv_data_param,
- scan_data_len,
- scan_data_param);
-
-#if 0
- _bt_send_event_to_dest(scanner->sender, BT_LE_ADAPTER_EVENT,
- BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND, param);
-#else
- _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND, param);
-#endif
- }
-}
-
-void _bt_send_ibeacon_scan_result_event(const bt_remote_ibeacon_dev_info_t *ibeacon_dev_info)
-{
- int result = BLUETOOTH_ERROR_NONE;
- GSList *l;
- GVariant *param;
- bt_adapter_le_scanner_t *scanner = NULL;
-
- ret_if(ibeacon_dev_info == NULL);
- BT_DBG("_bt_send_ibeacon_scan_result_event");
-
- for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
- scanner = l->data;
- if (scanner->is_scanning == FALSE)
- continue;
-
- param = g_variant_new("(isnnnsnnn)",
- result,
- ibeacon_dev_info->address,
- ibeacon_dev_info->addr_type,
- ibeacon_dev_info->company_id,
- ibeacon_dev_info->ibeacon_type,
- ibeacon_dev_info->uuid,
- ibeacon_dev_info->major_id,
- ibeacon_dev_info->minor_id,
- ibeacon_dev_info->measured_power);
-
- _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_REMOTE_IBEACON_DEVICE_FOUND, param);
- }
-}
-
-int _bt_add_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type)
-{
- GDBusProxy *proxy;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- GError *error = NULL;
- GVariant *ret;
-
- if (__bt_is_factory_test_mode()) {
- BT_ERR("Unable to add white list in factory binary !!");
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- BT_CHECK_PARAMETER(device_address, return);
-
- if (address_type != BLUETOOTH_DEVICE_PUBLIC_ADDRESS &&
- address_type != BLUETOOTH_DEVICE_RANDOM_ADDRESS)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- ret = g_dbus_proxy_call_sync(proxy, "AddDeviceWhiteList",
- g_variant_new("(su)", address, address_type),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
-
- if (error) {
- BT_ERR("AddDeviceWhiteList Fail: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (ret)
- g_variant_unref(ret);
- BT_INFO("Add white list");
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_remove_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type)
-{
- GDBusProxy *proxy;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- GError *error = NULL;
- GVariant *ret;
-
- if (__bt_is_factory_test_mode()) {
- BT_ERR("Unable to remove white list in factory binary !!");
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- BT_CHECK_PARAMETER(device_address, return);
-
- if (address_type != BLUETOOTH_DEVICE_PUBLIC_ADDRESS &&
- address_type != BLUETOOTH_DEVICE_RANDOM_ADDRESS)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- ret = g_dbus_proxy_call_sync(proxy, "RemoveDeviceWhiteList",
- g_variant_new("(su)", address, address_type),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
-
- if (error) {
- BT_ERR("RemoveDeviceWhiteList Fail: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (ret)
- g_variant_unref(ret);
- BT_INFO("Remove white list");
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_clear_white_list(void)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret;
-
- if (__bt_is_factory_test_mode()) {
- BT_ERR("Unable to clear white list in factory binary !!");
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- ret = g_dbus_proxy_call_sync(proxy, "ClearDeviceWhiteList",
- NULL, G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
-
- if (error) {
- BT_ERR("ClearDeviceWhiteList Fail: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- if (ret)
- g_variant_unref(ret);
-
- BT_INFO("Clear white list");
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_initialize_ipsp(void)
-{
- BT_DBG("+");
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret;
-
- if (_bt_adapter_get_status() != BT_ACTIVATED &&
- _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- ret = g_dbus_proxy_call_sync(proxy, "InitializeIpsp",
- NULL, G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
- if (error) {
- BT_ERR("Initialize IPSP Failed :[%s]", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- if (ret)
- g_variant_unref(ret);
-
- BT_INFO("IPSP initialization called successfully");
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_deinitialize_ipsp(void)
-{
- BT_DBG("+");
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *ret;
-
- if (_bt_adapter_get_status() != BT_ACTIVATED &&
- _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- ret = g_dbus_proxy_call_sync(proxy, "DeinitializeIpsp",
- NULL, G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &error);
- if (error) {
- BT_ERR("De-Initialize IPSP Failed :[%s]", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- if (ret)
- g_variant_unref(ret);
-
- BT_INFO("IPSP De-initialization called successfully");
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_le_read_maximum_data_length(
- bluetooth_le_read_maximum_data_length_t *max_le_datalength)
-{
- GError *error = NULL;
- GDBusProxy *proxy;
- GVariant *reply = NULL;
- guint16 max_tx_octets, max_tx_time;
- guint16 max_rx_octets, max_rx_time;
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- reply = g_dbus_proxy_call_sync(proxy, "LEReadMaximumDataLength",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- if (reply == NULL) {
- BT_ERR("LEReadMaximumDataLength dBUS-RPC failed");
- if (error != NULL) {
- BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(reply, "(qqqq)", &max_tx_octets, &max_tx_time,
- &max_rx_octets, &max_rx_time);
-
- max_le_datalength->max_tx_octets = max_tx_octets;
- max_le_datalength->max_tx_time = max_tx_time;
- max_le_datalength->max_rx_octets = max_rx_octets;
- max_le_datalength->max_rx_time = max_rx_time;
-
- g_variant_unref(reply);
-
- return BLUETOOTH_ERROR_NONE;
-}
-int _bt_le_write_host_suggested_default_data_length(
- const unsigned int def_tx_Octets, const unsigned int def_tx_Time)
-{
- GError *error = NULL;
- GDBusProxy *proxy;
- GVariant *reply = NULL;
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- reply = g_dbus_proxy_call_sync(proxy,
- "LEWriteHostSuggestedDataLength",
- g_variant_new("(qq)", def_tx_Octets, def_tx_Time),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (reply == NULL) {
- BT_ERR("_bt_le_write_host_suggested_default_data_length dBUS-RPC failed");
- if (error != NULL) {
- BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_unref(reply);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_le_read_host_suggested_default_data_length(
- bluetooth_le_read_host_suggested_data_length_t *def_data_length)
-{
- GError *error = NULL;
- GDBusProxy *proxy;
- GVariant *reply = NULL;
- guint16 def_tx_octets, def_tx_time;
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- reply = g_dbus_proxy_call_sync(proxy, "LEReadHostSuggestedDataLength",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- if (reply == NULL) {
- BT_ERR("LEReadHostSuggestedDataLength dBUS-RPC failed");
- if (error != NULL) {
- BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(reply, "(qq)", &def_tx_octets, &def_tx_time);
-
- def_data_length->def_tx_octets = def_tx_octets;
- def_data_length->def_tx_time = def_tx_time;
-
- g_variant_unref(reply);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_le_set_data_length(bluetooth_device_address_t *device_address,
- const unsigned int max_tx_Octets, const unsigned int max_tx_Time)
-{
- GError *error = NULL;
- guint16 txOctets = max_tx_Octets;
- guint16 txTime = max_tx_Time;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- gchar *device_path = NULL;
- GDBusConnection *conn;
- GDBusProxy *device_proxy;
- GVariant *result;
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- device_path = _bt_get_device_object_path(address);
-
- if (device_path == NULL) {
- BT_DBG("Device path is null");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- conn = _bt_gdbus_get_system_gconn();
- if (conn == NULL) {
- BT_ERR("conn == NULL");
- g_free(device_path);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_DEVICE_INTERFACE, NULL, NULL);
-
- g_free(device_path);
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(device_proxy,
- "LESetDataLength",
- g_variant_new("(qq)", txOctets, txTime),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- g_object_unref(device_proxy);
-
- if (error) {
- BT_ERR("LESetDataLength error: [%s]", error->message);
- g_error_free(error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (result)
- g_variant_unref(result);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_service_adapter_le_init(void)
-{
- le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_service_adapter_le_deinit(void)
-{
- __bt_free_le_adv_slot();
- __bt_free_le_scanner_all();
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <gio/gio.h>
-#include <glib.h>
-#include <dlog.h>
-#include <string.h>
-#include <vconf.h>
-#include <syspopup_caller.h>
-#include <aul.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus.h>
-#include <bundle.h>
-#include <eventsystem.h>
-#include <bundle_internal.h>
-
-#include "alarm.h"
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-#include "bt-service-adapter.h"
-#include "bt-service-util.h"
-#include "bt-service-network.h"
-#include "bt-service-obex-server.h"
-#include "bt-service-opp-client.h"
-#include "bt-service-agent.h"
-#include "bt-service-main.h"
-#include "bt-service-avrcp.h"
-#include "bt-service-device.h"
-#include "bt-service-adapter-le.h"
-
-#ifdef TIZEN_DPM_ENABLE
-#include "bt-service-dpm.h"
-#endif
-
-typedef struct {
- guint event_id;
- int timeout;
- time_t start_time;
- int alarm_id;
-} bt_adapter_timer_t;
-
-bt_adapter_timer_t visible_timer = {0, };
-
-typedef struct {
- alarm_id_t alarm_id;
- bt_set_alarm_cb callback;
- void *user_data;
-} bt_service_alarm_t;
-
-typedef struct {
- gboolean is_alarm_initialized;
- GList *g_alarm_list;
-} bt_service_alarm_mgr_t;
-
-static bt_service_alarm_mgr_t alarm_mgr = {0, };
-
-static gboolean is_discovering;
-static gboolean cancel_by_user;
-static bt_status_t adapter_status = BT_DEACTIVATED;
-static bt_le_status_t adapter_le_status = BT_LE_DEACTIVATED;
-static gboolean is_le_intended = FALSE;
-static void *adapter_agent = NULL;
-static GDBusProxy *core_proxy = NULL;
-static guint timer_id = 0;
-static guint le_timer_id = 0;
-static gboolean is_recovery_mode;
-static gboolean in_power_off;
-
-static guint poweroff_subscribe_id;
-static uint status_reg_id;
-
-#define BT_CORE_NAME "org.projectx.bt_core"
-#define BT_CORE_PATH "/org/projectx/bt_core"
-#define BT_CORE_INTERFACE "org.projectx.btcore"
-
-#define BT_DISABLE_TIME 500 /* 500 ms */
-
-static int alarm_cb(alarm_id_t alarm_id, void* user_param);
-static void alarm_data_free(void *data);
-
-GDBusProxy *_bt_init_core_proxy(void)
-{
- GDBusProxy *proxy;
- GDBusConnection *conn;
-
- conn = _bt_gdbus_get_system_gconn();
- if (!conn)
- return NULL;
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- BT_CORE_NAME,
- BT_CORE_PATH,
- BT_CORE_INTERFACE,
- NULL, NULL);
-
- if (!proxy)
- return NULL;
-
- core_proxy = proxy;
-
- return proxy;
-}
-
-static GDBusProxy *__bt_get_core_proxy(void)
-{
- return (core_proxy) ? core_proxy : _bt_init_core_proxy();
-}
-
-static gboolean __bt_is_factory_test_mode(void)
-{
- int mode = 0;
-
- if (vconf_get_bool(VCONFKEY_BT_DUT_MODE, &mode)) {
- BT_ERR("Get the DUT Mode fail");
- return TRUE;
- }
-
- if (mode != FALSE) {
- BT_INFO("DUT Test Mode !!");
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean __bt_timeout_handler(gpointer user_data)
-{
- int result = BLUETOOTH_ERROR_NONE;
- time_t current_time;
- int time_diff;
-
- /* Take current time */
- time(¤t_time);
- time_diff = difftime(current_time, visible_timer.start_time);
-
- /* Send event to application */
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED,
- g_variant_new("(in)", result, time_diff));
-
- if (visible_timer.timeout <= time_diff) {
- g_source_remove(visible_timer.event_id);
- visible_timer.event_id = 0;
- visible_timer.timeout = 0;
-
-#ifndef TIZEN_PROFILE_WEARABLE
- if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
- BT_ERR("Set vconf failed\n");
-#endif
- return FALSE;
- }
-
- return TRUE;
-}
-
-static int __bt_visibility_alarm_cb(alarm_id_t alarm_id, void* user_param)
-{
-
- int result = BLUETOOTH_ERROR_NONE;
- int timeout = 0;
-
- if (alarm_id != visible_timer.alarm_id)
- return 0;
-
- if (visible_timer.event_id) {
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED,
- g_variant_new("(in)", result, timeout));
- g_source_remove(visible_timer.event_id);
- visible_timer.event_id = 0;
- visible_timer.timeout = 0;
-
-#ifndef TIZEN_PROFILE_WEARABLE
- if (vconf_set_int(BT_FILE_VISIBLE_TIME, 0) != 0)
- BT_ERR("Set vconf failed\n");
-#endif
- }
- /* Switch Off visibility in Bluez */
- _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
- visible_timer.alarm_id = 0;
- return 0;
-}
-
-static void __bt_visibility_alarm_remove()
-{
- if (visible_timer.event_id > 0) {
- g_source_remove(visible_timer.event_id);
- visible_timer.event_id = 0;
- }
-
- if (visible_timer.alarm_id > 0) {
- _bt_service_remove_alarm(visible_timer.alarm_id);
- visible_timer.alarm_id = 0;
- }
-}
-
-int __bt_set_visible_time(int timeout)
-{
- int result;
- alarm_id_t alarm_id;
-
- __bt_visibility_alarm_remove();
-
- visible_timer.timeout = timeout;
-
-#ifndef TIZEN_PROFILE_WEARABLE
-#ifdef TIZEN_DPM_ENABLE
- if (_bt_dpm_get_bluetooth_limited_discoverable_state() != DPM_RESTRICTED) {
-#endif
- if (vconf_set_int(BT_FILE_VISIBLE_TIME, timeout) != 0)
- BT_ERR("Set vconf failed");
-#ifdef TIZEN_DPM_ENABLE
- }
-#endif
-#endif
-
-
- if (timeout <= 0)
- return BLUETOOTH_ERROR_NONE;
-
- result = _bt_service_set_alarm(visible_timer.timeout,
- __bt_visibility_alarm_cb, NULL, &alarm_id);
- if (result != BLUETOOTH_ERROR_NONE)
- return BLUETOOTH_ERROR_INTERNAL;
- visible_timer.alarm_id = alarm_id;
- /* Take start time */
- time(&(visible_timer.start_time));
- visible_timer.event_id = g_timeout_add_seconds(1,
- __bt_timeout_handler, NULL);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-static void __bt_get_service_list(GVariant *value, bluetooth_device_info_t *dev)
-{
- int i = 0;
- char **parts;
- GVariantIter *iter;
- gchar *uuid = NULL;
-
- ret_if(value == NULL);
- ret_if(dev == NULL);
-
- dev->service_index = 0;
-
- g_variant_get(value, "as", &iter);
- while (g_variant_iter_loop(iter, "s", &uuid)) {
- g_strlcpy(dev->uuids[i], uuid, BLUETOOTH_UUID_STRING_MAX);
- parts = g_strsplit(uuid, "-", -1);
-
- if (parts == NULL || parts[0] == NULL) {
- g_free(uuid);
- break;
- }
-
- dev->service_list_array[i] = g_ascii_strtoull(parts[0], NULL, 16);
- g_strfreev(parts);
-
- dev->service_index++;
- i++;
- }
- g_variant_iter_free(iter);
-}
-
-static int __bt_get_bonded_device_info(gchar *device_path,
- bluetooth_device_info_t *dev_info)
-{
- GError *error = NULL;
- GDBusProxy *device_proxy;
- gchar *address = NULL;
- gchar *name = NULL;
- gchar *alias = NULL;
- unsigned int cod = 0;
- gint rssi = 0;
- gboolean trust = FALSE;
- gboolean paired = FALSE;
- guchar connected = 0;
- GByteArray *manufacturer_data = NULL;
- int ret;
- GDBusConnection *conn;
- GVariant *result;
- GVariantIter *property_iter;
- const gchar *key;
- GVariant *value;
- guint8 char_value;
- GVariantIter *char_value_iter;
-
- BT_CHECK_PARAMETER(device_path, return);
- BT_CHECK_PARAMETER(dev_info, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- BT_BLUEZ_NAME,
- device_path,
- BT_PROPERTIES_INTERFACE,
- NULL, NULL);
-
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(device_proxy,
- "GetAll",
- g_variant_new("(s)", BT_DEVICE_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- BT_ERR("Error occured in Proxy call");
- if (error != NULL) {
- BT_ERR("Error occured in Proxy call (Error: %s)", error->message);
- g_clear_error(&error);
- }
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_object_unref(device_proxy);
-
- g_variant_get(result, "(a{sv})", &property_iter);
-
- while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
- if (!g_strcmp0(key, "Paired")) {
- paired = g_variant_get_boolean(value);
- } else if (!g_strcmp0(key, "Address")) {
- g_variant_get(value, "s", &address);
- } else if (!g_strcmp0(key, "Alias")) {
- g_variant_get(value, "s", &alias);
- } else if (!g_strcmp0(key, "Name")) {
- g_variant_get(value, "s", &name);
- } else if (!g_strcmp0(key, "Class")) {
- cod = g_variant_get_uint32(value);
- } else if (!g_strcmp0(key, "Connected")) {
- connected = g_variant_get_byte(value);
- } else if (!g_strcmp0(key, "Trusted")) {
- trust = g_variant_get_boolean(value);
- } else if (!g_strcmp0(key, "RSSI")) {
- rssi = g_variant_get_int16(value);
- } else if (!g_strcmp0(key, "UUIDs")) {
- __bt_get_service_list(value, dev_info);
- } else if (!g_strcmp0(key, "LegacyManufacturerDataLen")) {
- dev_info->manufacturer_data.data_len = g_variant_get_uint16(value);
- } else if (!g_strcmp0(key, "LegacyManufacturerData")) {
- manufacturer_data = g_byte_array_new();
- g_variant_get(value, "ay", &char_value_iter);
- while (g_variant_iter_loop(char_value_iter, "y", &char_value))
- g_byte_array_append(manufacturer_data, &char_value, 1);
-
- g_variant_iter_free(char_value_iter);
-
- if (manufacturer_data) {
- if (manufacturer_data->len > 0) {
- memcpy(dev_info->manufacturer_data.data, manufacturer_data->data,
- manufacturer_data->len);
- }
- }
- g_byte_array_free(manufacturer_data, TRUE);
- }
- }
- g_variant_iter_free(property_iter);
-
- BT_DBG("trust: %d, paired: %d", trust, paired);
-
- g_variant_unref(result);
-
- if ((paired == FALSE) && (trust == FALSE)) {
- g_free(address);
- g_free(alias);
- g_free(name);
- return BLUETOOTH_ERROR_NOT_PAIRED;
- }
-
- _bt_convert_addr_string_to_type(dev_info->device_address.addr,
- address);
-
- _bt_divide_device_class(&dev_info->device_class, cod);
-
- g_strlcpy(dev_info->device_name.name, alias ? alias : name,
- BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
-
- dev_info->rssi = rssi;
- dev_info->trust = trust;
- dev_info->paired = paired;
- dev_info->connected = connected;
- ret = BLUETOOTH_ERROR_NONE;
- g_free(address);
- g_free(alias);
- g_free(name);
-
- return ret;
-}
-
-void _bt_set_discovery_status(gboolean mode)
-{
- is_discovering = mode;
-}
-
-void _bt_set_cancel_by_user(gboolean value)
-{
- cancel_by_user = value;
-}
-
-gboolean _bt_get_cancel_by_user(void)
-{
- return cancel_by_user;
-}
-
-void _bt_adapter_set_status(bt_status_t status)
-{
- BT_INFO("adapter_status changed [%d] -> [%d]", adapter_status, status);
- adapter_status = status;
-}
-
-bt_status_t _bt_adapter_get_status(void)
-{
- return adapter_status;
-}
-
-void _bt_adapter_set_le_status(bt_le_status_t status)
-{
- BT_INFO("adapter_le_status changed [%d] -> [%d]", adapter_le_status, status);
- adapter_le_status = status;
-}
-
-bt_le_status_t _bt_adapter_get_le_status(void)
-{
- return adapter_le_status;
-}
-
-
-void _bt_set_le_intended_status(gboolean value)
-{
- is_le_intended = value;
-}
-
-static void __bt_set_in_poweroff(void)
-{
- BT_INFO("Set in_power_off to TRUE");
- in_power_off = TRUE;
-}
-
-static gboolean __bt_is_in_poweroff(void)
-{
- return in_power_off;
-}
-
-static void __bt_phone_name_changed_cb(keynode_t *node, void *data)
-{
- char *phone_name = NULL;
- char *ptr = NULL;
-
- if (node == NULL)
- return;
-
- if (vconf_keynode_get_type(node) == VCONF_TYPE_STRING) {
- phone_name = vconf_keynode_get_str(node);
-
- if (phone_name && strlen(phone_name) != 0) {
- if (!g_utf8_validate(phone_name, -1,
- (const char **)&ptr))
- *ptr = '\0';
-
- BT_INFO("device_name is changed to %s", phone_name);
- _bt_set_local_name(phone_name);
- } else {
- BT_ERR("phone_name is NOT valid");
- }
- } else {
- BT_ERR("vconf type is NOT string");
- }
-}
-
-static void __bt_set_local_name(void)
-{
- bluetooth_device_name_t local_name;
- char *phone_name = NULL;
- char *ptr = NULL;
- char *temp = NULL;
-
- if (_bt_get_local_name(&local_name) != BLUETOOTH_ERROR_NONE ||
- (temp = strstr(local_name.name, "BlueZ")) != NULL) {
- phone_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
-
- if (!phone_name)
- return;
-
- if (strlen(phone_name) != 0) {
- if (!g_utf8_validate(phone_name, -1, (const char **)&ptr))
- *ptr = '\0';
-
- _bt_set_local_name(phone_name);
- }
- free(phone_name);
- }
-}
-
-static int __bt_set_enabled(void)
-{
- int adapter_status = BT_ADAPTER_DISABLED;
- int result = BLUETOOTH_ERROR_NONE;
-
- if (timer_id > 0) {
- BT_DBG("g_source is removed");
- g_source_remove(timer_id);
- timer_id = 0;
- }
-
- _bt_check_adapter(&adapter_status);
-
- if (adapter_status == BT_ADAPTER_DISABLED) {
- BT_ERR("Bluetoothd is not running");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
-#ifdef TIZEN_PROFILE_MOBILE || defined(TIZEN_PROFILE_IVI)
- /* BT setting UI will control Mobile's visible mode. So in the FRWK...set the visible mode as off: */
- if (_bt_set_discoverable_mode(
- BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0) != BLUETOOTH_ERROR_NONE)
- BT_ERR("Set connectable mode failed");
-#else
-#ifdef TIZEN_TV
- if (_bt_set_discoverable_mode(
- BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE, 0) != BLUETOOTH_ERROR_NONE)
- BT_ERR("Fail to set discoverable mode");
-#endif
-#endif
-
- /* Update Bluetooth Status to notify other modules */
- if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON) != 0)
- BT_ERR("Set vconf failed\n");
-
- if (vconf_set_int(VCONFKEY_BT_DEVICE, VCONFKEY_BT_DEVICE_NONE) != 0)
- BT_ERR("Set vconf failed\n");
-
- if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
- EVT_VAL_BT_ON) != ES_R_OK)
- BT_ERR("Fail to set value");
-
- /* Send enabled event to API */
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
- g_variant_new("(i)", result));
-
-#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
- _bt_audio_start_auto_connect(FALSE);
-#endif
-
- __bt_set_local_name();
- _bt_set_discovery_status(FALSE);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_set_disabled(int result)
-{
- int power_off_status = 0;
- int ret;
- int ret_pm_ignore;
- int pm_ignore_mode = 0;
-
- ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status);
- BT_DBG("ret : %d, power_off_status : %d", ret, power_off_status);
-
- ret_pm_ignore = vconf_get_int(VCONFKEY_PM_KEY_IGNORE, &pm_ignore_mode);
-
- /* Update the vconf BT status in normal Deactivation case only */
- if (ret == 0 && power_off_status == VCONFKEY_SYSMAN_POWER_OFF_NONE &&
- ret_pm_ignore == 0 && pm_ignore_mode != VCONFKEY_PM_KEY_LOCK) {
-
- BT_DBG("Update vconf for BT normal Deactivation");
-
- if (result == BLUETOOTH_ERROR_TIMEOUT)
- if (vconf_set_int(BT_OFF_DUE_TO_TIMEOUT, 1) != 0)
- BT_ERR("Set vconf failed");
-
- /* Update Bluetooth Status to notify other modules */
- if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
- BT_ERR("Set vconf failed");
-
- if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_STATE,
- EVT_VAL_BT_OFF) != ES_R_OK)
- BT_ERR("Fail to set value");
- }
-
- if (vconf_set_int(VCONFKEY_BT_DEVICE, VCONFKEY_BT_DEVICE_NONE) != 0)
- BT_ERR("Set vconf failed\n");
-
- _bt_cancel_queued_transfers();
- _bt_adapter_set_status(BT_DEACTIVATED);
- _bt_set_discovery_status(FALSE);
-
-#ifndef USB_BLUETOOTH
- if (_bt_adapter_get_le_status() != BT_LE_DEACTIVATED) {
-#endif
- /* Send disabled event */
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
- g_variant_new("(i)", result));
-#ifndef USB_BLUETOOTH
- }
-#endif
-
- BT_INFO("Adapter disabled");
-}
-
-static int __bt_set_le_enabled(void)
-{
- BT_DBG("+");
- int result = BLUETOOTH_ERROR_NONE;
- bt_status_t status;
-
- /* Update Bluetooth Status to notify other modules */
- if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_ON) != 0)
- BT_ERR("Set vconf failed");
-
- /* set packet length to max size to enable packet length extension */
- if (BLUETOOTH_ERROR_NONE != _bt_le_set_max_packet_len())
- BT_ERR("Fail to set max packet length");
-
- if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
- EVT_VAL_BT_LE_ON) != ES_R_OK)
- BT_ERR("Fail to set value");
-
- /* Send enabled event to API */
- /*
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
- DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
- */
- status = _bt_adapter_get_status();
- if (status == BT_DEACTIVATED) {
- BT_INFO("BREDR is off, turn off PSCAN");
- _bt_set_connectable(FALSE);
- }
- if (le_timer_id > 0) {
- g_source_remove(le_timer_id);
- le_timer_id = 0;
- }
-
- /* Send enabled event to API */
- _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_ENABLED,
- g_variant_new("(i)", result));
-
- __bt_set_local_name();
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_set_le_disabled(int result)
-{
- int power_off_status;
- int ret;
-
- ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status);
- BT_DBG("ret : %d", ret);
- BT_DBG("power_off_status : %d", power_off_status);
-
- /* Update Bluetooth Status to notify other modules */
- BT_DBG("Update vconf for BT LE normal Deactivation");
- if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0)
- BT_ERR("Set vconf failed\n");
- _bt_adapter_set_le_status(BT_LE_DEACTIVATED);
-
- if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
- EVT_VAL_BT_LE_OFF) != ES_R_OK)
- BT_ERR("Fail to set value");
-
- /* Send disabled event */
- _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_DISABLED,
- g_variant_new("(i)", result));
-}
-
-void *_bt_get_adapter_agent(void)
-{
- return adapter_agent;
-}
-
-int _bt_enable_core(void)
-{
- GDBusProxy *proxy;
- GVariant *result;
- GError *error = NULL;
-
- proxy = __bt_get_core_proxy();
- retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
-
- /* Clean up the process */
- result = g_dbus_proxy_call_sync(proxy,
- "EnableCore",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Bt core call failed(Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Bt core call failed");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_unref(result);
- return BLUETOOTH_ERROR_NONE;
-}
-
-#if defined(TIZEN_FEATURE_FLIGHTMODE_ENABLED) || (!defined(TIZEN_PROFILE_WEARABLE))
-static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data)
-{
- gboolean flight_mode = FALSE;
- int power_saving_mode = 0;
- int type;
-
- DBG_SECURE("key=%s", vconf_keynode_get_name(node));
- type = vconf_keynode_get_type(node);
- if (type == VCONF_TYPE_BOOL) {
- flight_mode = vconf_keynode_get_bool(node);
- if (flight_mode != TRUE) {
- BT_ERR("Ignore the event");
- return;
- }
- } else if (type == VCONF_TYPE_INT) {
- power_saving_mode = vconf_keynode_get_int(node);
- if (power_saving_mode != 2) {
- BT_ERR("Ignore the event");
- return;
- }
- } else {
- BT_ERR("Invaild vconf key type : %d", type);
- return;
- }
-
- _bt_enable_core();
-}
-#endif
-
-static void __bt_poweroff_event_filter(GDBusConnection *connection,
- const gchar *sender_name, const gchar *object_path,
- const gchar *interface_name, const gchar *signal_name,
- GVariant *parameters, gpointer user_data)
-{
- int state = 0;
-
- g_variant_get(parameters, "(i)", &state);
-
- if (state != BT_DEVICED_POWEROFF_SIGNAL_POWEROFF &&
- state != BT_DEVICED_POWEROFF_SIGNAL_REBOOT) {
- BT_DBG("Not interested event : %d", state);
- return;
- }
-
- if (_bt_adapter_get_status() == BT_ACTIVATING) {
- BT_INFO("Just update VCONFKEY_BT_STATUS in Power off");
- if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON))
- BT_ERR("Set VCONFKEY_BT_STATUS failed");
- } else {
- __bt_set_in_poweroff();
- }
-}
-
-void _bt_service_register_poweroff_event(void)
-{
- if (poweroff_subscribe_id)
- return;
-
- poweroff_subscribe_id = g_dbus_connection_signal_subscribe(
- _bt_gdbus_get_system_gconn(), NULL,
- BT_DEVICED_POWEROFF_INTERFACE,
- BT_DEVICED_POWEROFF_SIGNAL,
- BT_DEVICED_POWEROFF_OBJECT_PATH,
- NULL, 0, __bt_poweroff_event_filter, NULL, NULL);
-}
-
-void _bt_service_unregister_poweroff_event(void)
-{
- if (poweroff_subscribe_id == 0)
- return;
-
- g_dbus_connection_signal_unsubscribe(_bt_gdbus_get_system_gconn(),
- poweroff_subscribe_id);
- poweroff_subscribe_id = 0;
-}
-
-void _bt_service_register_vconf_handler(void)
-{
- BT_DBG("+");
-
-#ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
- if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
- (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
- BT_ERR("Unable to register key handler");
-#else
- BT_DBG("Telephony is disabled");
-#endif
-
-#ifndef TIZEN_PROFILE_WEARABLE
- if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
- (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
- BT_ERR("Unable to register key handler");
-#endif
-}
-
-void _bt_service_unregister_vconf_handler(void)
-{
- BT_DBG("+");
-
-#ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
- vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
- (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
-#endif
-
-#ifndef TIZEN_PROFILE_WEARABLE
- vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
- (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
-#endif
-}
-
-static void __bt_state_event_handler(const char *event_name, bundle *data, void *user_data)
-{
- const char *bt_status = NULL;
- const char *bt_le_status = NULL;
- BT_DBG("bt state set event(%s) received", event_name);
-
- bt_status = bundle_get_val(data, EVT_KEY_BT_STATE);
- BT_DBG("bt_state: (%s)", bt_status);
-
- bt_le_status = bundle_get_val(data, EVT_KEY_BT_LE_STATE);
- BT_DBG("bt_state: (%s)", bt_le_status);
-}
-
-void _bt_handle_adapter_added(void)
-{
- BT_DBG("+");
- bt_status_t status;
- bt_le_status_t le_status;
- int ret;
-/*
- if (timer_id > 0) {
- BT_DBG("g_source is removed");
- g_source_remove(timer_id);
- timer_id = 0;
- }
-*/
-
- status = _bt_adapter_get_status();
- le_status = _bt_adapter_get_le_status();
- BT_INFO("status : %d", status);
- BT_INFO("le_status : %d", le_status);
-
-#ifndef USB_BLUETOOTH
- adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE);
- if (!adapter_agent) {
- BT_ERR("Fail to register agent");
- return;
- }
-#else
- if (adapter_agent == NULL) {
- adapter_agent = _bt_create_agent(BT_ADAPTER_AGENT_PATH, TRUE);
- if (!adapter_agent) {
- BT_ERR("Fail to register agent");
- return;
- }
- }
-#endif
-
- if (_bt_register_media_player() != BLUETOOTH_ERROR_NONE)
- BT_ERR("Fail to register media player");
-
- if (_bt_register_obex_server() != BLUETOOTH_ERROR_NONE)
- BT_ERR("Fail to init obex server");
-
-#ifdef TIZEN_BT_PAN_NAP_ENABLED
- if (_bt_network_activate() != BLUETOOTH_ERROR_NONE)
- BT_ERR("Fail to activate network");
-#endif
-
- /* add the vconf noti handler */
- ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
- __bt_phone_name_changed_cb, NULL);
- if (ret < 0)
- BT_ERR("Unable to register key handler");
-
- if (le_status == BT_LE_ACTIVATING ||
- status == BT_ACTIVATING) {
- __bt_set_le_enabled();
- _bt_adapter_set_le_status(BT_LE_ACTIVATED);
- }
-
- if (status == BT_ACTIVATING) {
- __bt_set_enabled();
- _bt_adapter_set_status(BT_ACTIVATED);
- }
-
- /* eventsystem */
- if (eventsystem_register_event(SYS_EVENT_BT_STATE, &status_reg_id,
- (eventsystem_handler)__bt_state_event_handler, NULL) != ES_R_OK) {
- BT_ERR("Fail to register system event");
- }
-}
-
-void _bt_handle_adapter_removed(void)
-{
- int ret;
-
- _bt_adapter_set_status(BT_DEACTIVATED);
-
- __bt_visibility_alarm_remove();
-
- if (alarm_mgr.is_alarm_initialized == TRUE) {
- alarmmgr_fini();
- alarm_mgr.is_alarm_initialized = FALSE;
- g_list_free_full(alarm_mgr.g_alarm_list, alarm_data_free);
- alarm_mgr.g_alarm_list = NULL;
- }
-
-#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
- _bt_audio_stop_auto_connect();
-#endif
-
- ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
- (vconf_callback_fn)__bt_phone_name_changed_cb);
- if (0 != ret)
- ERR("vconf_ignore_key_changed failed\n");
-
-#ifndef USB_BLUETOOTH
- _bt_destroy_agent(adapter_agent);
- adapter_agent = NULL;
-
- if (is_recovery_mode == TRUE) {
- /* Send disabled event */
- _bt_set_disabled(BLUETOOTH_ERROR_NONE);
-
- /* Will recover BT by bt-core, so set the mode as activating */
- _bt_adapter_set_status(BT_ACTIVATING);
- is_recovery_mode = FALSE;
- } else {
- _bt_reliable_terminate_service(NULL);
- }
-#else
- _bt_set_disabled(BLUETOOTH_ERROR_NONE);
-#endif
-
- if (eventsystem_unregister_event(status_reg_id) != ES_R_OK)
- BT_ERR("Fail to unregister system event");
-}
-
-static gboolean __bt_enable_timeout_cb(gpointer user_data)
-{
- GDBusProxy *proxy;
- GVariant *result;
- GError *error = NULL;
-
- timer_id = 0;
-
- retv_if(_bt_adapter_get_status() == BT_ACTIVATED, FALSE);
-
- BT_ERR("EnableAdapter is failed");
-
- proxy = __bt_get_core_proxy();
- if (!proxy)
- return FALSE;
-
- /* Clean up the process */
- result = g_dbus_proxy_call_sync(proxy,
- "DisableAdapter",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Bt core call failed(Error: %s)", error->message);
- g_clear_error(&error);
- } else {
- BT_ERR("Bt core call failed");
- }
- return FALSE;
- }
-
- g_variant_unref(result);
- _bt_set_disabled(BLUETOOTH_ERROR_TIMEOUT);
-
-#ifndef USB_BLUETOOTH
- _bt_terminate_service(NULL);
-#endif
-
- return FALSE;
-}
-
-static gboolean __bt_enable_le_timeout_cb(gpointer user_data)
-{
- GDBusProxy *proxy;
- GVariant *result;
- GError *error = NULL;
-
- le_timer_id = 0;
-
- retv_if(_bt_adapter_get_le_status() == BT_LE_ACTIVATED, FALSE);
-
- BT_ERR("EnableAdapterLE is failed");
-
- proxy = __bt_get_core_proxy();
- if (!proxy)
- return FALSE;
-
- /* Clean up the process */
- result = g_dbus_proxy_call_sync(proxy,
- "DisableAdapterLe",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Bt core call failed(Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Bt core call failed");
- return FALSE;
- }
-
- g_variant_unref(result);
- _bt_adapter_set_le_status(BT_LE_DEACTIVATED);
-
- _bt_set_le_disabled(BLUETOOTH_ERROR_TIMEOUT);
-
- if (_bt_adapter_get_status() == BT_DEACTIVATED)
- _bt_terminate_service(NULL);
-
- return FALSE;
-}
-
-void _bt_adapter_start_le_enable_timer(void)
-{
- if (le_timer_id > 0) {
- g_source_remove(le_timer_id);
- le_timer_id = 0;
- }
-
- le_timer_id = g_timeout_add(BT_ENABLE_TIMEOUT,
- __bt_enable_le_timeout_cb, NULL);
-
- return;
-}
-
-void _bt_adapter_start_enable_timer(void)
-{
- if (timer_id > 0) {
- g_source_remove(timer_id);
- timer_id = 0;
- }
-
- timer_id = g_timeout_add(BT_ENABLE_TIMEOUT,
- __bt_enable_timeout_cb, NULL);
-
- return;
-}
-
-#ifdef TIZEN_TV
-static gboolean __bt_adapter_enabled_cb(gpointer user_data)
-{
- BT_DBG("+");
-
- __bt_set_enabled();
- _bt_adapter_set_status(BT_ACTIVATED);
-
- return FALSE;
-}
-#endif
-
-int _bt_enable_adapter_check_status(void)
-{
- bt_status_t status = _bt_adapter_get_status();
- bt_le_status_t le_status = _bt_adapter_get_le_status();
-
- BT_DBG("");
-
- if (status == BT_ACTIVATING) {
- BT_ERR("Enabling in progress");
- return BLUETOOTH_ERROR_IN_PROGRESS;
- }
-
- if (status == BT_ACTIVATED) {
- BT_ERR("Already enabled");
- return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
- }
-
- if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) {
- BT_ERR("Disabling in progress");
- return BLUETOOTH_ERROR_DEVICE_BUSY;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_enable_adapter(void)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- int ret;
- GVariant *result = NULL;
- bt_status_t status = _bt_adapter_get_status();
- bt_le_status_t le_status = _bt_adapter_get_le_status();
-
- BT_DBG("");
-
- if (status == BT_ACTIVATING) {
- BT_ERR("Enabling in progress");
- return BLUETOOTH_ERROR_IN_PROGRESS;
- }
-
- if (status == BT_ACTIVATED) {
- BT_ERR("Already enabled");
- return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
- }
-
- if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) {
- BT_ERR("Disabling in progress");
- return BLUETOOTH_ERROR_DEVICE_BUSY;
- }
-
- _bt_adapter_set_status(BT_ACTIVATING);
-
-#ifdef TIZEN_TV
-{
- int adapter_status = BT_ADAPTER_DISABLED;
-
- if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_OFF) != 0)
- BT_ERR("Set vconf failed");
-
- _bt_check_adapter(&adapter_status);
- if (adapter_status == BT_ADAPTER_ENABLED) {
- g_idle_add(__bt_adapter_enabled_cb, NULL);
- _bt_adapter_start_enable_timer();
- return BLUETOOTH_ERROR_NONE;
- }
-}
-#endif
-
- if (__bt_is_in_poweroff() == TRUE) {
- BT_INFO("Just update VCONFKEY_BT_STATUS in Power off");
- if (vconf_set_int(VCONFKEY_BT_STATUS, VCONFKEY_BT_STATUS_ON) != 0)
- BT_ERR("Set VCONFKEY_BT_STATUS failed");
- return BLUETOOTH_ERROR_NONE;
- }
-
- proxy = __bt_get_core_proxy();
- if (!proxy)
- return BLUETOOTH_ERROR_INTERNAL;
-
- if (le_status == BT_LE_ACTIVATED) {
- BT_INFO("LE Already enabled. Just turn on PSCAN");
- ret = _bt_set_connectable(TRUE);
- if (ret == BLUETOOTH_ERROR_NONE)
- _bt_adapter_set_status(BT_ACTIVATED);
- else
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- result = g_dbus_proxy_call_sync(proxy, "EnableAdapter",
- NULL,
- G_DBUS_CALL_FLAGS_NONE, BT_ENABLE_TIMEOUT,
- NULL, &error);
- if (error) {
- BT_ERR("EnableAdapterLe failed: %s", error->message);
- _bt_adapter_set_status(BT_DEACTIVATED);
- g_clear_error(&error);
- error = NULL;
- result = g_dbus_proxy_call_sync(proxy,
- "DisableAdapter",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error != NULL) {
- BT_ERR("Bt core call failed(Error: %s)", error->message);
- g_clear_error(&error);
- }
- g_variant_unref(result);
-#ifndef USB_BLUETOOTH
- /* Terminate myself */
- g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
-#endif
- return BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_unref(result);
- if (le_status == BT_LE_ACTIVATED)
- __bt_set_enabled();
- else
- _bt_adapter_start_enable_timer();
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-static gboolean __bt_disconnect_all(void)
-{
- int i;
- GDBusConnection *conn;
- GDBusProxy *dev_proxy;
- gboolean ret = FALSE;
- GVariant *result;
- GError *error = NULL;
- GArray *device_list;
- bluetooth_device_info_t *info;
- guint size;
- char *device_path = NULL;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
-
-
- BT_DBG("");
-
- conn = _bt_gdbus_get_system_gconn();
-
- device_list = g_array_new(FALSE, FALSE, sizeof(gchar));
-
- if (_bt_get_bonded_devices(&device_list)
- != BLUETOOTH_ERROR_NONE) {
- g_array_free(device_list, TRUE);
- return FALSE;
- }
-
- size = (device_list->len) / sizeof(bluetooth_device_info_t);
-
- for (i = 0; i < size; i++) {
-
- info = &g_array_index(device_list,
- bluetooth_device_info_t, i);
-
- if (info->connected != BLUETOOTH_CONNECTED_LINK_NONE) {
- BT_DBG("Found Connected device");
- _bt_convert_addr_type_to_string(address, info->device_address.addr);
- device_path = _bt_get_device_object_path(address);
- if (device_path == NULL)
- continue;
-
- BT_DBG("Disconnecting : %s", device_path);
-
- dev_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- BT_BLUEZ_NAME,
- device_path,
- BT_DEVICE_INTERFACE,
- NULL, NULL);
-
- if (dev_proxy == NULL)
- continue;
-
- result = g_dbus_proxy_call_sync(dev_proxy,
- "Disconnect",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Disconnect call failed(Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Disconnect call failed");
- g_object_unref(dev_proxy);
- return FALSE;
- }
-
- g_variant_unref(result);
- g_object_unref(dev_proxy);
- }
- }
- ret = TRUE;
- g_array_free(device_list, TRUE);
-
- return ret;
-}
-
-#if 0
-static gboolean __bt_set_disabled_timeout_cb(gpointer user_data)
-{
- BT_DBG("");
- _bt_set_disabled(BLUETOOTH_ERROR_NONE);
-
- return FALSE;
-}
-#endif
-
-int _bt_disable_cb(void)
-{
- FN_START;
- GDBusProxy *proxy;
-#if 0
- int ret;
-#endif
- GVariant *result;
- GError *error = NULL;
-
- _bt_adapter_set_status(BT_DEACTIVATING);
-#if 0
- bt_le_status_t le_status;
- le_status = _bt_adapter_get_le_status();
- BT_DBG("le_status : %d", le_status);
- if (le_status == BT_LE_ACTIVATED) {
- BT_INFO("LE is enabled. Just turn off PSCAN");
-
- if (_bt_is_discovering())
- _bt_cancel_discovery();
-
- if (_bt_is_connectable() == FALSE) {
- g_timeout_add(100, (GSourceFunc)__bt_set_disabled_timeout_cb, NULL);
- } else {
- ret = _bt_set_connectable(FALSE);
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("_bt_set_connectable fail!");
- _bt_adapter_set_status(BT_ACTIVATED);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- }
- }
-#endif
- proxy = __bt_get_core_proxy();
- retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "DisableAdapter",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to DisableAdapter (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to DisableAdapter");
- _bt_adapter_set_status(BT_ACTIVATED);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_unref(result);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_disable_adapter_check_status(void)
-{
- bt_status_t status = _bt_adapter_get_status();
-
- BT_DBG("");
-
- if (status == BT_DEACTIVATING) {
- BT_DBG("Disabling in progress");
- return BLUETOOTH_ERROR_IN_PROGRESS;
- }
-
- if (status == BT_DEACTIVATED) {
- BT_DBG("Already disabled");
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_disable_adapter(void)
-{
- BT_DBG("+");
- int ret;
-
- if (_bt_adapter_get_status() == BT_DEACTIVATING) {
- BT_DBG("Disabling in progress");
- return BLUETOOTH_ERROR_IN_PROGRESS;
- }
-
- if (_bt_adapter_get_status() == BT_DEACTIVATED) {
- BT_DBG("Already disabled");
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- if (timer_id > 0) {
- g_source_remove(timer_id);
- timer_id = 0;
- }
-
- __bt_disconnect_all();
- ret = _bt_disable_cb();
-
- BT_DBG("-");
- return ret;
-}
-
-int _bt_recover_adapter(void)
-{
- BT_DBG("+");
- GDBusProxy *proxy;
- GVariant *result;
- GError *error = NULL;
-
- if (_bt_adapter_get_status() == BT_DEACTIVATING) {
- BT_ERR("Disabling in progress");
- return BLUETOOTH_ERROR_IN_PROGRESS;
- }
-
- if (_bt_adapter_get_status() == BT_DEACTIVATED) {
- BT_ERR("Already disabled");
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- _bt_adapter_set_status(BT_DEACTIVATING);
-
- proxy = __bt_get_core_proxy();
- retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "RecoverAdapter",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to RecoverAdapter (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to RecoverAdapter");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- is_recovery_mode = TRUE;
-
- g_variant_unref(result);
- __bt_disconnect_all();
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_reset_adapter(void)
-{
- GDBusProxy *proxy;
- GVariant *result;
- GError *error = NULL;
-
- BT_DBG("");
-
- proxy = __bt_get_core_proxy();
- if (!proxy)
- return BLUETOOTH_ERROR_INTERNAL;
-
- result = g_dbus_proxy_call_sync(proxy,
- "ResetAdapter",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to ResetAdapter (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to ResetAdapter");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_unref(result);
- /* Terminate myself */
- if (_bt_adapter_get_status() == BT_DEACTIVATED)
- g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-#ifndef TIZEN_TV
-int _bt_check_adapter(int *status)
-{
-
- char *adapter_path = NULL;
-
- BT_CHECK_PARAMETER(status, return);
-
- *status = BT_ADAPTER_DISABLED;
-
- adapter_path = _bt_get_adapter_path();
-
-
- if (adapter_path != NULL)
- *status = BT_ADAPTER_ENABLED;
-
- g_free(adapter_path);
- return BLUETOOTH_ERROR_NONE;
-}
-#else
-int _bt_check_adapter(int *status)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *result;
- GVariant *temp;
- gboolean powered = FALSE;
-
- BT_CHECK_PARAMETER(status, return);
-
- *status = BT_ADAPTER_DISABLED;
-
- proxy = _bt_get_adapter_properties_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "Get",
- g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
- "Powered"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- BT_ERR("Failed to get local address");
- if (error != NULL) {
- BT_ERR("Failed to get local address (Error: %s)", error->message);
- g_clear_error(&error);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(result, "(v)", &temp);
- powered = g_variant_get_boolean(temp);
- BT_DBG("powered: %d", powered);
-
- if (powered)
- *status = BT_ADAPTER_ENABLED;
-
- g_variant_unref(result);
- g_variant_unref(temp);
- return BLUETOOTH_ERROR_NONE;
-}
-#endif
-
-int _bt_enable_adapter_le(void)
-{
- BT_DBG("+");
- GDBusProxy *proxy;
- GError *error = NULL;
- bt_status_t status = _bt_adapter_get_status();
- bt_le_status_t le_status = _bt_adapter_get_le_status();
- GVariant *result;
-
- if (le_status == BT_LE_ACTIVATING) {
- BT_ERR("Enabling in progress");
- return BLUETOOTH_ERROR_IN_PROGRESS;
- }
-
- if (le_status == BT_LE_ACTIVATED) {
- BT_ERR("Already enabled");
- return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
- }
-
- if (status == BT_DEACTIVATING || le_status == BT_LE_DEACTIVATING) {
- BT_ERR("Disabling in progress");
- return BLUETOOTH_ERROR_DEVICE_BUSY;
- }
-
- _bt_adapter_set_le_status(BT_LE_ACTIVATING);
-
- proxy = __bt_get_core_proxy();
- retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy, "EnableAdapterLe",
- NULL,
- G_DBUS_CALL_FLAGS_NONE, BT_ENABLE_TIMEOUT,
- NULL, &error);
- if (error) {
- BT_ERR("EnableAdapterLe failed: %s", error->message);
- _bt_adapter_set_le_status(BT_DEACTIVATED);
- g_clear_error(&error);
-
- /* Clean up the process */
- result = g_dbus_proxy_call_sync(proxy,
- "DisableAdapterLe",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- BT_ERR("Bt core call failed");
- if (error) {
- BT_ERR("EnableAdapterLE Failed %s", error->message);
- g_clear_error(&error);
- }
- }
- g_variant_unref(result);
- /* Terminate myself */
- if (_bt_adapter_get_status() == BT_DEACTIVATED)
- g_idle_add((GSourceFunc)_bt_terminate_service, NULL);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (result)
- g_variant_unref(result);
-
- _bt_adapter_start_le_enable_timer();
-
- if (status == BT_ACTIVATED) {
- _bt_adapter_set_le_status(BT_LE_ACTIVATED);
- __bt_set_le_enabled();
- }
- BT_DBG("le status : %d", _bt_adapter_get_le_status());
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_disable_adapter_le(void)
-{
- BT_DBG("+");
- GDBusProxy *proxy;
- bt_le_status_t bt_le_state;
- GVariant *result;
- GError *error = NULL;
-
- bt_le_state = _bt_adapter_get_le_status();
- if (bt_le_state == BT_LE_DEACTIVATING) {
- BT_DBG("Disabling in progress");
- return BLUETOOTH_ERROR_IN_PROGRESS;
- }
-
- if (bt_le_state == BT_LE_DEACTIVATED) {
- BT_DBG("Already disabled");
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
-
- proxy = __bt_get_core_proxy();
- if (!proxy)
- return BLUETOOTH_ERROR_INTERNAL;
-
- result = g_dbus_proxy_call_sync(proxy,
- "DisableAdapterLe",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Bt core call failed (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Bt core call failed");
- _bt_adapter_set_le_status(BT_LE_ACTIVATED);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_unref(result);
- _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
- BT_DBG("le status : %d", _bt_adapter_get_le_status());
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_get_local_address(bluetooth_device_address_t *local_address)
-{
-
- GDBusProxy *proxy;
- GError *error = NULL;
- const char *address;
- GVariant *result;
- GVariant *temp;
-
- BT_CHECK_PARAMETER(local_address, return);
-
- proxy = _bt_get_adapter_properties_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "Get",
- g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
- "Address"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- BT_ERR("Failed to get local address");
- if (error != NULL) {
- BT_ERR("Failed to get local address (Error: %s)", error->message);
- g_clear_error(&error);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(result, "(v)", &temp);
- address = g_variant_get_string(temp, NULL);
- BT_DBG("Address:%s", address);
-
- if (address)
- _bt_convert_addr_string_to_type(local_address->addr, address);
- else
- return BLUETOOTH_ERROR_INTERNAL;
-
- g_variant_unref(result);
- g_variant_unref(temp);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_get_local_version(bluetooth_version_t *local_version)
-{
- GDBusProxy *proxy;
- const char *ver = NULL;
- char *ptr = NULL;
- int ret = BLUETOOTH_ERROR_NONE;
- GVariant *result;
- GVariant *temp;
-
- BT_CHECK_PARAMETER(local_version, return);
-
- GError *error = NULL;
-
- proxy = _bt_get_adapter_properties_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "Get",
- g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
- "Version"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to get local version (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to get local version");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(result, "(v)", &temp);
- ver = g_variant_get_string(temp, NULL);
- BT_DBG("VERSION: %s", ver);
-
- if (ver && (strlen(ver) > 0)) {
- /* Check the utf8 valitation & Fill the NULL in the invalid location*/
- if (!g_utf8_validate(ver, -1, (const char **)&ptr))
- *ptr = '\0';
-
- g_strlcpy(local_version->version, ver,
- BLUETOOTH_VERSION_LENGTH_MAX + 1);
-
- } else {
- ret = BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_unref(result);
- g_variant_unref(temp);
- return ret;
-}
-
-int _bt_get_local_name(bluetooth_device_name_t *local_name)
-{
- GDBusProxy *proxy;
- const char *name = NULL;
- char *ptr = NULL;
- int ret = BLUETOOTH_ERROR_NONE;
- GVariant *result;
- GVariant *temp;
- GError *error = NULL;
-
- BT_CHECK_PARAMETER(local_name, return);
-
- proxy = _bt_get_adapter_properties_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "Get",
- g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
- "Alias"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to get local name (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to get local name");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(result, "(v)", &temp);
- name = g_variant_get_string(temp, NULL);
- BT_DBG("LOCAL NAME:%s", name);
-
- if (name && (strlen(name) > 0)) {
- /* Check the utf8 valitation & Fill the NULL in the invalid location*/
- if (!g_utf8_validate(name, -1, (const char **)&ptr))
- *ptr = '\0';
-
- g_strlcpy(local_name->name, name,
- BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1);
- } else {
- ret = BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_unref(result);
- g_variant_unref(temp);
- return ret;
-}
-
-int _bt_set_local_name(char *local_name)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- char *ptr = NULL;
- GVariant *result;
-
- BT_CHECK_PARAMETER(local_name, return);
-
- proxy = _bt_get_adapter_properties_proxy();
-
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- if (!g_utf8_validate(local_name, -1, (const char **)&ptr))
- *ptr = '\0';
-
- result = g_dbus_proxy_call_sync(proxy,
- "Set",
- g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
- "Alias", g_variant_new("s", local_name)),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to set Alias (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to set Alias");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_unref(result);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_is_service_used(char *service_uuid, gboolean *used)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- int ret = BLUETOOTH_ERROR_NONE;
- GVariant *result;
- GVariant *temp = NULL;
- GVariantIter *iter = NULL;
- gchar *uuid = NULL;
-
- BT_DBG("+");
- BT_CHECK_PARAMETER(service_uuid, return);
- BT_CHECK_PARAMETER(used, return);
-
- proxy = _bt_get_adapter_properties_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "Get",
- g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
- "UUIDs"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to get UUIDs (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to get UUIDs");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(result, "(v)", &temp);
- g_variant_get(temp, "as", &iter);
-
- *used = FALSE;
- while (g_variant_iter_loop(iter, "&s", &uuid)) {
- if (strcasecmp(uuid, service_uuid) == 0) {
- *used = TRUE;
- break;
- }
- }
- g_variant_iter_free(iter);
- g_variant_unref(result);
- g_variant_unref(temp);
-
- BT_DBG("Service Used? %d", *used);
-
- return ret;
-}
-
-static gboolean __bt_get_discoverable_property(void)
-{
- GDBusProxy *proxy;
- gboolean discoverable_v;
- GError *error = NULL;
- GVariant *result;
- GVariant *temp;
-
- proxy = _bt_get_adapter_properties_proxy();
- retv_if(proxy == NULL, FALSE);
-
- result = g_dbus_proxy_call_sync(proxy,
- "Get",
- g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
- "Discoverable"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to get Discoverable property (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to get Discoverable property");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(result, "(v)", &temp);
- discoverable_v = g_variant_get_boolean(temp);
- BT_DBG("discoverable_v:%d", discoverable_v);
-
- g_variant_unref(result);
- g_variant_unref(temp);
-
- return discoverable_v;
-}
-
-int _bt_get_discoverable_mode(int *mode)
-{
- gboolean discoverable;
- unsigned int timeout;
-
- BT_CHECK_PARAMETER(mode, return);
-
- discoverable = __bt_get_discoverable_property();
- timeout = _bt_get_discoverable_timeout_property();
-
- if (discoverable == TRUE) {
- if (timeout == 0)
- *mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
- else
- *mode = BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE;
- } else {
- *mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
- }
- return BLUETOOTH_ERROR_NONE;
-}
-
-
-int _bt_set_discoverable_mode(int discoverable_mode, int timeout)
-{
- int ret = BLUETOOTH_ERROR_NONE;
- gboolean inq_scan;
- gboolean pg_scan;
- GError *error = NULL;
- GDBusProxy *proxy;
- GVariant *result;
-
- proxy = _bt_get_adapter_properties_proxy();
-
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-#ifdef TIZEN_DPM_ENABLE
- if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE &&
- _bt_dpm_get_bluetooth_limited_discoverable_state() == DPM_RESTRICTED) {
- _bt_launch_dpm_popup("DPM_POLICY_DISABLE_BT_HANDSFREE");
- return BLUETOOTH_ERROR_ACCESS_DENIED;
- }
- if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE &&
- _bt_dpm_get_bluetooth_limited_discoverable_state() == DPM_RESTRICTED) {
- _bt_launch_dpm_popup("DPM_POLICY_DISABLE_BT");
- return BLUETOOTH_ERROR_ACCESS_DENIED;
- }
-#endif
-
- switch (discoverable_mode) {
- case BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE:
- pg_scan = TRUE;
- inq_scan = FALSE;
- timeout = 0;
- break;
- case BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE:
- pg_scan = TRUE;
- inq_scan = TRUE;
- timeout = 0;
- break;
- case BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE:
- inq_scan = TRUE;
- pg_scan = TRUE;
- break;
- default:
- return BLUETOOTH_ERROR_INVALID_PARAM;
- }
-
- BT_INFO("Req. discoverable_mode : %d, timeout : %d",
- discoverable_mode, timeout);
-
- result = g_dbus_proxy_call_sync(proxy,
- "Set",
- g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
- "Connectable", g_variant_new("b", pg_scan)),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to set connectable property (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to set connectable property");
- return BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_unref(result);
- result = g_dbus_proxy_call_sync(proxy,
- "Set",
- g_variant_new("(ssv)", BT_ADAPTER_INTERFACE, "Discoverable",
- g_variant_new("b", inq_scan)),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to set Discoverable property (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to set Discoverable property");
- return BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_unref(result);
- result = g_dbus_proxy_call_sync(proxy,
- "Set",
- g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
- "DiscoverableTimeout", g_variant_new("u", timeout)),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to set DiscoverableTimeout property (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to set DiscoverableTimeout property");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (discoverable_mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE)
- timeout = -1;
-
- ret = __bt_set_visible_time(timeout);
-
- g_variant_unref(result);
-
- return ret;
-}
-
-int _bt_start_discovery(void)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *result;
-
- if (_bt_is_discovering() == TRUE) {
- BT_ERR("BT is already in discovering");
- return BLUETOOTH_ERROR_IN_PROGRESS;
- } else if (_bt_is_device_creating() == TRUE) {
- BT_ERR("Bonding device is going on");
- return BLUETOOTH_ERROR_DEVICE_BUSY;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "StartDiscovery",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("StartDiscovery failed (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("StartDiscovery failed");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- is_discovering = TRUE;
- cancel_by_user = FALSE;
- /* discovery status will be change in event */
- g_variant_unref(result);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_start_custom_discovery(bt_discovery_role_type_t role)
-{
- GDBusProxy *proxy;
- GVariant *result;
- GError *error = NULL;
- const gchar *disc_type;
-
- if (_bt_is_discovering() == TRUE) {
- BT_ERR("BT is already in discovering");
- return BLUETOOTH_ERROR_IN_PROGRESS;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- if (role == DISCOVERY_ROLE_BREDR)
- disc_type = "BREDR";
- else if (role == DISCOVERY_ROLE_LE)
- disc_type = "LE";
- else if (role == DISCOVERY_ROLE_LE_BREDR)
- disc_type = "LE_BREDR";
- else
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- result = g_dbus_proxy_call_sync(proxy,
- "StartCustomDiscovery",
- g_variant_new("s", disc_type),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("StartCustomDiscovery failed (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("StartCustomDiscovery failed");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- is_discovering = TRUE;
- cancel_by_user = FALSE;
- /* discovery status will be change in event */
- g_variant_unref(result);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_cancel_discovery(void)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *result;
-
- if (_bt_is_discovering() == FALSE) {
- BT_ERR("BT is not in discovering");
- return BLUETOOTH_ERROR_NOT_IN_OPERATION;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "StopDiscovery",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- int ret = BLUETOOTH_ERROR_INTERNAL;
- if (error != NULL) {
- BT_ERR("StopDiscovery failed (Error: %s)", error->message);
-
- if (g_strrstr(error->message, "No discovery started"))
- ret = BLUETOOTH_ERROR_NOT_IN_OPERATION;
-
- g_clear_error(&error);
- } else {
- BT_ERR("StopDiscovery failed");
- }
-
- return ret;
- }
-
- cancel_by_user = TRUE;
- /* discovery status will be change in event */
- g_variant_unref(result);
- return BLUETOOTH_ERROR_NONE;
-}
-
-gboolean _bt_is_discovering(void)
-{
- return is_discovering;
-}
-
-gboolean _bt_is_connectable(void)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- gboolean is_connectable = FALSE;
- GVariant *result;
- GVariant *temp;
-
- proxy = _bt_get_adapter_properties_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "Get",
- g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
- "Connectable"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to get connectable property (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to get connectable property");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(result, "(v)", &temp);
- is_connectable = g_variant_get_boolean(temp);
- BT_DBG("discoverable_v:%d", is_connectable);
-
- g_variant_unref(result);
- g_variant_unref(temp);
-
- BT_INFO("Get connectable [%d]", is_connectable);
- return is_connectable;
-}
-
-int _bt_set_connectable(gboolean is_connectable)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *result;
-
- if (__bt_is_factory_test_mode()) {
- BT_ERR("Unable to set connectable in factory binary !!");
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- proxy = _bt_get_adapter_properties_proxy();
-
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "Set",
- g_variant_new("(ssv)", BT_ADAPTER_INTERFACE, "Connectable",
- g_variant_new("b", is_connectable)),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to set connectable property (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to set connectable property");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- BT_INFO_C("### Set connectable [%d]", is_connectable);
- g_variant_unref(result);
- return BLUETOOTH_ERROR_NONE;
-}
-
-gboolean _bt_get_discovering_property(bt_discovery_role_type_t discovery_type)
-{
- GDBusProxy *proxy;
- gboolean discovering_v;
- GError *error = NULL;
- char *discovering_type = NULL;
- GVariant *result;
- GVariant *temp;
-
- proxy = _bt_get_adapter_properties_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- if (discovery_type == DISCOVERY_ROLE_BREDR)
- discovering_type = "Discovering";
- else if (discovery_type == DISCOVERY_ROLE_LE)
- discovering_type = "LEDiscovering";
-
- result = g_dbus_proxy_call_sync(proxy,
- "Get",
- g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
- discovering_type),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to get discovering property (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to get discovering property");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(result, "(v)", &temp);
- discovering_v = g_variant_get_boolean(temp);
- BT_DBG("discoverable_v:%d", discovering_v);
-
- g_variant_unref(result);
- g_variant_unref(temp);
-
- return discovering_v;
-}
-
-unsigned int _bt_get_discoverable_timeout_property(void)
-{
- GDBusProxy *proxy;
- unsigned int timeout_v;
- GError *error = NULL;
- GVariant *result;
- GVariant *temp;
-
- proxy = _bt_get_adapter_properties_proxy();
- retv_if(proxy == NULL, 0);
-
- result = g_dbus_proxy_call_sync(proxy,
- "Get",
- g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
- "DiscoverableTimeout"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- BT_ERR("Fail to get discoverable timeout");
- if (error != NULL) {
- BT_ERR("Fail to get discoverable timeout (Error: %s)", error->message);
- g_clear_error(&error);
- }
- return 0;
- }
-
- g_variant_get(result, "(v)", &temp);
- timeout_v = g_variant_get_uint32(temp);
- BT_DBG("discoverable_v:%d", timeout_v);
-
- g_variant_unref(result);
- g_variant_unref(temp);
-
- return timeout_v;
-}
-
-static bluetooth_device_info_t *__bt_parse_device_info(GVariantIter *item_iter)
-{
- bluetooth_device_info_t *dev_info;
- GVariant *value;
- const gchar *key;
- GByteArray *manufacturer_data = NULL;
- guint8 char_value;
- GVariantIter *char_value_iter;
-
- dev_info = g_malloc0(sizeof(bluetooth_device_info_t));
-
- while (g_variant_iter_loop(item_iter, "{sv}", &key, &value)) {
-
- if (key == NULL)
- continue;
-
- if (!g_strcmp0(key, "Address")) {
- const char *address = NULL;
- address = g_variant_get_string(value, NULL);
- _bt_convert_addr_string_to_type(dev_info->device_address.addr,
- address);
- } else if (!g_strcmp0(key, "Class")) {
- unsigned int cod;
- cod = g_variant_get_uint32(value);
- _bt_divide_device_class(&dev_info->device_class, cod);
- } else if (!g_strcmp0(key, "Name")) {
- const char *name = NULL;
- name = g_variant_get_string(value, NULL);
- /* If there is no Alias */
- if (strlen(dev_info->device_name.name) == 0) {
- g_strlcpy(dev_info->device_name.name, name,
- BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
- }
- } else if (!g_strcmp0(key, "Alias")) {
- const char *alias = NULL;
- alias = g_variant_get_string(value, NULL);
- /* Overwrite the name */
- if (alias) {
- memset(dev_info->device_name.name, 0x00,
- BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
- g_strlcpy(dev_info->device_name.name, alias,
- BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
- }
- } else if (!g_strcmp0(key, "IsAliasSet")) {
- dev_info->is_alias_set = g_variant_get_boolean(value);
- } else if (!g_strcmp0(key, "Connected")) {
- dev_info->connected = g_variant_get_byte(value);
- } else if (!g_strcmp0(key, "Paired")) {
- dev_info->paired = g_variant_get_boolean(value);
- } else if (!g_strcmp0(key, "Trusted")) {
- dev_info->trust = g_variant_get_boolean(value);
- } else if (!g_strcmp0(key, "RSSI")) {
- dev_info->rssi = g_variant_get_int16(value);
- } else if (!g_strcmp0(key, "UUIDs")) {
- GVariantIter *iter;
- gchar *uuid = NULL;
- char **parts;
- int i = 0;
-
- dev_info->service_index = 0;
- g_variant_get(value, "as", &iter);
- while (g_variant_iter_loop(iter, "s", &uuid)) {
- g_strlcpy(dev_info->uuids[i], uuid, BLUETOOTH_UUID_STRING_MAX);
- parts = g_strsplit(uuid, "-", -1);
-
- if (parts == NULL || parts[0] == NULL) {
- g_free(uuid);
- break;
- }
-
- dev_info->service_list_array[i] = g_ascii_strtoull(parts[0], NULL, 16);
- g_strfreev(parts);
-
- i++;
- }
- dev_info->service_index = i;
- g_variant_iter_free(iter);
- } else if (strcasecmp(key, "LegacyManufacturerDataLen") == 0) {
- dev_info->manufacturer_data.data_len = g_variant_get_uint16(value);
- } else if (strcasecmp(key, "LegacyManufacturerData") == 0) {
- manufacturer_data = g_byte_array_new();
- g_variant_get(value, "ay", &char_value_iter);
- while (g_variant_iter_loop(char_value_iter, "y", &char_value))
- g_byte_array_append(manufacturer_data, &char_value, 1);
-
- if (manufacturer_data) {
- if (manufacturer_data->len > 0)
- memcpy(dev_info->manufacturer_data.data, manufacturer_data->data, manufacturer_data->len);
- }
- g_variant_iter_free(char_value_iter);
- g_byte_array_free(manufacturer_data, TRUE);
- }
- }
-
- return dev_info;
-}
-
-static void __bt_extract_device_info(GVariantIter *iter,
- GArray **dev_list)
-{
- bluetooth_device_info_t *dev_info = NULL;
- char *object_path = NULL;
- GVariantIter *interface_iter;
- GVariantIter *svc_iter;
- char *interface_str = NULL;
-
- /* Parse the signature: oa{sa{sv}}} */
- while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
- &interface_iter)) {
-
- if (object_path == NULL)
- continue;
-
- while (g_variant_iter_loop(interface_iter, "{sa{sv}}",
- &interface_str, &svc_iter)) {
- if (g_strcmp0(interface_str, "org.bluez.Device1") == 0) {
- BT_DBG("Found a device: %s", object_path);
- dev_info = __bt_parse_device_info(svc_iter);
- if (dev_info) {
- if (dev_info->paired == TRUE) {
- g_array_append_vals(*dev_list, dev_info,
- sizeof(bluetooth_device_info_t));
- }
- g_free(dev_info);
- }
- g_free(interface_str);
- g_variant_iter_free(svc_iter);
- break;
- }
- }
- }
- BT_DBG("-");
-}
-
-int _bt_get_bonded_devices(GArray **dev_list)
-{
- BT_DBG("+");
- GDBusConnection *conn;
- GDBusProxy *manager_proxy;
- GVariant *result = NULL;
- GVariantIter *iter = NULL;
- GError *error = NULL;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- manager_proxy = _bt_get_manager_proxy();
- retv_if(manager_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- NULL);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to GetManagedObjects (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to Failed to GetManagedObjects");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- /* signature of GetManagedObjects: a{oa{sa{sv}}} */
- g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
-
- __bt_extract_device_info(iter, dev_list);
- g_variant_iter_free(iter);
- g_variant_unref(result);
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_get_profile_connected_devices(char *profile_uuid, GArray **addr_list)
-{
- BT_DBG("+");
- GDBusConnection *conn;
- GDBusProxy *manager_proxy;
- GVariant *result = NULL;
- GVariant *result1 = NULL;
- GVariantIter *iter = NULL;
- GError *error = NULL;
- char *object_path = NULL;
- GVariantIter *interface_iter;
- char *interface_str = NULL;
- GDBusProxy *device_proxy = NULL;
- gboolean is_connected = FALSE;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- manager_proxy = _bt_get_manager_proxy();
- retv_if(manager_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- NULL);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to GetManagedObjects (Error: %s)", error->message);
- g_clear_error(&error);
- error = NULL;
- } else
- BT_ERR("Failed to Failed to GetManagedObjects");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- /* signature of GetManagedObjects: a{oa{sa{sv}}} */
- g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
-
- /* Parse the signature: oa{sa{sv}}} */
- while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_iter)) {
- if (object_path == NULL)
- continue;
-
- while (g_variant_iter_loop(interface_iter, "{sa{sv}}",
- &interface_str, NULL)) {
- if (g_strcmp0(interface_str, "org.bluez.Device1") == 0) {
- BT_DBG("Found a device: %s", object_path);
- g_free(interface_str);
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- object_path, BT_DEVICE_INTERFACE, NULL, NULL);
-
- if (device_proxy == NULL) {
- BT_DBG("Device don't have this service");
- break;
- }
-
- result1 = g_dbus_proxy_call_sync(device_proxy, "IsConnectedProfile",
- g_variant_new("(s)", profile_uuid),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (result1 == NULL) {
- BT_ERR("Error occured in Proxy call");
- if (error) {
- BT_ERR("Error occured in Proxy call [%s]\n", error->message);
- g_error_free(error);
- error = NULL;
- }
- g_object_unref(device_proxy);
- break;
- }
- g_variant_get(result1, "(b)", &is_connected);
-
- if (is_connected == TRUE) {
- char address[BT_ADDRESS_STRING_SIZE];
- bluetooth_device_address_t *addr = NULL;
-
- _bt_convert_device_path_to_address(object_path, address);
-
- addr = g_malloc0(sizeof(bluetooth_device_address_t));
- _bt_convert_addr_string_to_type(addr->addr, address);
-
- g_array_append_vals(*addr_list, addr,
- sizeof(bluetooth_device_address_t));
- }
-
- g_variant_unref(result1);
- g_object_unref(device_proxy);
-
- break;
- }
- }
- }
-
- g_variant_unref(result);
- g_variant_iter_free(iter);
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_get_bonded_device_info(bluetooth_device_address_t *device_address,
- bluetooth_device_info_t *dev_info)
-{
- char *object_path = NULL;
- GDBusProxy *adapter_proxy;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- int ret = BLUETOOTH_ERROR_NONE;
-
- BT_CHECK_PARAMETER(device_address, return);
- BT_CHECK_PARAMETER(dev_info, return);
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- object_path = _bt_get_device_object_path(address);
-
- retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
-
- ret = __bt_get_bonded_device_info(object_path, dev_info);
- g_free(object_path);
-
- return ret;
-}
-
-int _bt_is_alias_set(bluetooth_device_address_t *device_address, gboolean *is_alias_set)
-{
- char *object_path = NULL;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- gboolean alias_set = FALSE;
-
- GDBusConnection *conn;
- GDBusProxy *device_proxy;
- GError *error = NULL;
- GVariant *result = NULL;
- GVariant *temp = NULL;
-
-
- BT_CHECK_PARAMETER(device_address, return);
- BT_CHECK_PARAMETER(is_alias_set, return);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- object_path = _bt_get_device_object_path(address);
- retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
-
- conn = _bt_gdbus_get_system_gconn();
- if (conn == NULL) {
- g_free(object_path);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- BT_BLUEZ_NAME,
- object_path,
- BT_PROPERTIES_INTERFACE,
- NULL, NULL);
- if (device_proxy == NULL) {
- g_free(object_path);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- result = g_dbus_proxy_call_sync(device_proxy, "Get",
- g_variant_new("(ss)", BT_DEVICE_INTERFACE, "IsAliasSet"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- BT_ERR("Error occured in Proxy call");
- if (error != NULL) {
- BT_ERR("Getting is_alias_set property failed: [%s]\n", error->message);
- g_error_free(error);
- }
- g_object_unref(device_proxy);
- g_free(object_path);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(result, "(v)", &temp);
- alias_set = g_variant_get_boolean(temp);
- *is_alias_set = alias_set;
- BT_DBG("address: [%s] | *is_alias_set: %s", address, *is_alias_set ? "TRUE" : "FALSE");
- g_variant_unref(temp);
- g_variant_unref(result);
- g_object_unref(device_proxy);
-
- g_free(object_path);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_get_timeout_value(int *timeout)
-{
- time_t current_time;
- int time_diff;
-
- /* Take current time */
- time(¤t_time);
- time_diff = difftime(current_time, visible_timer.start_time);
-
- BT_DBG("Time diff = %d\n", time_diff);
-
- *timeout = visible_timer.timeout - time_diff;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_set_le_privacy(gboolean set_privacy)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *result = NULL;
-
- if (__bt_is_factory_test_mode()) {
- BT_ERR("Unable to set le privacy in factory binary !!");
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- if (_bt_adapter_get_status() != BT_ACTIVATED &&
- _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "SetLePrivacy",
- g_variant_new("(b)", set_privacy),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to SetLePrivacy (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to SetLePrivacy");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_unref(result);
- BT_INFO("SetLePrivacy as %d", set_privacy);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_set_le_static_random_address(gboolean is_enable)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- GVariant *result = NULL;
-
- if (__bt_is_factory_test_mode()) {
- BT_ERR("Unable to set le random address in factory binary !!");
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- if (_bt_adapter_get_status() != BT_ACTIVATED &&
- _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy,
- "SetLeStaticRandomAddress",
- g_variant_new("(b)", is_enable),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to SetLeStaticRandomAddress (Error: %s)", error->message);
- g_clear_error(&error);
- } else
- BT_ERR("Failed to SetLeStaticRandomAddress");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_unref(result);
- BT_INFO("SetLeStaticRandomAddress as %d", is_enable);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_set_manufacturer_data(bluetooth_manufacturer_data_t *m_data)
-{
- GDBusProxy *proxy;
- GError *error = NULL;
- int i;
- GVariant *val;
- GVariant *result;
- GVariantBuilder *builder;
-
- BT_CHECK_PARAMETER(m_data, return);
-
- if (_bt_adapter_get_status() != BT_ACTIVATED &&
- _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
-
- for (i = 0; i < (m_data->data_len) + 2; i++)
- g_variant_builder_add(builder, "y", m_data->data[i]);
-
- val = g_variant_new("(ay)", builder);
-
- result = g_dbus_proxy_call_sync(proxy,
- "SetManufacturerData",
- val,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- g_variant_builder_unref(builder);
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to SetManufacturerData (Error: %s)", error->message);
- g_clear_error(&error);
- } else {
- BT_ERR("Failed to SetManufacturerData");
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
- builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
-
- for (i = 0; i < (m_data->data_len) + 2; i++)
- g_variant_builder_add(builder, "y", m_data->data[i]);
-
- val = g_variant_new("(ay)", builder);
-
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED,
- val);
-
- BT_INFO("Set manufacturer data");
-
- g_variant_builder_unref(builder);
- g_variant_unref(result);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-
-int _bt_service_set_alarm(int timeout, bt_set_alarm_cb call_back, void *user_data, alarm_id_t *alarm_id)
-{
- int result = BLUETOOTH_ERROR_NONE;
- bt_service_alarm_t *alarm = NULL;
-
- if (!call_back || !alarm_id)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- if (!alarm_mgr.is_alarm_initialized) {
- result = alarmmgr_init("bt-service");
- if (result != 0) {
- BT_ERR("Failed to initialize alarm = %d", result);
- result = BLUETOOTH_ERROR_INTERNAL;
- goto finish;
- }
- result = alarmmgr_set_cb(alarm_cb, NULL);
- if (result != 0) {
- BT_ERR("Failed to set the callback = %d", result);
- result = BLUETOOTH_ERROR_INTERNAL;
- goto finish;
- }
- alarm_mgr.is_alarm_initialized = TRUE;
- }
-
- alarm = g_malloc0(sizeof(bt_service_alarm_t));
- if (!alarm)
- return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
-
- result = alarmmgr_add_alarm(ALARM_TYPE_VOLATILE, timeout,
- 0, NULL, alarm_id);
- if (result != 0) {
- BT_ERR("Failed to create alarm error = %d", result);
- result = BLUETOOTH_ERROR_INTERNAL;
- g_free(alarm);
- goto finish;
- }
- alarm->alarm_id = *alarm_id;
- alarm->callback = call_back;
- alarm->user_data = user_data;
-
- alarm_mgr.g_alarm_list = g_list_append(alarm_mgr.g_alarm_list, alarm);
- result = BLUETOOTH_ERROR_NONE;
-finish:
- return result;
-}
-
-static int alarm_cb(alarm_id_t alarm_id, void* user_param)
-{
- GList *node = NULL;
- bt_service_alarm_t *p_data;
- bt_set_alarm_cb callback = NULL;
- void *user_data = NULL;
-
- node = g_list_find_custom(alarm_mgr.g_alarm_list,
- GINT_TO_POINTER(alarm_id), compare_alarm);
- if (!node)
- return 0;
-
- p_data = (bt_service_alarm_t *)node->data;
- alarm_mgr.g_alarm_list = g_list_delete_link(alarm_mgr.g_alarm_list,
- node);
-
- if (!p_data)
- return 0;
-
- callback = p_data->callback;
- user_data = p_data->user_data;
- g_free(p_data);
-
- if (callback)
- callback(alarm_id, user_data);
-
- return 0;
-}
-
-int _bt_service_remove_alarm(alarm_id_t alarm_id)
-{
- GList *list = NULL;
- bt_service_alarm_t *p_data;
- list = g_list_find_custom(alarm_mgr.g_alarm_list, GINT_TO_POINTER(alarm_id), compare_alarm);
-
- if (list != NULL) {
- alarmmgr_remove_alarm(alarm_id);
- p_data = (bt_service_alarm_t *)list->data;
- alarm_mgr.g_alarm_list = g_list_remove(alarm_mgr.g_alarm_list, list->data);
- g_free(p_data);
- }
-
- return 0;
-}
-
-gint compare_alarm(gconstpointer list_data, gconstpointer data)
-{
- alarm_id_t alarm_id = (alarm_id_t)data;
- bt_service_alarm_t *p_data = (bt_service_alarm_t *)list_data;
-
- if (p_data->alarm_id == alarm_id)
- return 0;
-
- return 1;
-}
-
-static void alarm_data_free(void *data)
-{
- bt_service_alarm_t *p_data = (bt_service_alarm_t *)data;
- g_free(p_data);
- return;
-}
-
-static gboolean _bt_adapter_request_delayed_cb(gpointer user_data)
-{
- int result;
- int function = (int)user_data;
-
- switch (function) {
- case BT_ENABLE_ADAPTER:
- result = _bt_enable_adapter();
- if (result != BLUETOOTH_ERROR_NONE) {
- BT_ERR("_bt_enable_adapter is failed");
- /* Send enabled event to API */
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_ENABLED,
- g_variant_new("(i)", result));
- }
- break;
- case BT_DISABLE_ADAPTER:
- result = _bt_disable_adapter();
- if (result != BLUETOOTH_ERROR_NONE) {
- BT_ERR("_bt_disable_adapter is failed");
- /* Send disabled event to API */
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
- g_variant_new("(i)", result));
- }
- break;
- default:
- BT_ERR("function is NOT matched");
- break;
- }
-
- return FALSE;
-}
-
-int _bt_adapter_request_delayed(int function)
-{
- int ret;
-
- switch (function) {
- case BT_ENABLE_ADAPTER:
- ret = _bt_enable_adapter_check_status();
- if (ret == BLUETOOTH_ERROR_NONE)
- _bt_adapter_set_status(BT_ACTIVATING);
- else
- return ret;
-
- break;
- case BT_DISABLE_ADAPTER:
- ret = _bt_disable_adapter_check_status();
- if (ret == BLUETOOTH_ERROR_NONE)
- _bt_adapter_set_status(BT_DEACTIVATING);
- else
- return ret;
-
- break;
- default:
- BT_ERR("function is NOT matched");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_idle_add((GSourceFunc)_bt_adapter_request_delayed_cb, (void*)function);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-
-int _bt_get_enable_timer_id(void)
-{
- return timer_id;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <malloc.h>
-#include <stacktrim.h>
-#include <syspopup_caller.h>
-#include <vconf.h>
-#include <bundle_internal.h>
-
-#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
-#include <tethering.h>
-#endif
-
-#include "bt-internal-types.h"
-#include "bt-service-common.h"
-#include "bt-service-agent.h"
-#include "bt-service-gap-agent.h"
-#include "bt-service-adapter.h"
-#include "bt-service-event.h"
-#include "bt-service-rfcomm-server.h"
-#include "bt-service-device.h"
-#include "bt-service-audio.h"
-
-#ifdef TIZEN_DPM_ENABLE
-#include "bt-service-dpm.h"
-#endif
-
-#define BT_APP_AUTHENTICATION_TIMEOUT 35
-#define BT_APP_AUTHORIZATION_TIMEOUT 15
-
-#define HFP_AUDIO_GATEWAY_UUID "0000111f-0000-1000-8000-00805f9b34fb"
-#define HSP_AUDIO_GATEWAY_UUID "00001112-0000-1000-8000-00805f9b34fb"
-#define A2DP_UUID "0000110D-0000-1000-8000-00805F9B34FB"
-#define AVRCP_TARGET_UUID "0000110c-0000-1000-8000-00805f9b34fb"
-#define OPP_UUID "00001105-0000-1000-8000-00805f9b34fb"
-#define FTP_UUID "00001106-0000-1000-8000-00805f9b34fb"
-#define SPP_UUID "00001101-0000-1000-8000-00805f9b34fb"
-#define PBAP_UUID "0000112f-0000-1000-8000-00805f9b34fb"
-#define MAP_UUID "00001132-0000-1000-8000-00805f9b34fb"
-#define NAP_UUID "00001116-0000-1000-8000-00805f9b34fb"
-#define GN_UUID "00001117-0000-1000-8000-00805f9b34fb"
-#define BNEP_UUID "0000000f-0000-1000-8000-00805f9b34fb"
-#define HID_UUID "00001124-0000-1000-8000-00805f9b34fb"
-#define HID_DEVICE_UUID "00001124-0000-1000-8000-00805f9b43bf"
-#define SAP_UUID_OLD "a49eb41e-cb06-495c-9f4f-bb80a90cdf00"
-#define SAP_UUID_NEW "a49eb41e-cb06-495c-9f4f-aa80a90cdf4a"
-#define IOTIVITY_UUID "12341234-1C25-481F-9DFB-59193D238280"
-
-#define BT_AGENT_OBJECT "/org/bluez/agent/frwk_agent"
-
-#define BT_AGENT_INTERFACE "org.bluez.Agent1"
-
-#define BT_AGENT_SIGNAL_RFCOMM_AUTHORIZE "RfcommAuthorize"
-#define BT_AGENT_SIGNAL_OBEX_AUTHORIZE "ObexAuthorize"
-
-#define BT_PASSKEY_MAX_LENGTH 4
-
-#define BT_AGENT_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS 200
-#define BT_AGENT_SYSPOPUP_MAX_ATTEMPT 3
-#define BT_PAN_MAX_CONNECTION 4
-
-extern guint nap_connected_device_count;
-
-static char *passkey_watcher = NULL;
-
-#define G_VARIANT_UNREF(variant) \
- g_variant_unref(variant); \
- variant = NULL
-
-static int __bt_agent_is_auto_response(uint32_t dev_class, const gchar *address,
- const gchar *name);
-static gboolean __bt_agent_is_hid_keyboard(uint32_t dev_class);
-static int __bt_agent_generate_passkey(char *passkey, int size);
-
-static void __bt_agent_release_memory(void)
-{
- /* Release Malloc Memory*/
- malloc_trim(0);
-
- /* Release Stack Memory*/
- stack_trim();
-}
-static gboolean __bt_agent_system_popup_timer_cb(gpointer user_data)
-{
- int ret;
- static int retry_count;
- bundle *b = (bundle *)user_data;
- retv_if(user_data == NULL, FALSE);
-
- ++retry_count;
-
- ret = syspopup_launch("bt-syspopup", b);
- if (ret < 0) {
- BT_ERR("Sorry! Can't launch popup, ret=%d, Re-try[%d] time..",
- ret, retry_count);
- if (retry_count >= BT_AGENT_SYSPOPUP_MAX_ATTEMPT) {
- BT_ERR("Sorry!! Max retry %d reached", retry_count);
- bundle_free(b);
- retry_count = 0;
- return FALSE;
- }
- } else {
- BT_DBG("Hurray!! Finally Popup launched");
- retry_count = 0;
- bundle_free(b);
- }
-
- return (ret < 0) ? TRUE : FALSE;
-}
-
-int _bt_launch_system_popup(bt_agent_event_type_t event_type,
- const char *device_name,
- const unsigned char *auth_info,
- char *passkey,
- const char *filename,
- const char *agent_path)
-{
- int ret;
- bundle *b;
- char event_str[BT_MAX_EVENT_STR_LENGTH + 1];
-
- b = bundle_create();
- if (!b) {
- BT_ERR("Launching system popup failed");
- return -1;
- }
-
- bundle_add(b, "device-name", device_name);
- bundle_add(b, "auth-info", (const char *)auth_info);
- bundle_add(b, "passkey", passkey);
- bundle_add(b, "file", filename);
- bundle_add(b, "agent-path", agent_path);
-
- switch (event_type) {
- case BT_AGENT_EVENT_PIN_REQUEST:
- g_strlcpy(event_str, "pin-request", sizeof(event_str));
- break;
-
- case BT_AGENT_EVENT_PASSKEY_CONFIRM_REQUEST:
- g_strlcpy(event_str, "passkey-confirm-request",
- sizeof(event_str));
- break;
-
- case BT_AGENT_EVENT_PASSKEY_REQUEST:
- g_strlcpy(event_str, "passkey-request", sizeof(event_str));
- break;
-
- case BT_AGENT_EVENT_PASSKEY_DISPLAY_REQUEST:
- g_strlcpy(event_str, "passkey-display-request",
- sizeof(event_str));
- break;
-
- case BT_AGENT_EVENT_AUTHORIZE_REQUEST:
- g_strlcpy(event_str, "authorize-request",
- sizeof(event_str));
- break;
-
- case BT_AGENT_EVENT_CONFIRM_MODE_REQUEST:
- g_strlcpy(event_str, "confirm-mode-request",
- sizeof(event_str));
- break;
-
- case BT_AGENT_EVENT_FILE_RECEIVED:
- g_strlcpy(event_str, "file-received", sizeof(event_str));
- break;
-
- case BT_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST:
- g_strlcpy(event_str, "keyboard-passkey-request",
- sizeof(event_str));
- break;
-
- case BT_AGENT_EVENT_TERMINATE:
- g_strlcpy(event_str, "terminate", sizeof(event_str));
- break;
-
- case BT_AGENT_EVENT_EXCHANGE_REQUEST:
- g_strlcpy(event_str, "exchange-request", sizeof(event_str));
- break;
-
- case BT_AGENT_EVENT_PBAP_REQUEST:
- g_strlcpy(event_str, "phonebook-request", sizeof(event_str));
- break;
-
- case BT_AGENT_EVENT_MAP_REQUEST:
- g_strlcpy(event_str, "message-request", sizeof(event_str));
- break;
-
- case BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE:
- g_strlcpy(event_str, "remote-legacy-pair-failed", sizeof(event_str));
- break;
-
- default:
- BT_ERR("Invalid event type");
- bundle_free(b);
- return -1;
-
- }
-
- bundle_add(b, "event-type", event_str);
-
- ret = syspopup_launch("bt-syspopup", b);
- if (0 > ret) {
- BT_ERR("Popup launch failed...retry %d", ret);
-
- g_timeout_add(BT_AGENT_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS,
- (GSourceFunc)__bt_agent_system_popup_timer_cb, b);
- } else {
- bundle_free(b);
- }
-
- BT_INFO("_bt_agent_launch_system_popup");
- return 0;
-}
-
-static GVariant *__bt_service_getall(GDBusProxy *device, const char *interface)
-{
- GError *error = NULL;
- GVariant *reply;
-
- reply = g_dbus_proxy_call_sync(device,
- "GetAll", g_variant_new("(s)", interface),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
- if (reply == NULL) {
- ERR("GetAll dBUS-RPC failed");
- if (error) {
- ERR("D-Bus API failure: errCode[%x], message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- return NULL;
- }
-
- return reply;
-}
-
-static gboolean __pincode_request(GapAgentPrivate *agent, GDBusProxy *device)
-{
- uint32_t device_class;
- gchar *address = NULL;
- unsigned char auth_info[5] = {0, };
- gchar *name = NULL;
- GVariant *reply = NULL;
- GVariant *reply_temp = NULL;
- GVariant *tmp_value;
- char pin_code[BLUETOOTH_PIN_CODE_MAX_LENGTH + 1];
-
- BT_DBG("+");
-
-#ifdef TIZEN_DPM_ENABLE
- if (_bt_dpm_get_bluetooth_pairing_state() == DPM_RESTRICTED) {
- BT_ERR("Not allow to pair the device");
- gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL);
- __bt_agent_release_memory();
- return TRUE;
- }
-#endif
-
- reply_temp = __bt_service_getall(device, BT_DEVICE_INTERFACE);
-
- if (reply_temp == NULL) {
- gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "",
- NULL);
- goto done;
- }
-
- g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
-
- tmp_value = g_variant_lookup_value(reply, "Class", G_VARIANT_TYPE_UINT32);
- g_variant_get(tmp_value, "u", &device_class);
- G_VARIANT_UNREF(tmp_value);
-
- tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
- g_variant_get(tmp_value, "s", &address);
- G_VARIANT_UNREF(tmp_value);
- if (!address) {
- gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "", NULL);
- goto done;
- }
-
- tmp_value = g_variant_lookup_value(reply, "Name", G_VARIANT_TYPE_STRING);
- g_variant_get(tmp_value, "s", &name);
- G_VARIANT_UNREF(tmp_value);
- if (!name) {
- BT_DBG("Replacing the name with address");
- name = g_strdup(address);
- } else {
- BT_INFO("Name = %s, Address = %s, Class = 0x%x", name, address, device_class);
- if (name[0] == '\0') {
- g_free(name);
- BT_DBG("Name[0]=NULL, Replacing the name with address");
- name = g_strdup(address);
- }
- }
-
- __bt_get_auth_info(reply, (char *)auth_info);
- if (_bt_is_device_creating() == TRUE &&
- _bt_is_bonding_device_address(address) == TRUE &&
- __bt_agent_is_auto_response(device_class, address, name)) {
- BT_DBG("0000 Auto Pair");
- /* Use Fixed PIN "0000" for basic pairing */
- _bt_set_autopair_status_in_bonding_info(TRUE);
- gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, "0000",
- NULL);
- } else if (__bt_agent_is_hid_keyboard(device_class)) {
- BT_DBG("HID Keyboard");
- char str_passkey[BT_PASSKEY_MAX_LENGTH + 1] = { 0 };
-
- if (__bt_agent_generate_passkey(str_passkey,
- BT_PASSKEY_MAX_LENGTH) != 0) {
- gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT,
- "", NULL);
- goto done;
- }
-
- gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT,
- str_passkey, NULL);
-
- _bt_launch_system_popup(BT_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST,
- name, auth_info, str_passkey, NULL,
- _gap_agent_get_path(agent));
- } else if (_bt_get_device_pin_code(address, pin_code)
- == BLUETOOTH_ERROR_NONE) {
- BT_DBG("Use stored PIN code(%s)", pin_code);
- gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, pin_code,
- NULL);
- goto done;
- } else {
- BT_DBG("Show Pin entry");
- _bt_launch_system_popup(BT_AGENT_EVENT_PIN_REQUEST, name, auth_info,
- NULL, NULL, _gap_agent_get_path(agent));
- }
-
-done:
- g_variant_unref(reply);
- g_variant_unref(reply_temp);
- g_free(address);
- g_free(name);
- __bt_agent_release_memory();
- BT_DBG("-");
-
- return TRUE;
-}
-
-static gboolean __passkey_request(GapAgentPrivate *agent, GDBusProxy *device)
-{
- gchar *address = NULL;
- gchar *name = NULL;
- unsigned char auth_info[5] = {0, };
- GVariant *reply = NULL;
- GVariant *reply_temp = NULL;
- GVariant *tmp_value;
- BT_DBG("+");
-
-#ifdef TIZEN_DPM_ENABLE
- if (_bt_dpm_get_bluetooth_pairing_state() == DPM_RESTRICTED) {
- BT_ERR("Not allow to pair the device");
- gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL);
- __bt_agent_release_memory();
- return TRUE;
- }
-#endif
-
- reply_temp = __bt_service_getall(device, BT_DEVICE_INTERFACE);
-
- if (reply_temp == NULL) {
- gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "",
- NULL);
- goto done;
- }
-
- g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
-
- tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
- g_variant_get(tmp_value, "s", &address);
- G_VARIANT_UNREF(tmp_value);
- if (!address) {
- gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "", NULL);
- goto done;
- }
-
- tmp_value = g_variant_lookup_value(reply, "Name", G_VARIANT_TYPE_STRING);
- g_variant_get(tmp_value, "s", &name);
- G_VARIANT_UNREF(tmp_value);
- if (!name)
- name = g_strdup(address);
-
- __bt_get_auth_info(reply, (char *)auth_info);
-
- _bt_launch_system_popup(BT_AGENT_EVENT_PASSKEY_REQUEST, name, auth_info,
- NULL, NULL, _gap_agent_get_path(agent));
-
-done:
- g_variant_unref(reply);
- g_variant_unref(reply_temp);
- g_free(address);
- g_free(name);
- __bt_agent_release_memory();
-
- BT_DBG("-");
- return TRUE;
-}
-
-static gboolean __display_request(GapAgentPrivate *agent, GDBusProxy *device,
- guint passkey)
-{
- gchar *address = NULL;
- gchar *name = NULL;
- unsigned char auth_info[5] = {0, };
- char *str_passkey;
- GVariant *reply = NULL;
- GVariant *reply_temp = NULL;
- GVariant *tmp_value = NULL;
-
- BT_DBG("+");
-
- reply_temp = __bt_service_getall(device, BT_DEVICE_INTERFACE);
- if (reply_temp == NULL) {
- gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "",
- NULL);
- goto done;
- }
-
- g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
-
- tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
- g_variant_get(tmp_value, "s", &address);
- G_VARIANT_UNREF(tmp_value);
- if (!address) {
- gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "", NULL);
- goto done;
- }
-
- tmp_value = g_variant_lookup_value(reply, "Name", G_VARIANT_TYPE_STRING);
- g_variant_get(tmp_value, "s", &name);
- G_VARIANT_UNREF(tmp_value);
- if (!name)
- name = g_strdup(address);
-
- __bt_get_auth_info(reply, (char *)auth_info);
-
- str_passkey = g_strdup_printf("%06d", passkey);
-
- if (passkey_watcher) {
- GVariant *param = NULL;
-
- BT_INFO("Send passkey to %s", passkey_watcher);
-
- param = g_variant_new("(ss)", address, str_passkey);
-
- _bt_send_event_to_dest(passkey_watcher, BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_PASSKEY_NOTIFICATION, param);
- } else {
- _bt_launch_system_popup(BT_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST, name,
- auth_info, str_passkey, NULL,
- _gap_agent_get_path(agent));
- }
-
- g_free(str_passkey);
-
-done:
- g_variant_unref(reply);
- g_variant_unref(reply_temp);
- g_free(address);
- g_free(name);
- __bt_agent_release_memory();
-
- BT_DBG("-");
- return TRUE;
-}
-
-static gboolean __confirm_request(GapAgentPrivate *agent, GDBusProxy *device,
- guint passkey)
-{
- gchar *address = NULL;
- gchar *name = NULL;
- unsigned char auth_info[5] = {0, };
- char str_passkey[7];
- GVariant *reply_temp = NULL;
- GVariant *reply = NULL;
- GVariant *tmp_value;
- BT_DBG("+ passkey[%.6d]", passkey);
-
-#ifdef TIZEN_DPM_ENABLE
- if (_bt_dpm_get_bluetooth_pairing_state() == DPM_RESTRICTED) {
- BT_ERR("Not allow to pair the device");
- gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL);
- __bt_agent_release_memory();
- return TRUE;
- }
-#endif
-
- snprintf(str_passkey, sizeof(str_passkey), "%.6d", passkey);
-
- reply_temp = __bt_service_getall(device, BT_DEVICE_INTERFACE);
-
- if (reply_temp == NULL) {
- BT_ERR("Device doesn't exist");
- gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "",
- NULL);
- goto done;
- }
-
- g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
-
- tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
- g_variant_get(tmp_value, "s", &address);
- G_VARIANT_UNREF(tmp_value);
- if (!address) {
- gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "", NULL);
- goto done;
- }
-
- tmp_value = g_variant_lookup_value(reply, "Name", G_VARIANT_TYPE_STRING);
- g_variant_get(tmp_value, "s", &name);
- G_VARIANT_UNREF(tmp_value);
- if (!name)
- name = g_strdup(address);
- __bt_get_auth_info(reply, (char *)auth_info);
-
- BT_DBG("LAUNCH SYSPOPUP");
- _bt_launch_system_popup(BT_AGENT_EVENT_PASSKEY_CONFIRM_REQUEST, name,
- auth_info, str_passkey, NULL,
- _gap_agent_get_path(agent));
-
-done:
- g_variant_unref(reply);
- g_variant_unref(reply_temp);
- g_free(address);
- g_free(name);
- __bt_agent_release_memory();
- BT_DBG("-");
-
- return TRUE;
-}
-
-static gboolean __pairing_cancel_request(GapAgentPrivate *agent, const char *address)
-{
- BT_DBG("On Going Pairing is cancelled by remote\n");
-
- syspopup_destroy_all();
-
- __bt_agent_release_memory();
-
- return TRUE;
-}
-
-static gboolean __a2dp_authorize_request_check(void)
-{
- /* Check for existing Media device to disconnect */
- return _bt_is_headset_type_connected(BT_AUDIO_A2DP, NULL);
-}
-
-static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *device,
- const char *uuid)
-{
- gchar *address = NULL;
- gchar *name = NULL;
- unsigned char auth_info[5] = {0, };
- gboolean trust;
- GVariant *reply = NULL;
- GVariant *reply_temp = NULL;
- GVariant *tmp_value;
-#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
- bool enabled;
- tethering_h tethering = NULL;
-#endif
- int result = BLUETOOTH_ERROR_NONE;
- int request_type = BT_AGENT_EVENT_AUTHORIZE_REQUEST;
-
- BT_DBG("+");
-
- /* Check if already Media connection exsist */
- if (!strcasecmp(uuid, A2DP_UUID)) {
- gboolean ret = FALSE;
-
- ret = __a2dp_authorize_request_check();
-
- if (ret) {
- BT_ERR("Already one A2DP device connected \n");
- gap_agent_reply_authorize(agent, GAP_AGENT_REJECT,
- NULL);
- goto done;
- }
- }
- /* Check completed */
-
- if (!strcasecmp(uuid, HFP_AUDIO_GATEWAY_UUID) ||
- !strcasecmp(uuid, HSP_AUDIO_GATEWAY_UUID) ||
- !strcasecmp(uuid, HFP_HS_UUID) ||
- !strcasecmp(uuid, HSP_HS_UUID) ||
- !strcasecmp(uuid, A2DP_UUID) ||
- !strcasecmp(uuid, HID_UUID) ||
- !strcasecmp(uuid, HID_DEVICE_UUID) ||
- !strcasecmp(uuid, SAP_UUID_OLD) ||
- !strcasecmp(uuid, SAP_UUID_NEW) ||
- !strcasecmp(uuid, IOTIVITY_UUID) ||
- !strcasecmp(uuid, AVRCP_TARGET_UUID)) {
- BT_DBG("Auto accept authorization for audio device (HFP, A2DP, AVRCP) [%s]", uuid);
- gap_agent_reply_authorize(agent, GAP_AGENT_ACCEPT,
- NULL);
-
- goto done;
- }
-
- if (!strcasecmp(uuid, NAP_UUID) ||
- !strcasecmp(uuid, GN_UUID) ||
- !strcasecmp(uuid, BNEP_UUID)) {
-
- BT_DBG("Network connection request: %s", uuid);
-#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
- if (nap_connected_device_count >=
- BT_PAN_MAX_CONNECTION) {
- BT_ERR("Max connection exceeded");
- goto fail;
- }
- int ret;
- ret = tethering_create(&tethering);
-
- if (ret != TETHERING_ERROR_NONE) {
- BT_ERR("Fail to create tethering: %d", ret);
- goto fail;
- }
-
- enabled = tethering_is_enabled(tethering, TETHERING_TYPE_BT);
-
- ret = tethering_destroy(tethering);
-
- if (ret != TETHERING_ERROR_NONE)
- BT_ERR("Fail to create tethering: %d", ret);
-
- if (enabled != true) {
- BT_ERR("BT tethering is not enabled");
- goto fail;
- }
-#endif
-
- gap_agent_reply_authorize(agent, GAP_AGENT_ACCEPT,
- NULL);
- goto done;
-#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
-fail:
- gap_agent_reply_authorize(agent, GAP_AGENT_REJECT,
- NULL);
-
- goto done;
-#endif
- }
-
- reply_temp = __bt_service_getall(device, BT_DEVICE_INTERFACE);
- if (reply_temp == NULL) {
- gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "",
- NULL);
- goto done;
- }
-
- g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
-
- tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
- g_variant_get(tmp_value, "s", &address);
- G_VARIANT_UNREF(tmp_value);
- if (!address) {
- gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "", NULL);
- goto done;
- }
-
- tmp_value = g_variant_lookup_value(reply, "Alias", G_VARIANT_TYPE_STRING);
- g_variant_get(tmp_value, "s", &name);
- G_VARIANT_UNREF(tmp_value);
- if (!name)
- name = g_strdup(address);
-
- tmp_value = g_variant_lookup_value(reply, "Trusted", G_VARIANT_TYPE_BOOLEAN);
- g_variant_get(tmp_value, "b", &trust);
- G_VARIANT_UNREF(tmp_value);
-
- __bt_get_auth_info(reply, (char *)auth_info);
-
- BT_INFO("Authorization request for device [%s] Service:[%s]\n", address, uuid);
-
- if (strcasecmp(uuid, OPP_UUID) == 0 &&
- _gap_agent_exist_osp_server(agent, BT_OBEX_SERVER,
- NULL) == TRUE) {
- _bt_send_event(BT_OPP_SERVER_EVENT,
- BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
- g_variant_new("(iss)", result, address, name));
-
- goto done;
- }
-
- if (_gap_agent_exist_osp_server(agent, BT_RFCOMM_SERVER,
- (char *)uuid) == TRUE) {
- bt_agent_osp_server_t *osp_serv;
- osp_serv = _gap_agent_get_osp_server(agent,
- BT_RFCOMM_SERVER, (char *)uuid);
-
- if (osp_serv) {
- _bt_send_event(BT_RFCOMM_SERVER_EVENT,
- BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
- g_variant_new("(issssn)", result, address, uuid,
- name, osp_serv->path, osp_serv->fd));
- }
-
- goto done;
- }
-
- if (!strcasecmp(uuid, OPP_UUID))
- request_type = BT_AGENT_EVENT_EXCHANGE_REQUEST;
- else if (!strcasecmp(uuid, PBAP_UUID))
- request_type = BT_AGENT_EVENT_PBAP_REQUEST;
- else if (!strcasecmp(uuid, MAP_UUID))
- request_type = BT_AGENT_EVENT_MAP_REQUEST;
-
- if (trust) {
- BT_INFO("Trusted device, so authorize\n");
- gap_agent_reply_authorize(agent,
- GAP_AGENT_ACCEPT, NULL);
- } else {
- _bt_launch_system_popup(request_type, name, auth_info, NULL, NULL,
- _gap_agent_get_path(agent));
- }
-
-done:
- if (reply)
- g_variant_unref(reply);
-
- if (reply_temp)
- g_variant_unref(reply_temp);
-
- g_free(name);
- g_free(address);
- __bt_agent_release_memory();
- BT_DBG("-");
-
- return TRUE;
-}
-
-static gboolean __authorization_cancel_request(GapAgentPrivate *agent,
- const char *address)
-{
- BT_DBG("On Going Authorization is cancelled by remote\n");
-
- gap_agent_reply_authorize(agent, GAP_AGENT_CANCEL, NULL);
-
- syspopup_destroy_all();
-
- __bt_agent_release_memory();
-
- return TRUE;
-}
-
-void _bt_destroy_agent(void *agent)
-{
- if (!agent)
- return;
-
- _gap_agent_reset_dbus((GapAgentPrivate *)agent);
-
- g_free(agent);
-}
-
-void* _bt_create_agent(const char *path, gboolean adapter)
-{
- GAP_AGENT_FUNC_CB func_cb;
- GDBusProxy *adapter_proxy;
- GapAgentPrivate *agent;
-
- adapter_proxy = _bt_get_adapter_proxy();
- if (!adapter_proxy)
- return NULL;
-
- func_cb.pincode_func = __pincode_request;
- func_cb.display_func = __display_request;
- func_cb.passkey_func = __passkey_request;
- func_cb.confirm_func = __confirm_request;
- func_cb.authorize_func = __authorize_request;
- func_cb.pairing_cancel_func = __pairing_cancel_request;
- func_cb.authorization_cancel_func = __authorization_cancel_request;
-
- /* Allocate memory*/
- agent = g_new0(GapAgentPrivate, 1);
-
- _gap_agent_setup_dbus(agent, &func_cb, path, adapter_proxy);
-
- if (adapter) {
- if (!_gap_agent_register(agent)) {
- _bt_destroy_agent(agent);
- agent = NULL;
- }
- }
-
- return agent;
-}
-
-gboolean _bt_agent_register_osp_server(const gint type,
- const char *uuid, char *path, int fd)
-{
- void *agent = _bt_get_adapter_agent();
- if (!agent)
- return FALSE;
-
- return _gap_agent_register_osp_server(agent, type, uuid, path, fd);
-
-}
-
-gboolean _bt_agent_unregister_osp_server(const gint type, const char *uuid)
-{
- void *agent = _bt_get_adapter_agent();
-
- if (!agent)
- return FALSE;
-
- return _gap_agent_unregister_osp_server(agent, type, uuid);
-}
-
-gboolean _bt_agent_reply_authorize(gboolean accept)
-{
- guint accept_val;
-
- void *agent = _bt_get_adapter_agent();
- if (!agent)
- return FALSE;
-
- accept_val = accept ? GAP_AGENT_ACCEPT : GAP_AGENT_REJECT;
-
- return gap_agent_reply_authorize(agent, accept_val, NULL);
-}
-
-gboolean _bt_agent_is_canceled(void)
-{
- void *agent = _bt_get_adapter_agent();
- if (!agent)
- return FALSE;
-
- return _gap_agent_is_canceled(agent);
-}
-
-void _bt_agent_set_canceled(gboolean value)
-{
- void *agent = _bt_get_adapter_agent();
- if (!agent)
- return;
-
- return _gap_agent_set_canceled(agent, value);
-}
-
-int _bt_agent_reply_cancellation(void)
-{
- void *agent = _bt_get_adapter_agent();
-
- if (!agent)
- return BLUETOOTH_ERROR_INTERNAL;
-
- if (gap_agent_reply_confirmation(agent, GAP_AGENT_CANCEL, NULL) != TRUE) {
- BT_ERR("Fail to reply agent");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-static gboolean __bt_agent_is_hid_keyboard(uint32_t dev_class)
-{
- switch ((dev_class & 0x1f00) >> 8) {
- case 0x05:
- switch ((dev_class & 0xc0) >> 6) {
- case 0x01:
- /* input-keyboard" */
- return TRUE;
- }
- break;
- }
-
- return FALSE;
-}
-
-static gboolean __bt_agent_find_device_by_address_exactname(char *buffer,
- const char *address)
-{
- char *pch;
- char *last;
-
- pch = strtok_r(buffer, "= ,", &last);
-
- if (pch == NULL)
- return FALSE;
-
- while ((pch = strtok_r(NULL, ",", &last))) {
- if (0 == g_strcmp0(pch, address)) {
- BT_DBG("Match found\n");
- return TRUE;
- }
- }
- return FALSE;
-}
-
-static gboolean __bt_agent_find_device_by_partial_name(char *buffer,
- const char *partial_name)
-{
- char *pch;
- char *last;
-
- pch = strtok_r(buffer, "= ,", &last);
-
- if (pch == NULL)
- return FALSE;
-
- while ((pch = strtok_r(NULL, ",", &last))) {
- if (g_str_has_prefix(partial_name, pch)) {
- BT_DBG("Match found\n");
- return TRUE;
- }
- }
- return FALSE;
-}
-
-static gboolean __bt_agent_is_device_blacklist(const char *address,
- const char *name)
-{
- char *buffer;
- char **lines;
- int i;
- FILE *fp;
- long size;
- size_t result;
-
- BT_DBG("+");
-
- fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "r");
-
- if (fp == NULL) {
- BT_ERR("Unable to open blacklist file");
- return FALSE;
- }
-
- fseek(fp, 0, SEEK_END);
- size = ftell(fp);
- if (size <= 0) {
- BT_DBG("size is not a positive number");
- fclose(fp);
- return FALSE;
- }
-
- rewind(fp);
-
- buffer = g_malloc0(sizeof(char) * size);
- result = fread((char *)buffer, 1, size, fp);
- fclose(fp);
- if (result != size) {
- BT_ERR("Read Error");
- g_free(buffer);
- return FALSE;
- }
-
- BT_DBG("Buffer = %s", buffer);
-
- lines = g_strsplit_set(buffer, BT_AGENT_NEW_LINE, 0);
- g_free(buffer);
-
- if (lines == NULL) {
- BT_ERR("No lines in the file");
- return FALSE;
- }
-
- for (i = 0; lines[i] != NULL; i++) {
- if (g_str_has_prefix(lines[i], "AddressBlacklist"))
- if (__bt_agent_find_device_by_address_exactname(
- lines[i], address))
- goto done;
- if (g_str_has_prefix(lines[i], "ExactNameBlacklist"))
- if (__bt_agent_find_device_by_address_exactname(
- lines[i], name))
- goto done;
- if (g_str_has_prefix(lines[i], "PartialNameBlacklist"))
- if (__bt_agent_find_device_by_partial_name(lines[i],
- name))
- goto done;
- if (g_str_has_prefix(lines[i], "KeyboardAutoPair"))
- if (__bt_agent_find_device_by_address_exactname(
- lines[i], address))
- goto done;
- }
- g_strfreev(lines);
- BT_DBG("-");
- return FALSE;
-done:
- BT_DBG("Found the device");
- g_strfreev(lines);
- return TRUE;
-}
-
-static gboolean __bt_agent_is_auto_response(uint32_t dev_class,
- const gchar *address, const gchar *name)
-{
- gboolean is_headset = FALSE;
- gboolean is_mouse = FALSE;
- char lap_address[BT_LOWER_ADDRESS_LENGTH];
-
- BT_DBG("bt_agent_is_headset_class, %d +", dev_class);
-
- if (address == NULL)
- return FALSE;
-
- switch ((dev_class & 0x1f00) >> 8) {
- case 0x04:
- switch ((dev_class & 0xfc) >> 2) {
- case 0x01:
- case 0x02:
- /* Headset */
- is_headset = TRUE;
- break;
- case 0x06:
- /* Headphone */
- is_headset = TRUE;
- break;
- case 0x0b: /* VCR */
- case 0x0c: /* Video Camera */
- case 0x0d: /* Camcorder */
- break;
- default:
- /* Other audio device */
- is_headset = TRUE;
- break;
- }
- break;
- case 0x05:
- switch (dev_class & 0xff) {
- case 0x80: /* 0x80: Pointing device(Mouse) */
- is_mouse = TRUE;
- break;
-
- case 0x40: /* 0x40: input device (BT keyboard) */
-
- /* Get the LAP(Lower Address part) */
- g_strlcpy(lap_address, address, sizeof(lap_address));
-
- /* Need to Auto pair the blacklisted Keyboard */
- if (__bt_agent_is_device_blacklist(lap_address, name) != TRUE) {
- BT_DBG("Device is not black listed\n");
- return FALSE;
- } else {
- BT_ERR("Device is black listed\n");
- return TRUE;
- }
- }
- }
-
- if ((!is_headset) && (!is_mouse))
- return FALSE;
-
- /* Get the LAP(Lower Address part) */
- g_strlcpy(lap_address, address, sizeof(lap_address));
-
- BT_DBG("Device address = %s\n", address);
- BT_DBG("Address 3 byte = %s\n", lap_address);
-
- if (__bt_agent_is_device_blacklist(lap_address, name)) {
- BT_ERR("Device is black listed\n");
- return FALSE;
- }
-
- return TRUE;
-}
-
-static int __bt_agent_generate_passkey(char *passkey, int size)
-{
- int i;
- ssize_t len;
- int random_fd;
- unsigned int value = 0;
-
- if (passkey == NULL)
- return -1;
-
- if (size <= 0)
- return -1;
-
- random_fd = open("/dev/urandom", O_RDONLY);
-
- if (random_fd < 0)
- return -1;
-
- for (i = 0; i < size; i++) {
- len = read(random_fd, &value, sizeof(value));
- if (len > 0)
- passkey[i] = '0' + (value % 10);
- }
-
- close(random_fd);
-
- BT_DBG("passkey: %s", passkey);
-
- return 0;
-}
-
-int _bt_set_passkey_notification(const char *sender, gboolean enable)
-{
- BT_INFO("Set passkey notification(sender:%s, %s)",
- sender, enable ? "Enable" : "Disable");
-
- g_free(passkey_watcher);
- if (enable == TRUE)
- passkey_watcher = g_strdup(sender);
- else
- passkey_watcher = NULL;
-
- return BLUETOOTH_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <gio/gio.h>
-#include <glib.h>
-#include <dlog.h>
-#include <string.h>
-#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
-#include <vconf.h>
-#endif
-#include <syspopup_caller.h>
-
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-
-#include "bt-service-audio.h"
-#include "bt-service-adapter.h"
-#include "bt-service-common.h"
-#include "bt-service-device.h"
-#include "bt-service-event.h"
-#include "bt-service-util.h"
-
-#include "bt-service-headset-connection.h"
-
-#ifdef TIZEN_SUPPORT_DUAL_HF
-#ifdef TIZEN_PROFILE_WEARABLE
-#define VCONF_KEY_BT_HOST_BT_MAC_ADDR "db/wms/host_bt_mac"
-#endif
-#endif
-
-typedef struct {
- unsigned int type;
- int device_state;
- char device_address[BT_ADDRESS_STRING_SIZE + 1];
-} bt_connected_headset_data_t;
-
-#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
-typedef struct {
- int alarm_id;
- int retry_count;
-} bt_auto_connect_timer_t;
-
-bt_auto_connect_timer_t auto_connect_timer = {0, };
-#endif
-
-static GList *g_connected_list;
-
-static bt_headset_wait_t *g_wait_data;
-
-static bt_audio_function_data_t *pdata;
-
-static void __bt_remove_device_from_wait_list();
-
-static void __bt_free_wait_data();
-
-static gboolean __bt_device_support_uuid(char *remote_address,
- bt_audio_type_t type);
-
-#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
-static int __bt_auto_connect_alarm_cb(alarm_id_t alarm_id, void* user_param);
-#endif
-
-static void __bt_hf_request_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data)
-{
- GError *g_error = NULL;
- GVariant *out_param1 = NULL;
- GVariant *reply = NULL;
- int result = BLUETOOTH_ERROR_NONE;
- bt_function_data_t *func_data;
- request_info_t *req_info;
-
- reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
- g_object_unref(proxy);
-
- func_data = user_data;
-
- if (func_data == NULL) {
- /* Send reply */
- BT_ERR("func_data == NULL");
- goto done;
- }
-
- req_info = _bt_get_request_info(func_data->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- goto done;
- }
-
- if (reply == NULL) {
- BT_ERR("HF Connect Dbus Call Error");
- result = _bt_convert_gerror(g_error);
- if (g_error) {
- BT_ERR("Error: %s\n", g_error->message);
- g_clear_error(&g_error);
- }
- } else {
- g_variant_unref(reply);
- }
-
- if (req_info->context == NULL)
- goto done;
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- func_data->address, BT_ADDRESS_STR_LEN, TRUE, NULL, NULL);
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("(iv)", result, out_param1));
-
- _bt_delete_request_list(req_info->req_id);
-
-done:
- if (func_data) {
- g_free(func_data->address);
- g_free(func_data);
- }
-}
-
-void _bt_audio_check_pending_connect()
-{
- BT_DBG("+");
- bluetooth_device_address_t device_address;
-
- if (pdata == NULL)
- return;
-
- if (pdata->pending == BT_PENDING_CONNECT) {
-
- _bt_convert_addr_string_to_type(device_address.addr,
- pdata->address);
- _bt_audio_connect(pdata->req_id,
- BT_AUDIO_A2DP,
- &device_address,
- NULL);
-
- g_free(pdata->address);
- g_free(pdata);
- pdata = NULL;
- }
-
- BT_DBG("-");
- return;
-}
-
-static void __bt_audio_request_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data)
-{
- GError *g_error = NULL;
- GVariant *out_param1 = NULL;
- GVariant *reply = NULL;
- int result = BLUETOOTH_ERROR_NONE;
- bt_audio_function_data_t *func_data;
- request_info_t *req_info;
-
- reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
- g_object_unref(proxy);
- g_variant_unref(reply);
-
- func_data = user_data;
-
- if (func_data == NULL) {
- /* Send reply */
- BT_ERR("func_data == NULL");
- goto done;
- }
-
- if (func_data->pending != BT_PENDING_NONE && g_error == NULL) {
- bluetooth_device_address_t device_address;
- _bt_convert_addr_string_to_type(device_address.addr,
- func_data->address);
-
- if (func_data->pending == BT_PENDING_CONNECT) {
-
- if (__bt_device_support_uuid(func_data->address,
- BT_AUDIO_A2DP)) {
-
- pdata = g_new0(bt_audio_function_data_t, 1);
- pdata->req_id = func_data->req_id;
- pdata->address = strdup(func_data->address);
- pdata->pending = func_data->pending;
- } else
- goto check_req_info;
-
- } else {
- if (_bt_is_service_connected(func_data->address
- , BT_AUDIO_HSP)) {
- _bt_audio_disconnect(func_data->req_id,
- BT_AUDIO_HSP, &device_address, NULL);
- } else
- goto check_req_info;
- }
-
- goto done;
- }
-
-check_req_info:
- req_info = _bt_get_request_info(func_data->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- goto done;
- }
-
- if (g_error == NULL)
- goto dbus_return;
-
- BT_ERR("Audio Connect/Disconnect Dbus Call Error: %s\n", g_error->message);
-
- result = BLUETOOTH_ERROR_INTERNAL;
- /* If there is error then we need to set local initiated connection as false
- * If don't do this then when headset initiate connection for HFP then we don't
- * initiate connection for A2dp to headset as this flag was set to true in first
- * connection failure attempt and not set in error case.*/
- _bt_headset_set_local_connection(FALSE);
-
- /* Remove the device from the list */
- _bt_remove_headset_from_list(func_data->type, func_data->address);
-
- /* Error, check if any waiting device is there */
- if (g_wait_data == NULL)
- goto dbus_return;
-
- if (g_strcmp0(g_wait_data->address, func_data->address) != 0) {
- bluetooth_device_address_t device_address;
- _bt_convert_addr_string_to_type(device_address.addr,
- g_wait_data->address);
- _bt_audio_connect(g_wait_data->req_id, g_wait_data->type,
- &device_address, NULL);
- }
-
- /* Event will be sent by the event reciever */
-dbus_return:
- if (req_info->context == NULL) {
- BT_DBG("req_info->context is NULL");
- goto done;
- }
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- func_data->address, BT_ADDRESS_STR_LEN, TRUE, NULL, NULL);
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("(iv)", result, out_param1));
-
- _bt_delete_request_list(req_info->req_id);
-done:
- g_clear_error(&g_error);
-
- if (func_data) {
- g_free(func_data->address);
- g_free(func_data);
- }
-}
-
-static void __bt_free_wait_data()
-{
- if (g_wait_data != NULL) {
- g_free(g_wait_data->address);
- g_free(g_wait_data);
- g_wait_data = NULL;
- }
-}
-
-static void __bt_remove_device_from_wait_list()
-{
- /* Before deleting the request update the UI */
- GVariant *out_param_1 = NULL;
- int result = BLUETOOTH_ERROR_INTERNAL;
- request_info_t *req_info;
-
- req_info = _bt_get_request_info(g_wait_data->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- return;
- }
-
- out_param_1 = g_variant_new_from_data((const GVariantType *)"ay",
- g_wait_data->address, BT_ADDRESS_STR_LEN, TRUE, NULL, NULL);
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("(iv)", result, out_param_1));
-
- _bt_delete_request_list(g_wait_data->req_id);
-}
-
-static void __bt_set_headset_disconnection_type(const char *address)
-{
- bt_connected_headset_data_t *connected_device;
- GList *node;
-
- node = g_list_first(g_connected_list);
- while (node != NULL) {
- connected_device = node->data;
- if (g_strcmp0(connected_device->device_address, address) == 0) {
- g_wait_data->disconnection_type = connected_device->type;
- return;
- }
- node = g_list_next(node);
- }
-}
-
-gboolean _bt_is_headset_type_connected(int type, char *address)
-{
- GList *node;
-
- node = g_list_first(g_connected_list);
- while (node != NULL) {
- bt_connected_headset_data_t *connected_device = node->data;
-
- if (connected_device->type & type) {
- if (address != NULL)
- g_strlcpy(address, connected_device->device_address,
- BT_ADDRESS_STRING_SIZE + 1);
- return TRUE;
- }
-
- node = g_list_next(node);
- }
- return FALSE;
-}
-
-#ifdef TIZEN_SUPPORT_DUAL_HF
-gboolean __bt_is_companion_device(const char *addr)
-{
-#ifdef TIZEN_PROFILE_WEARABLE
- char *host_device_address = NULL;
- host_device_address = vconf_get_str(VCONF_KEY_BT_HOST_BT_MAC_ADDR);
-
- if (!host_device_address) {
- BT_INFO("Failed to get a companion device address");
- return FALSE;
- }
-
- if (g_strcmp0(host_device_address, addr) == 0) {
- BT_INFO("Found companion device");
- free(host_device_address);
- return TRUE;
- }
-
- free(host_device_address);
- return FALSE;
-#else
- /* TODO : Need to add companion device check condition for Phone models */
- return FALSE;
-#endif
-}
-#endif
-
-static int __bt_is_headset_connected(int type, int req_id,
- const char *address)
-{
- gboolean connected = FALSE;
- char connected_address[BT_ADDRESS_STRING_SIZE + 1];
- bluetooth_device_address_t device_address;
- bt_connected_headset_data_t *connected_device = NULL;
-#ifdef TIZEN_SUPPORT_DUAL_HF
- gboolean is_companion_device = FALSE;
-#endif
-
- /* Check if any other headset is connected */
- GList *node = NULL;;
-
- node = g_list_first(g_connected_list);
- while (node != NULL) {
- connected_device = node->data;
- if ((connected_device->type & type)) {
- g_strlcpy(connected_address, connected_device->device_address,
- BT_ADDRESS_STRING_SIZE + 1);
-#ifdef TIZEN_SUPPORT_DUAL_HF
- is_companion_device = __bt_is_companion_device(connected_address);
- BT_INFO(" is_companion_device[%d]", is_companion_device);
-
- if (!is_companion_device) {
- connected = TRUE;
- break;
- }
-#else
- connected = TRUE;
- break;
-#endif
- }
- node = g_list_next(node);
- }
-
- if (!connected)
- return BLUETOOTH_ERROR_NOT_CONNECTED;
-
- BT_DBG("connected headset %s", connected_address);
-
- if (g_strcmp0(connected_address, address) == 0)
- return BLUETOOTH_ERROR_ALREADY_CONNECT;
-#ifdef TIZEN_SUPPORT_DUAL_HF
- else if (TRUE == __bt_is_companion_device(address))
- return BLUETOOTH_ERROR_NOT_CONNECTED;
-#endif
-
- /* Convert BD address from string type */
- _bt_convert_addr_string_to_type(device_address.addr, connected_address);
- int value = BLUETOOTH_ERROR_NONE;
- value = _bt_audio_disconnect(0, connected_device->type & type, &device_address, NULL);
-
- /* If already one device is waiting, remove current waiting device and add new */
- if (value == BLUETOOTH_ERROR_NONE) {
- if (g_wait_data != NULL) {
- if (g_strcmp0(g_wait_data->address, address) != 0) {
- __bt_remove_device_from_wait_list();
- __bt_free_wait_data();
- }
- }
-
- if (g_wait_data == NULL) {
- g_wait_data = g_malloc0(sizeof(bt_headset_wait_t));
- g_wait_data->address = g_strdup(address);
- g_wait_data->req_id = req_id;
- g_wait_data->type = type;
- g_wait_data->ag_flag = FALSE;
-
- /* Set disconnection type */
- __bt_set_headset_disconnection_type(connected_address);
- }
- }
-
- return value;
-}
-
-static int __bt_is_headset_connecting(int type)
-{
- bt_connected_headset_data_t *connected_device = NULL;
-
- /* Check if any other headset is connected */
- GList *node = NULL;
-
- node = g_list_first(g_connected_list);
- while (node != NULL) {
- connected_device = node->data;
- if (connected_device->device_state == BT_STATE_CONNECTING)
- return BLUETOOTH_ERROR_CONNECTION_BUSY;
- node = g_list_next(node);
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int __bt_is_headset_disconnecting(int type)
-{
- bt_connected_headset_data_t *connected_device = NULL;
-
- /* Check if any other headset is connected */
- GList *node = NULL;
-
- node = g_list_first(g_connected_list);
- while (node != NULL) {
- connected_device = node->data;
- if (connected_device->device_state == BT_STATE_DISCONNECTING)
- return BLUETOOTH_ERROR_CONNECTION_BUSY;
-
- node = g_list_next(node);
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_set_audio_wait_data_flag(gboolean flag)
-{
- BT_DBG("_bt_set_audio_wait_data_flag \n");
- g_wait_data->ag_flag = flag;
-}
-
-bt_headset_wait_t *_bt_get_audio_wait_data(void)
-{
- BT_DBG("_bt_get_audio_wait_data \n");
- return g_wait_data;
-}
-
-void _bt_rel_wait_data(void)
-{
- BT_DBG("_bt_rel_wait_data \n");
- __bt_free_wait_data();
-}
-
-void _bt_add_headset_to_list(int type, int status, const char *address)
-{
- bt_connected_headset_data_t *connected_device;
- bt_connected_headset_data_t *device;
- GList *node;
-
- BT_DBG("_bt_add_headset_to_list \n");
-
- node = g_list_first(g_connected_list);
- while (node != NULL) {
- device = (bt_connected_headset_data_t *)node->data;
-
- if (g_strcmp0(device->device_address, address) == 0) {
- BT_DBG("Address match, update connection type \n");
- if (status == BT_STATE_CONNECTED)
- device->type |= type;
- device->device_state = status;
- return;
- }
- node = g_list_next(node);
- }
-
- connected_device = g_malloc0(sizeof(bt_connected_headset_data_t));
-
- connected_device->device_state = status;
- if ((status == BT_STATE_CONNECTED) || (status == BT_STATE_CONNECTING))
- connected_device->type |= type;
- g_strlcpy(connected_device->device_address, address,
- sizeof(connected_device->device_address));
- g_connected_list = g_list_append(g_connected_list, connected_device);
-}
-
-int _bt_get_device_state_from_list(int type, const char *address)
-{
- GList *node;
- bt_connected_headset_data_t *device;
-
- BT_DBG("+");
- node = g_list_first(g_connected_list);
- while (node != NULL) {
- device = (bt_connected_headset_data_t *)node->data;
- if (g_strcmp0(device->device_address, address) == 0) {
- BT_DBG("Device found");
- return device->device_state;
- }
- node = g_list_next(node);
- }
-
- BT_DBG("Device not found");
- return BLUETOOTH_ERROR_INTERNAL;
-}
-
-void _bt_remove_headset_from_list(int type, const char *address)
-{
- GList *node;
-
- BT_DBG("_bt_remove_headset_from_list \n");
-
- node = g_list_first(g_connected_list);
- while (node != NULL) {
- bt_connected_headset_data_t *connected_device = node->data;
-
- if (g_strcmp0(connected_device->device_address, address) != 0) {
- node = g_list_next(node);
- continue;
- }
-
- BT_DBG("Address match \n");
-
- BT_DBG("Connection type = %x\n", connected_device->type);
-
- switch (type) {
- case BT_AUDIO_A2DP:
- if (connected_device->type & BT_AUDIO_A2DP)
- connected_device->type &= ~(BT_AUDIO_A2DP);
- break;
- case BT_AUDIO_HSP:
- if (connected_device->type & BT_AUDIO_HSP)
- connected_device->type &= ~(BT_AUDIO_HSP);
- break;
- case BT_AUDIO_ALL:
- if (connected_device->type & BT_AUDIO_ALL)
- connected_device->type &= ~(BT_AUDIO_ALL);
- break;
- case BT_AVRCP:
- if (connected_device->type & BT_AVRCP)
- connected_device->type &= ~(BT_AVRCP);
- break;
- case BT_AUDIO_A2DP_SOURCE:
- if (connected_device->type & BT_AUDIO_A2DP_SOURCE)
- connected_device->type &= ~(BT_AUDIO_A2DP_SOURCE);
- }
-
- BT_DBG("Connection type = %x\n", connected_device->type);
-
- if (connected_device->type == 0x00) {
- g_connected_list = g_list_remove(g_connected_list, connected_device);
- g_free(connected_device);
- } else {
- connected_device->device_state = BT_STATE_CONNECTED;
- }
-
- node = g_list_next(node);
- }
-}
-
-static gboolean __bt_device_support_uuid(char *remote_address,
- bt_audio_type_t type)
-{
- GArray *dev_list = NULL;
- int size;
- int i;
- int j;
- bluetooth_device_info_t *info;
- char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- gboolean ret = FALSE;
-
- BT_DBG("+");
-
- dev_list = g_array_new(FALSE, FALSE, sizeof(gchar));
-
- _bt_get_bonded_devices(&dev_list);
- size = (dev_list->len) / sizeof(bluetooth_device_info_t);
-
- for (i = 0; i < size; i++) {
- info = &g_array_index(dev_list, bluetooth_device_info_t, i);
- _bt_convert_addr_type_to_string(bond_address,
- info->device_address.addr);
- if (strcmp(bond_address, remote_address) != 0)
- continue;
-
- BT_INFO("Device address Matched");
- j = 0;
- while (j != info->service_index) {
- if (type == BT_AUDIO_HSP) {
- if (strcmp(info->uuids[j], HFP_HS_UUID) == 0) {
- BT_INFO("HFP HS UUID exists");
- ret = TRUE;
- goto end;
- }
- } else if (type == BT_AUDIO_A2DP) {
- if (strcmp(info->uuids[j], A2DP_SINK_UUID) == 0) {
- BT_INFO("A2DP SINK UUID exists");
- ret = TRUE;
- goto end;
- }
- }
- j++;
- }
- }
-end:
- g_array_free(dev_list, TRUE);
- BT_DBG("-");
- return ret;
-}
-
-gboolean _bt_is_service_connected(char* address, int type)
-{
- GList *node;
-
- node = g_list_first(g_connected_list);
- while (node != NULL) {
- bt_connected_headset_data_t *conn_device = node->data;
-
- if ((g_strcmp0(conn_device->device_address, address) == 0) &&
- (conn_device->type & type)) {
- BT_INFO("Service connected");
- return TRUE;
- }
-
- node = g_list_next(node);
- }
- BT_INFO("Service not connected");
- return FALSE;
-}
-
-int _bt_audio_connect(int request_id, int type,
- bluetooth_device_address_t *device_address,
- GArray *out_param1)
-{
- int result = BLUETOOTH_ERROR_NONE;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- GDBusProxy *adapter_proxy;
- GDBusConnection *g_conn;
- int ret;
- char *uuid = NULL;
- int value = BLUETOOTH_ERROR_NONE;
- bt_audio_function_data_t *func_data;
- guint hfp_hs_restricted = 0x0; /* set default "allowed" */
- guint a2dp_restricted = 0x0;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- g_conn = _bt_gdbus_get_system_gconn();
- retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- func_data = g_malloc0(sizeof(bt_audio_function_data_t));
-
- func_data->address = g_strdup(address);
- func_data->req_id = request_id;
- func_data->type = type;
- func_data->pending = BT_PENDING_NONE;
-
- result = _bt_get_restrict_profile(device_address, RESTRICTED_PROFILE_HFP_HS, &hfp_hs_restricted);
- if (result != BLUETOOTH_ERROR_NONE)
- BT_ERR("Can't get hfp_hs restriction info");
-
- result = _bt_get_restrict_profile(device_address, RESTRICTED_PROFILE_A2DP, &a2dp_restricted);
- if (result != BLUETOOTH_ERROR_NONE)
- BT_ERR("Can't get a2dp restriction info");
-
- switch (type) {
- case BT_AUDIO_HSP:
- uuid = HFP_HS_UUID;
- break;
- case BT_AUDIO_A2DP:
- uuid = A2DP_SINK_UUID;
- break;
- case BT_AVRCP:
- uuid = AVRCP_TARGET_UUID;
- break;
- case BT_AUDIO_A2DP_SOURCE:
- uuid = A2DP_SOURCE_UUID;
- break;
- case BT_AUDIO_ALL:
- if ((hfp_hs_restricted == 0x0) && (a2dp_restricted == 0x0)) { /* in case of both profiles are not restricted */
- if (__bt_device_support_uuid(address, BT_AUDIO_HSP)) {
- uuid = HFP_HS_UUID;
- func_data->pending = BT_PENDING_CONNECT;
- type = BT_AUDIO_HSP;
- } else if (__bt_device_support_uuid(address, BT_AUDIO_A2DP)) {
- uuid = A2DP_SINK_UUID;
- type = BT_AUDIO_A2DP;
- } else {
- BT_ERR("No audio role supported");
- result = BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
- goto fail;
- }
- } else if ((hfp_hs_restricted == 0x1) && (a2dp_restricted == 0x1)) { /* in case of both profiles are restricted */
- BT_ERR("All profiles are restricted");
- result = BLUETOOTH_ERROR_INTERNAL;
- goto fail;
- } else if (a2dp_restricted == 0x01) { /* in case of a2dp is restricted, only connection for hfp_hs */
- if (__bt_device_support_uuid(address, BT_AUDIO_HSP)) {
- uuid = HFP_HS_UUID;
- type = BT_AUDIO_HSP;
- } else {
- BT_ERR("HFP_HS role is not supported");
- result = BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
- goto fail;
- }
- } else if (hfp_hs_restricted == 0x01) { /* in case of hfp_hs is restricted, only connection for a2dp */
- if (__bt_device_support_uuid(address, BT_AUDIO_A2DP)) {
- uuid = A2DP_SINK_UUID;
- type = BT_AUDIO_A2DP;
- } else {
- BT_ERR("A2DP role is not supported");
- result = BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
- goto fail;
- }
- }
- break;
- case BT_AVRCP_TARGET:
- uuid = AVRCP_REMOTE_UUID;
- break;
- default:
- BT_ERR("Unknown role");
- result = BLUETOOTH_ERROR_INTERNAL;
- goto fail;
- }
- BT_INFO("Connecting to service %s", uuid);
-
- value = __bt_is_headset_connected(type, request_id, address);
-
- if (value == BLUETOOTH_ERROR_ALREADY_CONNECT) {
- return BLUETOOTH_ERROR_ALREADY_CONNECT;
- } else if (value == BLUETOOTH_ERROR_NOT_CONNECTED) {
- value = __bt_is_headset_connecting(type);
- if (value != BLUETOOTH_ERROR_NONE) {
- result = BLUETOOTH_ERROR_IN_PROGRESS;
- goto fail;
- }
- _bt_headset_set_local_connection(TRUE);
- ret = _bt_connect_profile(address, uuid,
- __bt_audio_request_cb, func_data);
-
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("_bt_connect_profile Error");
- _bt_headset_set_local_connection(FALSE);
- g_free(func_data->address);
- g_free(func_data);
- return ret;
- }
-
- /* Add data to the connected list */
- _bt_add_headset_to_list(type, BT_STATE_CONNECTING, address);
- } else if (value == BLUETOOTH_ERROR_IN_PROGRESS) {
- return BLUETOOTH_ERROR_IN_PROGRESS;
- }
-
- if (out_param1)
- g_array_free(out_param1, TRUE);
-
- return BLUETOOTH_ERROR_NONE;
-fail:
- if (out_param1 != NULL)
- g_array_append_vals(out_param1, address,
- BT_ADDRESS_STR_LEN);
-
- return result;
-}
-
-int _bt_audio_disconnect(int request_id, int type,
- bluetooth_device_address_t *device_address,
- GArray *out_param1)
-{
- int result = BLUETOOTH_ERROR_NONE;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- bt_audio_function_data_t *func_data;
- GDBusProxy *adapter_proxy;
- GDBusConnection *g_conn;
- GList *node;
- int ret;
- char *uuid;
- int value = BLUETOOTH_ERROR_NONE;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- g_conn = _bt_gdbus_get_system_gconn();
- retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- func_data = g_malloc0(sizeof(bt_audio_function_data_t));
- func_data->address = g_strdup(address);
- func_data->req_id = request_id;
- func_data->pending = BT_PENDING_NONE;
- func_data->type = type;
-
- switch (type) {
- case BT_AUDIO_HSP:
- uuid = HFP_HS_UUID;
- break;
- case BT_AUDIO_A2DP:
- uuid = A2DP_SINK_UUID;
- break;
- case BT_AVRCP:
- uuid = AVRCP_TARGET_UUID;
- break;
- case BT_AUDIO_A2DP_SOURCE:
- uuid = A2DP_SOURCE_UUID;
- break;
- case BT_AUDIO_ALL:
- if (_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
- uuid = A2DP_SINK_UUID;
- func_data->pending = BT_PENDING_DISCONNECT;
- } else if (_bt_is_service_connected(address, BT_AUDIO_HSP)) {
- uuid = HFP_HS_UUID;
- } else {
- BT_ERR("No audio service connected");
- result = BLUETOOTH_ERROR_NOT_CONNECTED;
- goto fail;
- }
- break;
- case BT_AVRCP_TARGET:
- uuid = AVRCP_REMOTE_UUID;
- break;
- default:
- BT_ERR("Unknown role");
- result = BLUETOOTH_ERROR_INTERNAL;
- goto fail;
- }
- value = __bt_is_headset_disconnecting(type);
- if (value != BLUETOOTH_ERROR_NONE) {
- BT_INFO("Disconnect in progress");
- result = BLUETOOTH_ERROR_IN_PROGRESS;
- goto fail;
- }
- BT_INFO("Disconnecting service %s", uuid);
- ret = _bt_disconnect_profile(address, uuid,
- __bt_audio_request_cb, func_data);
-
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("_bt_disconnect_profile Error");
- g_free(func_data->address);
- g_free(func_data);
- return ret;
- }
-
- /*
- * This logic is added for dual HF mode issue.
- */
- node = g_list_first(g_connected_list);
- while (node != NULL) {
- bt_connected_headset_data_t *connected_device = node->data;
-
- if (g_strcmp0(connected_device->device_address, address) == 0) {
- BT_DBG("Connection type update");
- type = connected_device->type;
- break;
- }
- node = g_list_next(node);
- }
- _bt_add_headset_to_list(type, BT_STATE_DISCONNECTING, address);
-
- if (out_param1)
- g_array_free(out_param1, TRUE);
-
- return BLUETOOTH_ERROR_NONE;
-fail:
- if (out_param1 != NULL)
- g_array_append_vals(out_param1, address,
- BT_ADDRESS_STR_LEN);
-
- return result;
-}
-
-void _bt_remove_from_connected_list(const char *address)
-{
- bt_connected_headset_data_t *connected_device;
- GList *node;
-
- node = g_list_first(g_connected_list);
- while (node != NULL) {
- connected_device = node->data;
- if (connected_device != NULL &&
- g_strcmp0(connected_device->device_address, address) == 0) {
- BT_ERR("Device is removed from the list");
- g_connected_list = g_list_remove(g_connected_list, connected_device);
- g_free(connected_device);
- return;
- }
- node = g_list_next(node);
- }
-}
-
-int _bt_hf_connect(int request_id,
- bluetooth_device_address_t *device_address,
- GArray *out_param1)
-{
- int result = BLUETOOTH_ERROR_NONE;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- bt_function_data_t *func_data;
- GDBusProxy *adapter_proxy;
- GDBusConnection *g_conn;
- gboolean connected = FALSE;
- int ret;
- char *uuid;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- adapter_proxy = _bt_get_adapter_proxy();
- if (adapter_proxy == NULL) {
- result = BLUETOOTH_ERROR_INTERNAL;
- goto fail;
- }
-
- g_conn = _bt_gdbus_get_system_gconn();
- if (g_conn == NULL) {
- result = BLUETOOTH_ERROR_INTERNAL;
- goto fail;
- }
-
- /* Check if HF is connected or not */
- result = _bt_is_device_connected(device_address, BT_PROFILE_CONN_HFG, &connected);
- if (connected == TRUE) {
- BT_ERR("HF is already connected");
- result = BLUETOOTH_ERROR_ALREADY_CONNECT;
- goto fail;
- }
-
- func_data = g_malloc0(sizeof(bt_function_data_t));
- func_data->address = g_strdup(address);
- func_data->req_id = request_id;
- uuid = g_strdup(HFP_AG_UUID);
-
- BT_DBG("Connecting to service %s", uuid);
-
- ret = _bt_connect_profile(address, uuid,
- __bt_hf_request_cb, func_data);
-
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("_bt_connect_profile Error");
- g_free(func_data->address);
- g_free(func_data);
- g_free(uuid);
- return ret;
- }
- g_free(uuid);
- if (out_param1)
- g_array_free(out_param1, TRUE);
-
- return BLUETOOTH_ERROR_NONE;
-fail:
- if (out_param1 != NULL)
- g_array_append_vals(out_param1, address,
- BT_ADDRESS_STR_LEN);
-
- return result;
-}
-
-int _bt_hf_disconnect(int request_id,
- bluetooth_device_address_t *device_address,
- GArray *out_param1)
-{
- int result = BLUETOOTH_ERROR_NONE;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- bt_function_data_t *func_data;
- GDBusProxy *adapter_proxy;
- GDBusConnection *g_conn;
-
- int ret;
- char *uuid;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- adapter_proxy = _bt_get_adapter_proxy();
- if (adapter_proxy == NULL) {
- result = BLUETOOTH_ERROR_INTERNAL;
- goto fail;
- }
-
- g_conn = _bt_gdbus_get_system_gconn();
- if (g_conn == NULL) {
- result = BLUETOOTH_ERROR_INTERNAL;
- goto fail;
- }
-
- func_data = g_malloc0(sizeof(bt_function_data_t));
- func_data->address = g_strdup(address);
- func_data->req_id = request_id;
- uuid = g_strdup(HFP_AG_UUID);
-
- BT_DBG("Disconnecting service %s", uuid);
- ret = _bt_disconnect_profile(address, uuid,
- __bt_hf_request_cb, func_data);
-
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("_bt_disconnect_profile Error");
- g_free(func_data->address);
- g_free(func_data);
- g_free(uuid);
- return ret;
- }
- g_free(uuid);
- if (out_param1)
- g_array_free(out_param1, TRUE);
-
- return BLUETOOTH_ERROR_NONE;
-fail:
- if (out_param1 != NULL)
- g_array_append_vals(out_param1, address,
- BT_ADDRESS_STR_LEN);
-
- return result;
-}
-
-int _bt_audio_set_content_protect(gboolean status)
-{
- GDBusConnection *conn;
- GError *error = NULL;
-
- BT_DBG("+\n");
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- BT_DBG("Content Protection status = [%d]", status);
-
- g_dbus_connection_emit_signal(conn,
- NULL, BT_CONTENT_PROTECTION_PATH,
- BT_CONTENT_PROTECTION_INTERFACE,
- "ProtectionRequired",
- g_variant_new("(b)", status),
- &error);
-
- if (error) {
- /* dBUS gives error cause */
- ERR("Could not Emit Signal: errCode[%x], message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- BT_DBG("Emit Signal done = [ProtectionRequired]");
- return BLUETOOTH_ERROR_NONE;
-}
-
-#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
-static void __bt_auto_connect_request_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data)
-{
- GError *err = NULL;
- GVariant *reply = NULL;
-
- reply = g_dbus_proxy_call_finish(proxy, res, &err);
- g_object_unref(proxy);
- g_variant_unref(reply);
-
- BT_DBG("+");
- if (err != NULL) {
- g_dbus_error_strip_remote_error(err);
- BT_INFO("Auto_connect_request Dbus Call Error: %s", err->message);
-
- if (strcmp("Host is down", err->message)) {
- BT_INFO("Fail reason is not 'Host Down'. Terminate auto connect");
- _bt_audio_stop_auto_connect();
- vconf_set_str(BT_LAST_CONNECTED_DEVICE, "");
- }
- }
- g_clear_error(&err);
-}
-
-
-// It is the function that retry to create alarm.
-// Sometimes alarm mgr service is created later than bluetooth-frwk service in booting time.
-// So, in this case, we have to retry alarmmgr_add_alarm.
-static gboolean __bt_audio_alarm_retry_cb(gpointer data)
-{
- int result;
- alarm_id_t alarm_id;
-
- BT_DBG("__bt_audio_alarm_retry_cb called.");
- result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS,
- __bt_auto_connect_alarm_cb, NULL, &alarm_id);
-
- if (result != BLUETOOTH_ERROR_NONE)
- return TRUE;
- else
- auto_connect_timer.alarm_id = alarm_id;
-
- return FALSE;
-}
-
-static int __bt_auto_connect_alarm_cb(alarm_id_t alarm_id, void* user_param)
-{
- int result = BLUETOOTH_ERROR_NONE;
- char *address = NULL;
- alarm_id_t new_alarm_id;
-
- BT_INFO("alram id = [%d] , retry_count [%d] ",
- alarm_id, auto_connect_timer.retry_count);
-
- if (alarm_id != auto_connect_timer.alarm_id)
- return 0;
-
- address = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
-
- if (address == NULL) {
- BT_ERR("Address vconf is null");
- auto_connect_timer.alarm_id = 0;
- return 0;
- }
-
- BT_DBG("ADDRESS [%s]", address);
-
- result = _bt_connect_profile(address, A2DP_SOURCE_UUID,
- __bt_auto_connect_request_cb, NULL);
-
- auto_connect_timer.retry_count--;
-
- BT_DBG("result [%d]", result);
-
- if (auto_connect_timer.retry_count <= 0) {
- BT_INFO(" ### Stopping Auto connect retry");
- auto_connect_timer.alarm_id = 0;
- } else {
- result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS,
- __bt_auto_connect_alarm_cb, NULL, &new_alarm_id);
- if (result == BLUETOOTH_ERROR_NONE)
- auto_connect_timer.alarm_id = new_alarm_id;
- }
-
- free(address);
- return 0;
-}
-
-static void __bt_auto_connect_alarm_remove()
-{
- BT_DBG("");
- if (auto_connect_timer.alarm_id > 0) {
- _bt_service_remove_alarm(auto_connect_timer.alarm_id);
- auto_connect_timer.alarm_id = 0;
- }
- auto_connect_timer.retry_count = 0;
-}
-
-int _bt_audio_start_auto_connect(gboolean linkloss_flag)
-{
- int result = BLUETOOTH_ERROR_NONE;
- char *address = NULL;
- alarm_id_t alarm_id = 0;
-
- BT_DBG("");
-
- address = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
-
- if (address == NULL) {
- BT_ERR("No target device");
- return 0;
- }
-
- __bt_auto_connect_alarm_remove();
-
- auto_connect_timer.retry_count = BT_AUTO_CONNECT_TIMEOUT_RETRY_TIME /
- BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS;
-
- if (linkloss_flag) {
- BT_INFO(" ### Start auto connection after linkloss");
- result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS,
- __bt_auto_connect_alarm_cb, NULL, &alarm_id);
- if (result != BLUETOOTH_ERROR_NONE)
- g_timeout_add(500, (GSourceFunc)__bt_audio_alarm_retry_cb, NULL);
- else
- auto_connect_timer.alarm_id = alarm_id;
-
- } else {
- BT_INFO(" ### Start auto connection after BT activated");
- result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_BT_ACTIVATED,
- __bt_auto_connect_alarm_cb, NULL, &alarm_id);
- if (result == BLUETOOTH_ERROR_NONE)
- auto_connect_timer.alarm_id = alarm_id;
- }
-
- free(address);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_audio_stop_auto_connect(void)
-{
- BT_DBG("");
- __bt_auto_connect_alarm_remove();
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_audio_set_auto_connect_device_addr(const char *address)
-{
- if (address == NULL) {
- BT_ERR("address is null");
- return;
- }
-
- BT_INFO("Last connected device is [%s]", address);
- vconf_set_str(BT_LAST_CONNECTED_DEVICE, address);
-}
-#endif /*TIZEN_BT_A2DP_SINK_AUTO_CONNECT */
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "bt-internal-types.h"
-#include "bt-service-common.h"
-#include "bt-service-avrcp-controller.h"
-#include "bt-service-audio.h"
-#include "bt-service-event.h"
-
-static bt_player_settinngs_t repeat_status[] = {
- { REPEAT_INVALID, "" },
- { REPEAT_MODE_OFF, "off" },
- { REPEAT_SINGLE_TRACK, "singletrack" },
- { REPEAT_ALL_TRACK, "alltracks" },
- { REPEAT_GROUP, "group" },
- { REPEAT_INVALID, "" }
-};
-
-static bt_player_settinngs_t equalizer_status[] = {
- { EQUALIZER_INVALID, "" },
- { EQUALIZER_OFF, "off" },
- { EQUALIZER_ON, "on" },
- { EQUALIZER_INVALID, "" },
-};
-
-static bt_player_settinngs_t scan_status[] = {
- { SCAN_INVALID, "" },
- { SCAN_MODE_OFF, "off" },
- { SCAN_ALL_TRACK, "alltracks" },
- { SCAN_GROUP, "group" },
- { SCAN_INVALID, "" },
-};
-
-static bt_player_settinngs_t shuffle_settings[] = {
- { SHUFFLE_INVALID, "" },
- { SHUFFLE_MODE_OFF, "off" },
- { SHUFFLE_ALL_TRACK, "alltracks" },
- { SHUFFLE_GROUP, "group" },
- { SHUFFLE_INVALID, "" }
-};
-
-static char *avrcp_control_path = NULL;
-
-void _bt_set_control_device_path(const char *path)
-{
-
- ret_if(path == NULL);
-
- g_free(avrcp_control_path);
- BT_DBG("control_path = %s", path);
- avrcp_control_path = g_strdup(path);
-}
-
-void _bt_remove_control_device_path(const char *path)
-{
- ret_if(path == NULL);
-
- if (avrcp_control_path &&
- !g_strcmp0(avrcp_control_path, path)) {
- BT_DBG("control_path = %s", path);
- g_free(avrcp_control_path);
- avrcp_control_path = NULL;
- }
-}
-
-static char *__bt_get_control_device_path(void)
-{
- char *adapter_path;
- char *control_path;
- char connected_address[BT_ADDRESS_STRING_SIZE + 1];
-
- BT_DBG("+");
-
- if (avrcp_control_path != NULL)
- return avrcp_control_path;
-
- retv_if(!_bt_is_headset_type_connected(BT_AVRCP,
- connected_address), NULL);
-
- BT_DBG("device address = %s", connected_address);
-
- adapter_path = _bt_get_device_object_path(connected_address);
- retv_if(adapter_path == NULL, NULL);
-
- control_path = g_strdup_printf(BT_MEDIA_CONTROL_PATH, adapter_path);
- g_free(adapter_path);
-
- avrcp_control_path = control_path;
- BT_DBG("control_path = %s", control_path);
- return control_path;
-}
-
-static int __bt_media_send_control_msg(const char *name)
-{
- GVariant *reply = NULL;
- GError *err = NULL;
- GDBusConnection *conn = NULL;
- GDBusProxy *proxy = NULL;
- char *control_path = NULL;
-
- retv_if(name == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- BT_INFO("Command [%s]", name);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- control_path = __bt_get_control_device_path();
- retv_if(control_path == NULL, BLUETOOTH_ERROR_NOT_CONNECTED);
- BT_DBG("control_path %s", control_path);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, control_path,
- BT_PLAYER_CONTROL_INTERFACE, NULL, &err);
- if (proxy == NULL) {
- BT_ERR("Unable to allocate new proxy \n");
- if (err) {
- BT_ERR("%s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- reply = g_dbus_proxy_call_sync(proxy, name, NULL,
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
-
- g_object_unref(proxy);
-
- if (!reply) {
- BT_ERR("Error returned in method call");
- if (err) {
- BT_ERR("%s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_unref(reply);
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_avrcp_control_cmd(int type)
-{
- int ret = BLUETOOTH_ERROR_INTERNAL;
- BT_DBG("+");
-
- switch (type) {
- case PLAY:
- ret = __bt_media_send_control_msg("Play");
- break;
- case PAUSE:
- ret = __bt_media_send_control_msg("Pause");
- break;
- case STOP:
- ret = __bt_media_send_control_msg("Stop");
- break;
- case NEXT:
- ret = __bt_media_send_control_msg("Next");
- break;
- case PREVIOUS:
- ret = __bt_media_send_control_msg("Previous");
- break;
- case PRESS_FAST_FORWARD:
- ret = __bt_media_send_control_msg("PressFastForward");
- break;
- case RELEASE_FAST_FORWARD:
- ret = __bt_media_send_control_msg("ReleaseFastForward");
- break;
- case PRESS_REWIND:
- ret = __bt_media_send_control_msg("PressRewind");
- break;
- case RELEASE_REWIND:
- ret = __bt_media_send_control_msg("ReleaseRewind");
- break;
- case VOLUME_UP:
- ret = __bt_media_send_control_msg("VolumeUp");
- break;
- case VOLUME_DOWN:
- ret = __bt_media_send_control_msg("VolumeDown");
- break;
- default:
- BT_DBG("Invalid Type\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
- BT_DBG("-");
- return ret;
-}
-
-GDBusProxy *__bt_get_control_properties_proxy(void)
-{
- GDBusProxy *proxy = NULL;
- GError *error = NULL;
- char *control_path = NULL;
- GDBusConnection *conn = NULL;
-
- control_path = __bt_get_control_device_path();
- retv_if(control_path == NULL, NULL);
- BT_DBG("control_path = %s", control_path);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, NULL);
-
- proxy = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, control_path,
- BT_PROPERTIES_INTERFACE, NULL, &error);
- if (proxy == NULL) {
- BT_ERR("Unable to allocate new proxy");
- if (error) {
- BT_ERR("%s", error->message);
- g_clear_error(&error);
- }
- return NULL;
- }
-
- return proxy;
-}
-
-static int __bt_media_attr_to_event(const char *str)
-{
- if (!strcasecmp(str, "Equalizer"))
- return BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS;
- else if (!strcasecmp(str, "Repeat"))
- return BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS;
- else if (!strcasecmp(str, "Shuffle"))
- return BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS;
- else if (!strcasecmp(str, "Scan"))
- return BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS;
- else if (!strcasecmp(str, "Position"))
- return BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS;
- else if (!strcasecmp(str, "Track"))
- return BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED;
- else if (!strcasecmp(str, "Status"))
- return BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED;
-
- return 0;
-}
-
-static int __bt_media_attr_to_type(const char *str)
-{
- if (!strcasecmp(str, "Equalizer"))
- return EQUALIZER;
- else if (!strcasecmp(str, "Repeat"))
- return REPEAT;
- else if (!strcasecmp(str, "Shuffle"))
- return SHUFFLE;
- else if (!strcasecmp(str, "Scan"))
- return SCAN;
- else if (!strcasecmp(str, "Position"))
- return POSITION;
- else if (!strcasecmp(str, "Track"))
- return METADATA;
- else if (!strcasecmp(str, "Status"))
- return STATUS;
-
- return 0;
-}
-
-static const char *__bt_media_type_to_str(int type)
-{
- switch (type) {
- case EQUALIZER:
- return "Equalizer";
- case REPEAT:
- return "Repeat";
- case SHUFFLE:
- return "Shuffle";
- case SCAN:
- return "Scan";
- case POSITION:
- return "Position";
- case METADATA:
- return "Track";
- case STATUS:
- return "Status";
- }
- return NULL;
-}
-
-static int __bt_media_attrval_to_val(int type, const char *value)
-{
- int ret = 0;
-
- switch (type) {
- case EQUALIZER:
- if (!strcmp(value, "off"))
- ret = EQUALIZER_OFF;
- else if (!strcmp(value, "on"))
- ret = EQUALIZER_ON;
- else
- ret = EQUALIZER_INVALID;
- break;
-
- case REPEAT:
- if (!strcmp(value, "off"))
- ret = REPEAT_MODE_OFF;
- else if (!strcmp(value, "singletrack"))
- ret = REPEAT_SINGLE_TRACK;
- else if (!strcmp(value, "alltracks"))
- ret = REPEAT_ALL_TRACK;
- else if (!strcmp(value, "group"))
- ret = REPEAT_GROUP;
- else
- ret = REPEAT_INVALID;
- break;
-
- case SHUFFLE:
- if (!strcmp(value, "off"))
- ret = SHUFFLE_MODE_OFF;
- else if (!strcmp(value, "alltracks"))
- ret = SHUFFLE_ALL_TRACK;
- else if (!strcmp(value, "group"))
- ret = SHUFFLE_GROUP;
- else
- ret = SHUFFLE_INVALID;
- break;
-
- case SCAN:
- if (!strcmp(value, "off"))
- ret = SCAN_MODE_OFF;
- else if (!strcmp(value, "alltracks"))
- ret = SCAN_ALL_TRACK;
- else if (!strcmp(value, "group"))
- ret = SCAN_GROUP;
- else
- ret = SCAN_INVALID;
- break;
-
- case STATUS:
- if (!strcmp(value, "stopped"))
- ret = STATUS_STOPPED;
- else if (!strcmp(value, "playing"))
- ret = STATUS_PLAYING;
- else if (!strcmp(value, "paused"))
- ret = STATUS_PAUSED;
- else if (!strcmp(value, "forward-seek"))
- ret = STATUS_FORWARD_SEEK;
- else if (!strcmp(value, "reverse-seek"))
- ret = STATUS_REVERSE_SEEK;
- else if (!strcmp(value, "error"))
- ret = STATUS_ERROR;
- else
- ret = STATUS_INVALID;
- }
- return ret;
-}
-
-int _bt_avrcp_control_get_property(int type, unsigned int *value)
-{
- GDBusProxy *proxy = NULL;
- char *name = NULL;
- int ret = BLUETOOTH_ERROR_NONE;
- GError *err = NULL;
- GVariant *reply = NULL;
- GVariant *temp = NULL;
-
- BT_CHECK_PARAMETER(value, return);
-
- proxy = __bt_get_control_properties_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_NOT_CONNECTED);
-
- reply = g_dbus_proxy_call_sync(proxy,
- "Get", g_variant_new("(ss)", BT_PLAYER_CONTROL_INTERFACE, __bt_media_type_to_str(type)),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
-
- g_object_unref(proxy);
-
- if (!reply) {
- BT_ERR("Can't get managed objects");
- if (err) {
- BT_ERR("%s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- } else {
- switch (type) {
- case EQUALIZER:
- case REPEAT:
- case SHUFFLE:
- case SCAN:
- case STATUS:
- name = (char *)g_variant_get_data(reply);
- if (name)
- *value = __bt_media_attrval_to_val(type, name);
- BT_INFO("Type[%s] and Value[%s]", __bt_media_type_to_str(type), name);
- break;
- case POSITION:
- g_variant_get(reply, "(v)", &temp);
- *value = g_variant_get_uint32(temp);
- g_variant_unref(temp);
- BT_INFO("Type[%s] and Value[%d]", __bt_media_type_to_str(type), *value);
- break;
- default:
- BT_ERR("Invalid Type [%d]", type);
- ret = BLUETOOTH_ERROR_INTERNAL;
- }
- }
- g_variant_unref(reply);
- return ret;
-}
-
-int _bt_avrcp_control_set_property(int type, unsigned int value)
-{
- GValue *attr_value = NULL;
- GDBusProxy *proxy = NULL;
- GError *error = NULL;
- GVariant *reply, *param;
-
- g_value_init(attr_value, G_TYPE_STRING);
-
- switch (type) {
- case EQUALIZER:
- param = g_variant_new("s", equalizer_status[value].property);
- BT_INFO("equalizer_status %s", equalizer_status[value].property);
- break;
- case REPEAT:
- param = g_variant_new("s", repeat_status[value].property);
- BT_INFO("repeat_status %s", repeat_status[value].property);
- break;
- case SHUFFLE:
- param = g_variant_new("s", shuffle_settings[value].property);
- BT_INFO("shuffle_settings %s", shuffle_settings[value].property);
- break;
- case SCAN:
- param = g_variant_new("s", scan_status[value].property);
- BT_INFO("scan_status %s", scan_status[value].property);
- break;
- default:
- BT_ERR("Invalid property type: %d", type);
- g_value_unset(attr_value);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- proxy = __bt_get_control_properties_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_NOT_CONNECTED);
-
- reply = g_dbus_proxy_call_sync(proxy,
- "Set", g_variant_new("(ssv)", BT_PLAYER_CONTROL_INTERFACE, __bt_media_type_to_str(type), param),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- g_object_unref(proxy);
- g_variant_unref(param);
-
- if (!reply) {
- BT_ERR("Can't get managed objects");
- if (error) {
- BT_ERR("SetProperty Fail: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- }
-
- g_variant_unref(reply);
- g_value_unset(attr_value);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-static int __bt_avrcp_control_parse_properties(
- media_metadata_attributes_t *metadata,
- GVariant *item)
-{
- GVariant *value = NULL;
- GVariantIter iter;
- char *value_string = NULL;
- unsigned int value_uint;
- const char *key = NULL;
-
- g_variant_iter_init(&iter, item);
- while (g_variant_iter_loop(&iter, "{sv}", &key, &value)) {
- if (strcasecmp(key, "Title") == 0) {
- value_string = (char *)g_variant_get_string(value, NULL);
- BT_DBG("Value : %s ", value_string);
- metadata->title = g_strdup(value_string);
- } else if (strcasecmp(key, "Artist") == 0) {
- value_string = (char *)g_variant_get_string(value, NULL);
- BT_DBG("Value : %s ", value_string);
- metadata->artist = g_strdup(value_string);
- } else if (strcasecmp(key, "Album") == 0) {
- value_string = (char *)g_variant_get_string(value, NULL);
- BT_DBG("Value : %s ", value_string);
- metadata->album = g_strdup(value_string);
- } else if (strcasecmp(key, "Genre") == 0) {
- value_string = (char *)g_variant_get_string(value, NULL);
- BT_DBG("Value : %s ", value_string);
- metadata->genre = g_strdup(value_string);
- } else if (strcasecmp(key, "Duration") == 0) {
- value_uint = g_variant_get_uint32(value);
- BT_DBG("Duration : %d", value_uint);
- metadata->duration = value_uint;
- } else if (strcasecmp(key, "NumberOfTracks") == 0) {
- value_uint = g_variant_get_uint32(value);
- metadata->total_tracks = value_uint;
- } else if (strcasecmp(key, "TrackNumber") == 0) {
- value_uint = g_variant_get_uint32(value);
- metadata->number = value_uint;
- } else
- BT_DBG("%s not supported, ignoring", key);
- }
-
- if (!metadata->title)
- metadata->title = g_strdup("");
- if (!metadata->artist)
- metadata->artist = g_strdup("");
- if (!metadata->album)
- metadata->album = g_strdup("");
- if (!metadata->genre)
- metadata->genre = g_strdup("");
-
- return BLUETOOTH_ERROR_NONE;
-
-}
-
-int _bt_avrcp_control_get_track_info(media_metadata_attributes_t *metadata)
-{
- GDBusProxy *proxy = NULL;
- GVariant *reply = NULL;
- GVariant *item = NULL;
- GError *err = NULL;
- GDBusConnection *conn = NULL;
- char *control_path = NULL;
- char *interface_name = NULL;
- char *property_name = NULL;
- GVariant *parameters = NULL;
- int ret = BLUETOOTH_ERROR_NONE;
-
- retv_if(metadata == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- control_path = __bt_get_control_device_path();
- retv_if(control_path == NULL, BLUETOOTH_ERROR_NOT_CONNECTED);
- BT_DBG("control_path %s", control_path);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, control_path,
- BT_PROPERTIES_INTERFACE, NULL, &err);
- if (proxy == NULL) {
- BT_ERR("Unable to allocate new proxy \n");
- if (err) {
- BT_ERR("%s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- interface_name = g_strdup(BT_PLAYER_CONTROL_INTERFACE);
- property_name = g_strdup("Track");
-
- parameters = g_variant_new("(ss)", interface_name, property_name);
-
- g_free(interface_name);
- g_free(property_name);
-
- reply = g_dbus_proxy_call_sync(proxy, "Get", parameters,
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
-
- g_object_unref(proxy);
-
- if (!reply) {
- BT_ERR("Error returned in method call");
- if (err) {
- BT_ERR("%s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(reply, "(v)", &item);
-
- ret = __bt_avrcp_control_parse_properties(metadata, item);
-
- g_variant_unref(reply);
- BT_DBG("-");
- return ret;
-}
-
-void _bt_handle_avrcp_control_event(GVariant *reply, const char *path)
-{
- GVariant *param = NULL;
- const char *property = NULL;
-
- if (!reply) {
- BT_ERR("Error returned in method call\n");
- return;
- }
-
- GVariantIter iter;
- GVariant *value = NULL;
- g_variant_iter_init(&iter, reply);
- while (g_variant_iter_loop(&iter, "{sv}", &property,
- &value)) {
- if ((strcasecmp(property, "Equalizer") == 0) ||
- (strcasecmp(property, "Repeat") == 0) ||
- (strcasecmp(property, "Shuffle") == 0) ||
- (strcasecmp(property, "Scan") == 0) ||
- (strcasecmp(property, "Status") == 0)) {
- const char *valstr;
- unsigned int type, val = 0;
-
- valstr = g_variant_get_string(value, NULL);
- BT_DBG("Value : %s ", valstr);
- type = __bt_media_attr_to_type(property);
- if (valstr)
- val = __bt_media_attrval_to_val(type, valstr);
-
- /* Send event to application */
- param = g_variant_new("(u)", val);
- _bt_send_event(BT_AVRCP_CONTROL_EVENT,
- __bt_media_attr_to_event(property), param);
- } else if (strcasecmp(property, "Position") == 0) {
- unsigned int val;
-
- val = g_variant_get_uint32(value);
- BT_DBG("Value : %d ", val);
-
- /* Send event to application */
- param = g_variant_new("(u)", val);
- _bt_send_event(BT_AVRCP_CONTROL_EVENT,
- __bt_media_attr_to_event(property), param);
- } else if (strcasecmp(property, "Track") == 0) {
- int ret = BLUETOOTH_ERROR_NONE;
- media_metadata_attributes_t metadata;
-
- memset(&metadata, 0x00, sizeof(media_metadata_attributes_t));
-
- ret = __bt_avrcp_control_parse_properties(
- &metadata, value);
- if (BLUETOOTH_ERROR_NONE != ret) {
- /* Free key and value because of break unless free not required */
- free((char *)property);
- g_variant_unref(value);
- g_free((char *)metadata.title);
- g_free((char *)metadata.artist);
- g_free((char *)metadata.album);
- g_free((char *)metadata.genre);
- break;
- }
-
- /* Send event to application */
- param = g_variant_new("(ssssuuu)",
- metadata.title,
- metadata.artist,
- metadata.album,
- metadata.genre,
- metadata.total_tracks,
- metadata.number,
- metadata.duration);
- _bt_send_event(BT_AVRCP_CONTROL_EVENT,
- BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED, param);
-
- g_free((char *)metadata.title);
- g_free((char *)metadata.artist);
- g_free((char *)metadata.album);
- g_free((char *)metadata.genre);
- } else {
- BT_DBG("Property not handled");
- }
- }
-
- BT_DBG("-");
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <gio/gio.h>
-#include <glib.h>
-#include <dlog.h>
-#include <string.h>
-#include <syspopup_caller.h>
-#include <dbus/dbus.h>
-
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-#include "bt-service-common.h"
-#include "bt-service-avrcp.h"
-#include "bt-service-event.h"
-#include "bt-service-util.h"
-#include "bt-service-audio.h"
-
-static bt_player_settinngs_t loopstatus_settings[] = {
- { REPEAT_INVALID, "" },
- { REPEAT_MODE_OFF, "None" },
- { REPEAT_SINGLE_TRACK, "Track" },
- { REPEAT_ALL_TRACK, "Playlist" },
- { REPEAT_INVALID, "" }
-};
-
-static bt_player_settinngs_t shuffle_settings[] = {
- { SHUFFLE_INVALID, "" },
- { SHUFFLE_MODE_OFF, "off" },
- { SHUFFLE_ALL_TRACK, "alltracks" },
- { SHUFFLE_GROUP, "group" },
- { SHUFFLE_INVALID, "" }
-};
-
-static bt_player_settinngs_t player_status[] = {
- { STATUS_STOPPED, "stopped" },
- { STATUS_PLAYING, "playing" },
- { STATUS_PAUSED, "paused" },
- { STATUS_FORWARD_SEEK, "forward-seek" },
- { STATUS_REVERSE_SEEK, "reverse-seek" },
- { STATUS_ERROR, "error" },
- { STATUS_INVALID, "" }
-};
-
-static guint avrcp_reg_id = 0;
-
-/* Introspection data exposed from bt-service */
-static const gchar bt_avrcp_bluez_introspection_xml[] =
-"<node name='/'>"
-" <interface name='org.freedesktop.DBus.Properties'>"
-" <method name='Set'>"
-" <arg type='s' name='interface' direction='in'/>"
-" <arg type='s' name='property' direction='in'/>"
-" <arg type='v' name='value' direction='in'/>"
-" </method>"
-" </interface>"
-"</node>";
-
-static gboolean __bt_media_emit_property_changed(GDBusConnection *connection,
- const char *path, const char *interface, const char *name,
- const GVariant *variant)
-{
- GVariantBuilder *builder = NULL;
- GError *error = NULL;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
- g_variant_builder_add(builder, "{sv}", name, variant);
-
- g_dbus_connection_emit_signal(connection, NULL, path,
- DBUS_INTERFACE_PROPERTIES,
- "PropertiesChanged",
- g_variant_new("(sa{sv})",
- interface, builder),
- &error);
-
- g_variant_builder_unref(builder);
- if (error) {
- BT_ERR("Could not Emit PropertiesChanged Signal: errCode[%x], message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- return FALSE;
- }
-
- return TRUE;
-}
-
-static GQuark __bt_avrcp_error_quark(void)
-{
- static GQuark quark = 0;
-
- if (!quark)
- quark = g_quark_from_static_string("bt-avrcp");
-
- return quark;
-}
-
-static GError *__bt_avrcp_set_error(bt_avrcp_error_t error)
-{
- BT_ERR("error[%d]\n", error);
-
- switch (error) {
- case BT_AVRCP_ERROR_INVALID_PARAM:
- return g_error_new(BT_AVRCP_ERROR, error,
- BT_ERROR_INVALID_PARAM);
- case BT_AVRCP_ERROR_INVALID_INTERFACE:
- return g_error_new(BT_AVRCP_ERROR, error,
- BT_ERROR_INVALID_INTERFACE);
- case BT_AVRCP_ERROR_INTERNAL:
- default:
- return g_error_new(BT_AVRCP_ERROR, error,
- BT_ERROR_INTERNAL);
- }
-}
-
-static void __bt_avrcp_agent_method(GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *method_name,
- GVariant *parameters,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
-{
- BT_DBG("+");
- BT_INFO("method %s", method_name);
- BT_INFO("object_path %s", object_path);
- int ret = BT_AVRCP_ERROR_NONE;
- GError *err = NULL;
- gboolean shuffle_status;
- guint32 status;
- gchar *interface = NULL;
- gchar *property = NULL;
- gchar *loop_status = NULL;
- GVariant *value = NULL;
-
- if (g_strcmp0(method_name, "Set") == 0) {
- g_variant_get(parameters, "(&s&sv)", &interface, &property,
- &value);
-
- if (g_strcmp0(interface, BT_MEDIA_PLAYER_INTERFACE) != 0) {
- ret = BT_AVRCP_ERROR_INVALID_INTERFACE;
- goto fail;
- }
- }
-
- if (value == NULL) {
- BT_ERR("value is NULL");
- goto fail;
- }
-
- BT_DBG("Property: %s\n", property);
- if (g_strcmp0(property, "Shuffle") == 0) {
-
- if (!g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN)) {
- BT_ERR("Error");
- ret = BT_AVRCP_ERROR_INVALID_PARAM;
- goto fail;
- }
-
- shuffle_status = g_variant_get_boolean(value);
- BT_DBG("Value: %s\n", shuffle_status ? "TRUE" : "FALSE");
- if (shuffle_status == TRUE)
- status = SHUFFLE_ALL_TRACK;
- else
- status = SHUFFLE_MODE_OFF;
-
- _bt_send_event(BT_AVRCP_EVENT,
- BLUETOOTH_EVENT_AVRCP_SETTING_SHUFFLE_STATUS,
- g_variant_new("(u)", status));
- } else if (g_strcmp0(property, "LoopStatus") == 0) {
-
- if (!g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
- BT_ERR("Error");
- ret = BT_AVRCP_ERROR_INVALID_PARAM;
- goto fail;
- }
-
- loop_status = (gchar *)g_variant_get_string(value, NULL);
- BT_DBG("Value: %s\n", loop_status);
-
- if (g_strcmp0(loop_status, "Track") == 0)
- status = REPEAT_SINGLE_TRACK;
- else if (g_strcmp0(loop_status, "Playlist") == 0)
- status = REPEAT_ALL_TRACK;
- else if (g_strcmp0(loop_status, "None") == 0)
- status = REPEAT_MODE_OFF;
- else
- status = REPEAT_INVALID;
-
- _bt_send_event(BT_AVRCP_EVENT,
- BLUETOOTH_EVENT_AVRCP_SETTING_REPEAT_STATUS,
- g_variant_new("(u)", status));
- }
-
- BT_DBG("-");
- return;
-
-fail:
- if (value)
- g_variant_unref(value);
- err = __bt_avrcp_set_error(ret);
- g_dbus_method_invocation_return_gerror(invocation, err);
- g_clear_error(&err);
- BT_INFO("-");
-}
-
-static const GDBusInterfaceVTable method_table = {
- __bt_avrcp_agent_method,
- NULL,
- NULL,
-};
-
-static GDBusNodeInfo *__bt_avrcp_create_method_node_info
- (const gchar *introspection_data)
-{
- GError *err = NULL;
- GDBusNodeInfo *node_info = NULL;
-
- if (introspection_data == NULL)
- return NULL;
-
- node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
-
- if (err) {
- BT_ERR("Unable to create node: %s", err->message);
- g_clear_error(&err);
- }
-
- return node_info;
-}
-
-int _bt_register_media_player(void)
-{
- BT_DBG("+");
- GDBusConnection *g_conn;
- gchar *adapter_path;
- gboolean shuffle_status;
- gchar *path;
- GDBusNodeInfo *node_info;
- GDBusProxy *proxy;
- GVariantBuilder *builder;
- GVariant *ret;
- GError *error = NULL;
-
- media_player_settings_t player_settings = {0,};
-
- player_settings.repeat = REPEAT_MODE_OFF;
- player_settings.status = STATUS_STOPPED;
- player_settings.position = 0;
- shuffle_status = FALSE;
-
- g_conn = _bt_gdbus_get_system_gconn();
- retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- node_info = __bt_avrcp_create_method_node_info(
- bt_avrcp_bluez_introspection_xml);
- if (node_info == NULL)
- return BLUETOOTH_ERROR_INTERNAL;
-
- avrcp_reg_id = g_dbus_connection_register_object(g_conn,
- BT_MEDIA_OBJECT_PATH,
- node_info->interfaces[0],
- &method_table,
- NULL, NULL, &error);
- g_dbus_node_info_unref(node_info);
-
- if (avrcp_reg_id == 0) {
- BT_ERR("Failed to register: %s", error->message);
- g_clear_error(&error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- adapter_path = _bt_get_adapter_path();
- retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- proxy = g_dbus_proxy_new_sync(g_conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, adapter_path,
- BT_MEDIA_INTERFACE, NULL, &error);
- g_free(adapter_path);
-
- if (proxy == NULL) {
- BT_ERR("Unable to create proxy");
- if (error) {
- BT_ERR("Error: %s", error->message);
- g_clear_error(&error);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
-
- g_variant_builder_add(builder, "{sv}", "LoopStatus",
- g_variant_new("s",
- loopstatus_settings[player_settings.repeat].property));
- BT_ERR("LoopStatus: %s", loopstatus_settings[player_settings.repeat].property);
-
- g_variant_builder_add(builder, "{sv}", "Shuffle",
- g_variant_new("b", shuffle_status));
-
- g_variant_builder_add(builder, "{sv}", "PlaybackStatus",
- g_variant_new("s",
- player_status[player_settings.status].property));
- BT_ERR("PlaybackStatus: %s", player_status[player_settings.status].property);
-
- g_variant_builder_add(builder, "{sv}", "Position",
- g_variant_new("u", player_settings.position));
-
- path = g_strdup(BT_MEDIA_OBJECT_PATH);
- ret = g_dbus_proxy_call_sync(proxy, "RegisterPlayer",
- g_variant_new("(oa{sv})", path, builder),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
-
- g_object_unref(proxy);
- g_free(path);
- g_variant_builder_unref(builder);
-
- if (ret == NULL) {
- BT_ERR("Call RegisterPlayer Failed");
- if (error) {
- BT_ERR("errCode[%x], message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_unref(ret);
- return BLUETOOTH_ERROR_NONE;
-}
-
-static void __bt_avrcp_unregister_object_path(void)
-{
- GDBusConnection *g_conn;
-
- g_conn = _bt_gdbus_get_system_gconn();
- ret_if(g_conn == NULL);
-
- if (avrcp_reg_id > 0) {
- g_dbus_connection_unregister_object(g_conn,
- avrcp_reg_id);
- avrcp_reg_id = 0;
- }
-}
-
-int _bt_unregister_media_player(void)
-{
- BT_DBG("+");
- GDBusConnection *g_conn;
- GDBusProxy *proxy;
- gchar *adapter_path;
- GVariant *ret;
- GError *error = NULL;
- gchar *path;
- int result = BLUETOOTH_ERROR_NONE;
-
- adapter_path = _bt_get_adapter_path();
- if (adapter_path == NULL) {
- result = BLUETOOTH_ERROR_INTERNAL;
- goto FAIL;
- }
-
- g_conn = _bt_gdbus_get_system_gconn();
- if (g_conn == NULL) {
- BT_ERR("g_conn is NULL");
- g_free(adapter_path);
- result = BLUETOOTH_ERROR_INTERNAL;
- goto FAIL;
- }
-
- proxy = g_dbus_proxy_new_sync(g_conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, adapter_path,
- BT_MEDIA_INTERFACE, NULL, &error);
- g_free(adapter_path);
-
- if (proxy == NULL) {
- BT_ERR("Unable to create proxy");
- if (error) {
- BT_ERR("Error: %s", error->message);
- g_clear_error(&error);
- }
- result = BLUETOOTH_ERROR_INTERNAL;
- goto FAIL;
- }
-
- path = g_strdup(BT_MEDIA_OBJECT_PATH);
- BT_DBG("path is [%s]", path);
-
- ret = g_dbus_proxy_call_sync(proxy, "UnregisterPlayer",
- g_variant_new("(o)", path),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
- g_free(path);
- g_object_unref(proxy);
-
- if (ret == NULL) {
- BT_ERR("UnregisterPlayer failed");
- if (error) {
- BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- result = BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_unref(ret);
-
-FAIL:
- __bt_avrcp_unregister_object_path();
-
- BT_DBG("-");
- return result;
-}
-
-int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data)
-{
- BT_DBG("+");
- char *interface = BT_MEDIA_PLAYER_INTERFACE;
- GDBusConnection *g_conn;
- GError *error = NULL;
- GVariantBuilder *builder = NULL;
- GVariantBuilder *inner_builder = NULL;
- GVariant *children[1];
- gboolean ret;
-
- retv_if(meta_data == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- g_conn = _bt_gdbus_get_system_gconn();;
- retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
- inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
-
- g_variant_builder_add(inner_builder, "{sv}",
- "xesam:title", g_variant_new_string(meta_data->title));
-
- children[0] = g_variant_new_string(meta_data->artist);
- g_variant_builder_add(inner_builder, "{sv}",
- "xesam:artist", g_variant_new_array(G_VARIANT_TYPE_STRING,
- children, 1));
-
- g_variant_builder_add(inner_builder, "{sv}",
- "xesam:album", g_variant_new_string(meta_data->album));
-
- children[0] = g_variant_new_string(meta_data->genre);
- g_variant_builder_add(inner_builder, "{sv}",
- "xesam:genre", g_variant_new_array(G_VARIANT_TYPE_STRING,
- children, 1));
-
- g_variant_builder_add(inner_builder, "{sv}",
- "xesam:totalTracks", g_variant_new_int32(meta_data->total_tracks));
-
- g_variant_builder_add(inner_builder, "{sv}",
- "xesam:trackNumber", g_variant_new_int32(meta_data->number));
-
- g_variant_builder_add(inner_builder, "{sv}",
- "mpris:length", g_variant_new_int64(meta_data->duration));
-
- g_variant_builder_add(builder, "{sv}",
- "Metadata", g_variant_new("a{sv}", inner_builder));
-
- ret = g_dbus_connection_emit_signal(g_conn, NULL, BT_MEDIA_OBJECT_PATH,
- DBUS_INTERFACE_PROPERTIES,
- "PropertiesChanged",
- g_variant_new("(sa{sv})",
- interface, builder),
- &error);
-
- g_variant_builder_unref(inner_builder);
- g_variant_builder_unref(builder);
-
- if (!ret) {
- if (error != NULL) {
- BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- }
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_avrcp_set_interal_property(int type, media_player_settings_t *properties)
-{
- BT_DBG("+");
- GDBusConnection *g_conn;
- int value;
- media_metadata_attributes_t meta_data;
- gboolean shuffle;
- GVariantBuilder *builder = NULL;
- GVariant *children[1];
-
- g_conn = _bt_gdbus_get_system_gconn();;
- retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- switch (type) {
- case REPEAT:
- value = properties->repeat;
- if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
- BT_MEDIA_PLAYER_INTERFACE, "LoopStatus",
- g_variant_new_string(loopstatus_settings[value].property))) {
- BT_ERR("Error sending the PropertyChanged signal \n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
- break;
- case SHUFFLE:
- value = properties->shuffle;
- if (g_strcmp0(shuffle_settings[value].property, "off") == 0)
- shuffle = FALSE;
- else
- shuffle = TRUE;
-
- if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
- BT_MEDIA_PLAYER_INTERFACE, "Shuffle",
- g_variant_new_boolean(shuffle))) {
- BT_ERR("Error sending the PropertyChanged signal \n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
- break;
- case STATUS:
- value = properties->status;
- if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
- BT_MEDIA_PLAYER_INTERFACE, "PlaybackStatus",
- g_variant_new_string(player_status[value].property))) {
- BT_ERR("Error sending the PropertyChanged signal \n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
- break;
- case POSITION:
- value = properties->position;
- if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
- BT_MEDIA_PLAYER_INTERFACE, "Position",
- g_variant_new_uint32(value))) {
- BT_ERR("Error sending the PropertyChanged signal \n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
- break;
- case METADATA:
- meta_data = properties->metadata;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
- g_variant_builder_add(builder, "{sv}",
- "xesam:title", g_variant_new_string(meta_data.title));
-
- children[0] = g_variant_new_string(meta_data.artist);
- g_variant_builder_add(builder, "{sv}",
- "xesam:artist", g_variant_new_array(G_VARIANT_TYPE_STRING,
- children, 1));
-
- g_variant_builder_add(builder, "{sv}",
- "xesam:album", g_variant_new_string(meta_data.album));
-
- children[0] = g_variant_new_string(meta_data.genre);
- g_variant_builder_add(builder, "{sv}",
- "xesam:genre", g_variant_new_array(G_VARIANT_TYPE_STRING,
- children, 1));
-
- g_variant_builder_add(builder, "{sv}",
- "xesam:totalTracks", g_variant_new_int32(meta_data.total_tracks));
-
- g_variant_builder_add(builder, "{sv}",
- "xesam:trackNumber", g_variant_new_int32(meta_data.number));
-
- g_variant_builder_add(builder, "{sv}",
- "mpris:length", g_variant_new_int64(meta_data.duration));
-
- if (!__bt_media_emit_property_changed(g_conn, BT_MEDIA_OBJECT_PATH,
- BT_MEDIA_PLAYER_INTERFACE, "Metadata",
- g_variant_new("a{sv}", builder))) {
- BT_ERR("Error sending the PropertyChanged signal \n");
- g_variant_builder_unref(builder);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_builder_unref(builder);
- break;
- default:
- BT_ERR("Invalid Type\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_avrcp_set_properties(media_player_settings_t *properties)
-{
- BT_DBG("+");
-
- if (_bt_avrcp_set_interal_property(REPEAT,
- properties) != BLUETOOTH_ERROR_NONE) {
- return BLUETOOTH_ERROR_INTERNAL;
- }
- if (_bt_avrcp_set_interal_property(SHUFFLE,
- properties) != BLUETOOTH_ERROR_NONE) {
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (_bt_avrcp_set_interal_property(STATUS,
- properties) != BLUETOOTH_ERROR_NONE) {
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (_bt_avrcp_set_interal_property(POSITION,
- properties) != BLUETOOTH_ERROR_NONE) {
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (_bt_avrcp_set_interal_property(METADATA,
- properties) != BLUETOOTH_ERROR_NONE) {
- return BLUETOOTH_ERROR_INTERNAL;
- }
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_avrcp_set_property(int type, unsigned int value)
-{
- BT_DBG("+");
- media_player_settings_t properties;
-
- switch (type) {
- case REPEAT:
- properties.repeat = value;
- break;
- case SHUFFLE:
- properties.shuffle = value;
- break;
- case STATUS:
- properties.status = value;
- break;
- case POSITION:
- properties.position = value;
- break;
- default:
- BT_DBG("Invalid Type\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (_bt_avrcp_set_interal_property(type,
- &properties) != BLUETOOTH_ERROR_NONE)
- return BLUETOOTH_ERROR_INTERNAL;
-
- BT_DBG("-");
-
- return BLUETOOTH_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <glib.h>
-#include <dlog.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <termios.h>
-#include <net_connection.h>
-#include <dbus/dbus.h>
-#include <glib.h>
-#include <dlog.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <termios.h>
-#include <net_connection.h>
-#include <bundle.h>
-#include <eventsystem.h>
-
-#include "bluetooth-api.h"
-#include "bt-service-common.h"
-#include "bt-service-agent.h"
-
-static GDBusConnection *system_conn;
-static GDBusConnection *session_conn;
-static GDBusProxy *manager_proxy;
-static GDBusProxy *adapter_proxy;
-static void *net_conn;
-
-static GDBusProxy *adapter_properties_proxy;
-
-GDBusConnection *_bt_gdbus_init_system_gconn(void)
-{
- GError *error = NULL;
-
- dbus_threads_init_default();
-
- if (system_conn != NULL)
- return system_conn;
-
- system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-
- if (!system_conn) {
- BT_ERR("Unable to connect to dbus: %s", error->message);
- g_clear_error(&error);
- }
-
- return system_conn;
-}
-
-GDBusConnection *_bt_gdbus_get_system_gconn(void)
-{
- GDBusConnection *local_system_gconn = NULL;
- GError *error = NULL;
-
- if (system_conn == NULL) {
- system_conn = _bt_gdbus_init_system_gconn();
- } else if (g_dbus_connection_is_closed(system_conn)) {
- local_system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-
- if (!local_system_gconn) {
- BT_ERR("Unable to connect to dbus: %s", error->message);
- g_clear_error(&error);
- }
-
- system_conn = local_system_gconn;
- }
-
- return system_conn;
-}
-
-GDBusConnection *_bt_gdbus_init_session_gconn(void)
-{
- GError *error = NULL;
-
- if (!g_thread_supported())
- g_thread_init(NULL);
-
- dbus_threads_init_default();
-
- if (session_conn != NULL)
- return session_conn;
-
- session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
-
- if (!session_conn) {
- BT_ERR("Unable to connect to dbus: %s", error->message);
- g_clear_error(&error);
- }
-
- return session_conn;
-}
-
-GDBusConnection *_bt_gdbus_get_session_gconn(void)
-{
- GDBusConnection *local_session_gconn = NULL;
- GError *error = NULL;
-
- if (session_conn == NULL) {
- session_conn = _bt_gdbus_init_session_gconn();
- } else if (g_dbus_connection_is_closed(session_conn)) {
- local_session_gconn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
-
- if (!local_session_gconn) {
- BT_ERR("Unable to connect to dbus: %s", error->message);
- g_clear_error(&error);
- }
-
- session_conn = local_session_gconn;
- }
-
- return session_conn;
-}
-
-static GDBusProxy *__bt_init_manager_proxy(void)
-{
- GDBusConnection *g_conn;
- GDBusProxy *proxy;
-
- dbus_threads_init_default();
-
- g_conn = _bt_gdbus_get_system_gconn();
- retv_if(g_conn == NULL, NULL);
-
- proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- BT_MANAGER_PATH, BT_MANAGER_INTERFACE, NULL, NULL);
-
- if (!proxy) {
- BT_ERR("Unable to get proxy");
- return NULL;
- }
-
- manager_proxy = proxy;
-
- return proxy;
-}
-
-static GDBusProxy *__bt_init_adapter_proxy(void)
-{
- GDBusConnection *g_conn;
- GDBusProxy *manager_proxy;
- GDBusProxy *proxy;
- char *adapter_path = NULL;
-
- dbus_threads_init_default();
-
- g_conn = _bt_gdbus_get_system_gconn();
- retv_if(g_conn == NULL, NULL);
-
- manager_proxy = _bt_get_manager_proxy();
- retv_if(manager_proxy == NULL, NULL);
-
- adapter_path = _bt_get_adapter_path();
- retv_if(adapter_path == NULL, NULL);
-
- proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- adapter_path, BT_ADAPTER_INTERFACE, NULL, NULL);
-
- g_free(adapter_path);
-
- retv_if(proxy == NULL, NULL);
-
- adapter_proxy = proxy;
-
- return proxy;
-}
-
-static GDBusProxy *__bt_init_adapter_properties_proxy(void)
-{
- GDBusConnection *g_conn;
- GDBusProxy *manager_proxy;
- GDBusProxy *proxy;
- char *adapter_path = NULL;
-
- dbus_threads_init_default();
-
- g_conn = _bt_gdbus_get_system_gconn();
- retv_if(g_conn == NULL, NULL);
-
- manager_proxy = _bt_get_manager_proxy();
- retv_if(manager_proxy == NULL, NULL);
-
- adapter_path = _bt_get_adapter_path();
- retv_if(adapter_path == NULL, NULL);
-
- proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- adapter_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
-
- g_free(adapter_path);
-
- retv_if(proxy == NULL, NULL);
-
- adapter_properties_proxy = proxy;
-
- return proxy;
-}
-
-GDBusProxy *_bt_get_manager_proxy(void)
-{
- if (manager_proxy) {
- const gchar *path = g_dbus_proxy_get_object_path(manager_proxy);
- if (path == NULL) {
- BT_ERR("Already proxy released hence creating new proxy");
- return __bt_init_manager_proxy();
- }
- return manager_proxy;
- }
- return __bt_init_manager_proxy();
-}
-
-static void *__bt_init_net_conn(void)
-{
- int result;
- connection_h connection = NULL;
-
- if (net_conn == NULL) {
- result = connection_create(&connection);
-
- if (result != CONNECTION_ERROR_NONE ||
- connection == NULL) {
- BT_DBG("connection_create() failed: %d", result);
- net_conn = NULL;
- return NULL;
- }
- net_conn = connection;
- }
- return net_conn;
-}
-
-void *_bt_get_net_conn(void)
-{
- return (net_conn) ? net_conn : __bt_init_net_conn();
-}
-
-GDBusProxy *_bt_get_adapter_proxy(void)
-{
- if (adapter_proxy) {
- const char *path = g_dbus_proxy_get_object_path(adapter_proxy);
- if (path == NULL) {
- BT_ERR("Already proxy released hence creating new proxy");
- return __bt_init_adapter_proxy();
- }
-
- return adapter_proxy;
- }
- return __bt_init_adapter_proxy();
-
-}
-
-GDBusProxy *_bt_get_adapter_properties_proxy(void)
-{
- return (adapter_properties_proxy) ? adapter_properties_proxy :
- __bt_init_adapter_properties_proxy();
-}
-
-static char *__bt_extract_adapter_path(GVariantIter *iter)
-{
- char *object_path = NULL;
- GVariantIter *interface_iter;
- GVariantIter *svc_iter;
- char *interface_str = NULL;
-
- /* Parse the signature: oa{sa{sv}}} */
- while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
- &interface_iter)) {
-
- if (object_path == NULL)
- continue;
-
- while (g_variant_iter_loop(interface_iter, "{&sa{sv}}",
- &interface_str, &svc_iter)) {
- if (g_strcmp0(interface_str, "org.bluez.Adapter1") != 0)
- continue;
-
- BT_DBG("Object Path: %s", object_path);
- g_variant_iter_free(svc_iter);
- g_variant_iter_free(interface_iter);
- return g_strdup(object_path);
- }
- }
- return NULL;
-}
-
-char *_bt_get_adapter_path(void)
-{
- GDBusConnection *conn;
- GDBusProxy *manager_proxy;
- GVariant *result = NULL;
- GVariantIter *iter = NULL;
- char *adapter_path = NULL;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, NULL);
-
- manager_proxy = _bt_get_manager_proxy();
- retv_if(manager_proxy == NULL, NULL);
-
- result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- NULL);
- if (!result) {
- BT_ERR("Can't get managed objects");
- return NULL;
- }
-
- /* signature of GetManagedObjects: a{oa{sa{sv}}} */
- g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
-
- adapter_path = __bt_extract_adapter_path(iter);
- g_variant_iter_free(iter);
- g_variant_unref(result);
- return adapter_path;
-}
-
-void _bt_deinit_bluez_proxy(void)
-{
- if (manager_proxy) {
- g_object_unref(manager_proxy);
- manager_proxy = NULL;
- }
-
- if (adapter_proxy) {
- g_object_unref(adapter_proxy);
- adapter_proxy = NULL;
- }
- if (adapter_properties_proxy) {
- g_object_unref(adapter_properties_proxy);
- adapter_properties_proxy = NULL;
- }
-}
-
-void _bt_deinit_proxys(void)
-{
- int ret;
- _bt_deinit_bluez_proxy();
-
- if (system_conn) {
- g_object_unref(system_conn);
- system_conn = NULL;
- }
-
- if (session_conn) {
- g_object_unref(session_conn);
- session_conn = NULL;
- }
-
- if (net_conn) {
- ret = connection_destroy(net_conn);
- net_conn = NULL;
- if (ret != 0)
- BT_ERR("connection_destroy failed : %d", ret);
- }
-}
-
-void _bt_convert_device_path_to_address(const char *device_path,
- char *device_address)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char *dev_addr;
-
- ret_if(device_path == NULL);
- ret_if(device_address == NULL);
-
- dev_addr = strstr(device_path, "dev_");
- if (dev_addr != NULL) {
- char *pos = NULL;
- dev_addr += 4;
- g_strlcpy(address, dev_addr, sizeof(address));
-
- while ((pos = strchr(address, '_')) != NULL)
- *pos = ':';
-
- g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE);
- }
-}
-
-
-void _bt_convert_addr_string_to_type(unsigned char *addr,
- const char *address)
-{
- int i;
- char *ptr = NULL;
-
- ret_if(address == NULL);
- ret_if(addr == NULL);
-
- for (i = 0; i < BT_ADDRESS_LENGTH_MAX; i++) {
- addr[i] = strtol(address, &ptr, 16);
- if (ptr[0] != '\0') {
- if (ptr[0] != ':')
- return;
-
- address = ptr + 1;
- }
- }
-}
-
-void _bt_convert_addr_string_to_secure_string(char *addr,
- const char *address)
-{
- int len;
-
- ret_if(address == NULL);
- ret_if(addr == NULL);
-
- len = strlen(address);
- ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
-
- strncpy(addr, address, len);
- addr[len] = '\0';
-
- addr[len-7] = 'X';
- addr[len-8] = 'X';
- addr[len-10] = 'X';
- addr[len-11] = 'X';
- addr[len-13] = 'X';
- addr[len-14] = 'X';
- addr[len-16] = 'X';
- addr[len-17] = 'X';
-
- return;
-}
-
-void _bt_convert_addr_type_to_string(char *address,
- unsigned char *addr)
-{
- ret_if(address == NULL);
- ret_if(addr == NULL);
-
- snprintf(address, BT_ADDRESS_STRING_SIZE,
- "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
- addr[0], addr[1], addr[2],
- addr[3], addr[4], addr[5]);
-}
-
-void _bt_print_device_address_t(const bluetooth_device_address_t *addr)
-{
- BT_DBG("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", addr->addr[0], addr->addr[1], addr->addr[2],
- addr->addr[3], addr->addr[4], addr->addr[5]);
-}
-
-void _bt_divide_device_class(bluetooth_device_class_t *device_class,
- unsigned int cod)
-{
- ret_if(device_class == NULL);
-
- device_class->major_class = (unsigned short)(cod & 0x00001F00) >> 8;
- device_class->minor_class = (unsigned short)((cod & 0x000000FC));
- device_class->service_class = (unsigned long)((cod & 0x00FF0000));
-
- if (cod & 0x002000) {
- device_class->service_class |=
- BLUETOOTH_DEVICE_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE;
- }
-}
-
-void _bt_free_device_info(bt_remote_dev_info_t *dev_info)
-{
- int i;
-
- ret_if(dev_info == NULL);
-
- g_free(dev_info->address);
- g_free(dev_info->name);
- g_free(dev_info->manufacturer_data);
-
- if (dev_info->uuids) {
- for (i = 0; i < dev_info->uuid_count && dev_info->uuids[i]; i++)
- g_free(dev_info->uuids[i]);
-
- g_free(dev_info->uuids);
- }
-
- g_free(dev_info);
-}
-
-void _bt_free_le_device_info(bt_remote_le_dev_info_t *le_dev_info)
-{
- ret_if(le_dev_info == NULL);
-
- g_free(le_dev_info->adv_data);
- g_free(le_dev_info);
-}
-
-int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length)
-{
- int i;
- const char *p = src;
- char *next;
- int count;
-
- if (dest == NULL || src == NULL)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- BT_DBG("+src : %s", src);
- BT_DBG("+dest : %s", dest);
-
- i = 0;
- while (*p != '\0' && i < length) {
- next = g_utf8_next_char(p);
- count = next - p;
-
- while (count > 0 && ((i + count) < length)) {
- dest[i++] = *p;
- p++;
- count--;
- }
- p = next;
- }
- return BLUETOOTH_ERROR_NONE;
-}
-
-gboolean _bt_utf8_validate(char *name)
-{
- BT_DBG("+");
- gunichar2 *u16;
- glong items_written = 0;
-
- if (FALSE == g_utf8_validate(name, -1, NULL))
- return FALSE;
-
- u16 = g_utf8_to_utf16(name, -1, NULL, &items_written, NULL);
- if (u16 == NULL)
- return FALSE;
-
- g_free(u16);
-
- if (items_written != g_utf8_strlen(name, -1))
- return FALSE;
-
- BT_DBG("-");
- return TRUE;
-}
-
-int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd)
-{
- BT_DBG("+");
- if (!_bt_agent_register_osp_server(type, uuid, path, fd))
- return BLUETOOTH_ERROR_INTERNAL;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_unregister_osp_server_in_agent(int type, char *uuid)
-{
- BT_DBG("+");
- if (!_bt_agent_unregister_osp_server(type, uuid))
- return BLUETOOTH_ERROR_INTERNAL;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_set_socket_non_blocking(int socket_fd)
-{
- /* Set Nonblocking */
- long arg;
-
- arg = fcntl(socket_fd, F_GETFL);
-
- if (arg < 0)
- return -errno;
-
- if (arg & O_NONBLOCK)
- BT_ERR("Already Non-blocking \n");
-
- arg |= O_NONBLOCK;
-
- if (fcntl(socket_fd, F_SETFL, arg) < 0)
- return -errno;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_set_non_blocking_tty(int sk)
-{
- struct termios ti = {0,};
- int err;
-
- err = _bt_set_socket_non_blocking(sk);
-
- if (err < 0) {
- BT_ERR("Error in set non blocking!\n");
- return err;
- }
-
- tcflush(sk, TCIOFLUSH);
-
- /* Switch tty to RAW mode */
- cfmakeraw(&ti);
- tcsetattr(sk, TCSANOW, &ti);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-static char *__bt_extract_device_path(GVariantIter *iter, char *address)
-{
- char *object_path = NULL;
- char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
-
- /* Parse the signature: oa{sa{sv}}} */
- while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path,
- NULL)) {
- if (!object_path) {
- BT_ERR("Unable to get object path");
- return NULL;
- }
- _bt_convert_device_path_to_address(object_path, device_address);
- if (g_strcmp0(address, device_address) == 0)
- return g_strdup(object_path);
-
- }
-
- BT_ERR("Unable to get object path");
- return NULL;
-}
-
-char *_bt_get_device_object_path(char *address)
-{
- char *object_path = NULL;
- GDBusConnection *conn;
- GDBusProxy *manager_proxy;
- GVariant *result = NULL;
- GVariantIter *iter = NULL;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, NULL);
-
- manager_proxy = _bt_get_manager_proxy();
- retv_if(manager_proxy == NULL, NULL);
-
- result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- NULL);
- if (!result) {
- BT_ERR("Can't get managed objects");
- return NULL;
- }
-
- /* signature of GetManagedObjects: a{oa{sa{sv}}} */
- g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
- object_path = __bt_extract_device_path(iter, address);
- g_variant_iter_free(iter);
- g_variant_unref(result);
- return object_path;
-}
-
-char *_bt_get_profile_uuid128(bt_profile_type_t profile_type)
-{
- switch (profile_type) {
- case BT_PROFILE_CONN_RFCOMM:
- return strdup(RFCOMM_UUID_STR);
- case BT_PROFILE_CONN_A2DP:
- return strdup(A2DP_SINK_UUID);
- case BT_PROFILE_CONN_A2DP_SINK:
- return strdup(A2DP_SOURCE_UUID);
- case BT_PROFILE_CONN_HSP:
- return strdup(HFP_HS_UUID);
- case BT_PROFILE_CONN_HID:
- return strdup(HID_UUID);
- case BT_PROFILE_CONN_NAP:
- return strdup(NAP_UUID);
- case BT_PROFILE_CONN_HFG:
- return strdup(HFP_AG_UUID);
- case BT_PROFILE_CONN_PBAP:
- return strdup(PBAP_UUID);
- case BT_PROFILE_CONN_GATT:
- case BT_PROFILE_CONN_ALL: /* NULL UUID will connect to both the audio profiles*/
- default:
- return NULL;
- };
-}
-
-const char *_bt_convert_uuid_to_string(const char *uuid)
-{
-#define SHORT_UUID_COUNT 199
-#define LONG_UUID_COUNT 17
-
- if (!uuid)
- return NULL;
-
- int offset = 0;
- int uuid_len = 4;
- typedef struct {
- const char *uuid;
- const char *specification_name;
- } uuid_name_s;
- static uuid_name_s short_uuid_name[SHORT_UUID_COUNT] = {
- // List should be sorted by UUID
- /* BT Classic Services */
- {"1101", "Serial Port Service"},
- {"1102", "LAN Access Using PPP Service"},
- {"1103", "Dialup Networking Service"},
- {"1104", "IrMCSync Service"},
- {"1105", "OBEX Object Push Service"},
- {"1106", "OBEX File Transfer Service"},
- {"1107", "IrMC Sync Command Service"},
- {"1108", "Headset Service"},
- {"1109", "Cordless Telephony Service"},
- {"110A", "Audio Source Service"},
- {"110B", "Audio Sink Service"},
- {"110C", "AV Remote Control Target Service"},
- {"110D", "Advanced Audio Distribution Profile"},
- {"110E", "AV Remote Control Service"},
- {"110F", "Video Conferencing Service"},
- {"1110", "Intercom Service"},
- {"1111", "Fax Service"},
- {"1112", "Headset Audio Gateway Service"},
- {"1113", "WAP Service"},
- {"1114", "WAP Client Service"},
- {"1115", "PANU Service"},
- {"1116", "NAP Service"},
- {"1117", "GN Service"},
- {"1118", "Direct Printing Service"},
- {"1119", "Reference Printing Service"},
- {"111A", "Basic Imaging Profile"},
- {"111B", "Imaging Responder Service"},
- {"111C", "Imaging Automatic Archive Service"},
- {"111D", "Imaging Reference Objects Service"},
- {"111E", "Handsfree Service"},
- {"111F", "Handsfree Audio Gateway Service"},
- {"1120", "Direct Printing Reference Objects Service"},
- {"1121", "Reflected UI Service"},
- {"1122", "Basic Printing Profile"},
- {"1123", "Printing Status Service"},
- {"1124", "Human Interface Device Service"},
- {"1125", "Hardcopy Cable Replacement Profile"},
- {"1126", "HCR Print Service"},
- {"1127", "HCR Scan Service"},
- {"112D", "SIM Access Service"},
- {"112E", "Phonebook Access PCE Service"},
- {"112F", "Phonebook Access PSE Service"},
- {"1130", "Phonebook Access Profile"},
- {"1132", "Message Access Server Service"},
- {"1133", "Message Notification Server Service"},
- {"1134", "Message Access Profile"},
- {"1200", "PnP Information Service"},
- {"1201", "Generic Networking Service"},
- {"1202", "Generic File Transfer Service"},
- {"1203", "Generic Audio Service"},
- {"1204", "Generic Telephony Service"},
- {"1205", "UPnP Service"},
- {"1206", "UPnP Ip Service"},
- {"1303", "Video Source Service"},
- {"1304", "Video Sink Service"},
- {"1305", "Video Distribution Profile"},
- {"1400", "Health Device Profile"},
- {"1401", "HDP Source Service"},
- {"1402", "HDP Sink Service"},
-
- /* GATT Services */
- {"1800", "Generic Access"},
- {"1801", "Generic Attribute"},
- {"1802", "Immediate Alert"},
- {"1803", "Link Loss"},
- {"1804", "Tx Power"},
- {"1805", "Current Time Service"},
- {"1806", "Reference Time Update Service"},
- {"1807", "Next DST Change Service"},
- {"1808", "Glucose"},
- {"1809", "Health Thermometer"},
- {"180A", "Device Information"},
- {"180D", "Heart Rate"},
- {"180F", "Battery Service"},
- {"1810", "Blood Pressure"},
- {"1811", "Alert Notification Service"},
- {"1812", "Human Interface Device"},
- {"1813", "Scan Parameters"},
- {"1814", "Running Speed and Cadence"},
- {"1815", "Automation IO"},
- {"1816", "Cycling Speed and Cadence"},
- {"1818", "Cycling Power"},
- {"1819", "Location and Navigation"},
- {"181A", "Environmental Sensing"},
- {"181B", "Body Composition"},
- {"181C", "User Data"},
- {"181D", "Weight Scale"},
- {"181E", "Bond Management"},
- {"181F", "Continuous Glucose Monitoring"},
- {"1820", "Internet Protocol Support Service"},
- {"1821", "Indoor Positioning"},
- {"1822", "Pulse Oximeter Service"},
- {"1823", "HTTP Proxy"},
- {"1824", "Transport Discovery"},
- {"1825", "Object Transfer Service"},
- {"1826", "Fitness Machine"},
- {"1827", "Mesh Provisioning Service"},
- {"1828", "Mesh Proxy Service"},
- {"1829", "Reconnection Configuration"},
- {"183A", "Insulin Delivery"},
-
- /* GATT Declarations */
- {"2800", "Primary Service Declaration"},
- {"2801", "Secondary Service Declaration"},
- {"2802", "Include Declaration"},
- {"2803", "Characteristic Declaration"},
-
- /* GATT Descriptors */
- {"2900", "Characteristic Extended Properties"},
- {"2901", "Characteristic User Description"},
- {"2902", "Client Characteristic Configuration"},
- {"2903", "Server Characteristic Configuration"},
- {"2904", "Characteristic Format"},
- {"2905", "Characteristic Aggregate Formate"},
- {"2906", "Valid Range"},
- {"2907", "External Report Reference"},
- {"2908", "Report Reference"},
-
- /* GATT Characteristics */
- {"2A00", "Device Name"},
- {"2A01", "Appearance"},
- {"2A02", "Peripheral Privacy Flag"},
- {"2A03", "Reconnection Address"},
- {"2A04", "Peripheral Preferred Connection Parameters"},
- {"2A05", "Service Changed"},
- {"2A06", "Alert Level"},
- {"2A07", "Tx Power Level"},
- {"2A08", "Date Time"},
- {"2A09", "Day of Week"},
- {"2A0A", "Day Date Time"},
- {"2A11", "Time with DST"},
- {"2A12", "Time Accuracy"},
- {"2A13", "Time Source"},
- {"2A14", "Reference Time Information"},
- {"2A16", "Time Update Control Point"},
- {"2A17", "Time Update State"},
- {"2A18", "Glucose Measurement"},
- {"2A19", "Battery Level"},
- {"2A1C", "Temperature Measurement"},
- {"2A1D", "Temperature Type"},
- {"2A1E", "Intermediate Temperature"},
- {"2A21", "Measurement Interval"},
- {"2A23", "System ID"},
- {"2A24", "Model Number String"},
- {"2A25", "Serial Number String"},
- {"2A26", "Firmware Revision String"},
- {"2A27", "Hardware Revision String"},
- {"2A28", "Software Revision String"},
- {"2A29", "Manufacturer Name String"},
- {"2A2A", "IEEE 11073-20601 Regulatory Certification Data List"},
- {"2A2B", "Current Time"},
- {"2A34", "Glucose Measurement Context"},
- {"2A35", "Blood Pressure Measurement"},
- {"2A37", "Heart Rate Measurement"},
- {"2A38", "Body Sensor Location"},
- {"2A39", "Heart Rate Control Point"},
- {"2A3F", "Alert Status"},
- {"2A46", "New Alert"},
- {"2A49", "Blood Pressure Feature"},
- {"2A4A", "HID Information"},
- {"2A4C", "HID Control Point"},
- {"2A50", "PnP ID"},
- {"2A51", "Glucose Feature"},
- {"2A52", "Record Access Control Point"},
- {"2A53", "RSC Measurement"},
- {"2A54", "RSC Feature"},
- {"2A55", "SC Control Point"},
- {"2A56", "Digital"},
- {"2A58", "Analog"},
- {"2A5A", "Aggregate"},
- {"2A5B", "CSC Measurement"},
- {"2A5C", "CSC Feature"},
- {"2A5D", "Sensor Location"},
- {"2A63", "Cycling Power Measurement"},
- {"2A64", "Cycling Power Vector"},
- {"2A65", "Cycling Power Feature"},
- {"2A66", "Cycling Power Control Point"},
- {"2A67", "Location and Speed"},
- {"2A68", "Navigation"},
- {"2A6D", "Pressure"},
- {"2A6E", "Temperature"},
- {"2A8E", "Height"},
- {"2A90", "Last Name"},
- {"2A91", "Maximum Recommended Heart Rate"},
- {"2A92", "Resting Heart Rate"},
- {"2A98", "Weight"},
- {"2A9B", "Body Composition Feature"},
- {"2A9C", "Body Composition Measurement"},
- {"2A9D", "Weight Measurement"},
- {"2AA2", "Language"},
- {"2AA4", "Bond Management Control Point"},
- {"2AA5", "Bond Management Features"},
- {"2AA6", "Central Address Resolution"},
- {"2AAD", "Indoor Positioning Configuration"},
- {"2AB5", "Location Name"},
- {"2AB6", "URI"},
- {"2ABC", "TDS Control Point"},
- {"2AC9", "Resolvable Private Address Only"},
- {"2ACC", "Fitness Machine Feature"},
- {"2ACE", "Cross Trainer Data"},
- {"2AD3", "Training Status"},
- {"2AD7", "Supported Heart Rate Range"},
- {"2AD9", "Fitness Machine Control Point"},
- {"2ADA", "Fitness Machine Status"},
- {"2B1D", "RC Feature"},
- {"2B1E", "RC Settings"},
- {"2B1F", "Reconnection Configuration Control Point"},
- };
- static uuid_name_s long_uuid_name[LONG_UUID_COUNT] = {
- // List should be sorted by UUID
- /* Custom uuids */
- {"1AB7C24D-185A-45B9-90D4-F7AB1A71949A", "Samsung Health Service"},
- {"22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB", "Data Source"},
- {"2F7CABCE-808D-411F-9A0C-BB92BA96C102", "Entity Update"},
- {"32D1955A-E5AA-4A96-9A49-08538DA8B8F6", "Samsung Gear Fit Manager Service"},
- {"69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9", "Control Point"},
- {"7905F431-B5CE-4E99-A40F-4B1E122D00D0", "Apple Notification Center Service"},
- {"89D3502B-0F36-433A-8EF4-C502AD55F8DC", "Apple Media Service"},
- {"9A3F68E0-86CE-11E5-A309-0002A5D5C51B", "Samsung Gear Manager Service"},
- {"9B3C81D8-57B1-4A8A-B8DF-0E56F7CA51C2", "Remote Command"},
- {"9FBF120D-6301-42D9-8C58-25E699A21DBD", "Notifications Source"},
- {"A49EB41E-CB06-495C-9F4F-BB80A90CDF00", "Samsung Gear Manager Service"},
- {"ADE3D529-C784-4F63-A987-EB69F70EE816", "IoT OIC Service"},
- {"C2051EE0-804D-4D50-A12C-15E243852100", "Notifications Source"},
- {"C2F2CC0F-C085-4DD4-BE5A-ACA3074BBC72", "Control Point"},
- {"C6B2F38C-23AB-46D8-A6AB-A3A870BBD5D7", "Entity Attribute"},
- {"CECE518B-28D7-4171-92D5-76A1E249A3B9", "Notifications Source"},
- {"FE53FF98-B259-4337-B56A-0EC9F82C6BAD", "Control Point"},
- };
- const uuid_name_s *uuid_name = short_uuid_name;
- static const char *unknown_name = "Unknown";
- int start = 0;
- int end = SHORT_UUID_COUNT - 1;
- int p;
- int ret;
-
- if (strlen(uuid) == 36) {
- if (!g_ascii_strncasecmp(uuid + 9, "0000-1000-8000-00805F9B34FB", 27))
- offset = 4;
- else {
- offset = 0;
- uuid_len = 36;
- end = LONG_UUID_COUNT - 1;
- uuid_name = long_uuid_name;
- }
- } else if (strlen(uuid) >= 8)
- offset = 4;
-
- while (start <= end) {
- p = start + (end - start) / 2;
- ret = g_ascii_strncasecmp(uuid + offset, uuid_name[p].uuid, uuid_len);
- if (ret == 0)
- return uuid_name[p].specification_name;
- else if (ret < 0)
- end = p - 1;
- else
- start = p + 1;
- }
-
- return unknown_name;
-}
-
-const char *_bt_convert_error_to_string(int error)
-{
- switch (error) {
- case BLUETOOTH_ERROR_CANCEL:
- return "CANCELLED";
- case BLUETOOTH_ERROR_INVALID_PARAM:
- return "INVALID_PARAMETER";
- case BLUETOOTH_ERROR_INVALID_DATA:
- return "INVALID DATA";
- case BLUETOOTH_ERROR_MEMORY_ALLOCATION:
- case BLUETOOTH_ERROR_OUT_OF_MEMORY:
- return "OUT_OF_MEMORY";
- case BLUETOOTH_ERROR_TIMEOUT:
- return "TIMEOUT";
- case BLUETOOTH_ERROR_NO_RESOURCES:
- return "NO_RESOURCES";
- case BLUETOOTH_ERROR_INTERNAL:
- return "INTERNAL";
- case BLUETOOTH_ERROR_NOT_SUPPORT:
- return "NOT_SUPPORT";
- case BLUETOOTH_ERROR_DEVICE_NOT_ENABLED:
- return "NOT_ENABLED";
- case BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED:
- return "ALREADY_ENABLED";
- case BLUETOOTH_ERROR_DEVICE_BUSY:
- return "DEVICE_BUSY";
- case BLUETOOTH_ERROR_ACCESS_DENIED:
- return "ACCESS_DENIED";
- case BLUETOOTH_ERROR_MAX_CLIENT:
- return "MAX_CLIENT";
- case BLUETOOTH_ERROR_NOT_FOUND:
- return "NOT_FOUND";
- case BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR:
- return "SERVICE_SEARCH_ERROR";
- case BLUETOOTH_ERROR_PARING_FAILED:
- return "PARING_FAILED";
- case BLUETOOTH_ERROR_NOT_PAIRED:
- return "NOT_PAIRED";
- case BLUETOOTH_ERROR_SERVICE_NOT_FOUND:
- return "SERVICE_NOT_FOUND";
- case BLUETOOTH_ERROR_NOT_CONNECTED:
- return "NOT_CONNECTED";
- case BLUETOOTH_ERROR_ALREADY_CONNECT:
- return "ALREADY_CONNECT";
- case BLUETOOTH_ERROR_CONNECTION_BUSY:
- return "CONNECTION_BUSY";
- case BLUETOOTH_ERROR_CONNECTION_ERROR:
- return "CONNECTION_ERROR";
- case BLUETOOTH_ERROR_MAX_CONNECTION:
- return "MAX_CONNECTION";
- case BLUETOOTH_ERROR_NOT_IN_OPERATION:
- return "NOT_IN_OPERATION";
- case BLUETOOTH_ERROR_CANCEL_BY_USER:
- return "CANCEL_BY_USER";
- case BLUETOOTH_ERROR_REGISTRATION_FAILED:
- return "REGISTRATION_FAILED";
- case BLUETOOTH_ERROR_IN_PROGRESS:
- return "IN_PROGRESS";
- case BLUETOOTH_ERROR_AUTHENTICATION_FAILED:
- return "AUTHENTICATION_FAILED";
- case BLUETOOTH_ERROR_HOST_DOWN:
- return "HOST_DOWN";
- case BLUETOOTH_ERROR_END_OF_DEVICE_LIST:
- return "END_OF_DEVICE_LIST";
- case BLUETOOTH_ERROR_AGENT_ALREADY_EXIST:
- return "AGENT_ALREADY_EXIST";
- case BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST:
- return "AGENT_DOES_NOT_EXIST";
- case BLUETOOTH_ERROR_ALREADY_INITIALIZED:
- return "ALREADY_INITIALIZED";
- case BLUETOOTH_ERROR_PERMISSION_DEINED:
- return "PERMISSION_DEINED";
- case BLUETOOTH_ERROR_ALREADY_DEACTIVATED:
- return "ALREADY_DEACTIVATED";
- case BLUETOOTH_ERROR_NOT_INITIALIZED:
- return "NOT_INITIALIZED";
- case BLUETOOTH_ERROR_AUTHENTICATION_REJECTED:
- return "AUTHENTICATION REJECTED";
- case BLUETOOTH_ERROR_AUTHORIZATION_REJECTED:
- return "AUTHORIZATION REJECTED";
- default:
- return "UNKNOWN";
- }
-}
-
-const char *_bt_convert_disc_reason_to_string(int reason)
-{
- switch (reason) {
- case (int)BLUETOOTH_ERROR_PAGE_TIMEOUT:
- return "Page timeout";
- case (int)BLUETOOTH_ERROR_AUTH_FAILURE:
- return "Authentication Failure";
- case (int)BLUETOOTH_ERROR_PIN_OR_KEY_MISSING:
- return "PIN or Key missing";
- case (int)BLUETOOTH_ERROR_CONNECTION_TIMEOUT:
- return "Link loss";
- case (int)BLUETOOTH_ERROR_CONNECTION_REJECTED_DUE_TO_SECURITY_REASONS:
- return "Connection rejected due to security reasons";
- case (int)BLUETOOTH_ERROR_REMOTE_USER_TERM:
- case (int)BLUETOOTH_ERROR_REMOTE_LOW_RESOURCES:
- case (int)BLUETOOTH_ERROR_REMOTE_POWER_OFF:
- return "Remote user terminated connection";
- case (int)BLUETOOTH_ERROR_LOCAL_HOST_TERM:
- return "Connection terminated by local host";
- case (int)BLUETOOTH_ERROR_REPEATED_ATTEMPTS:
- return "Repeated attempts";
- case (int)BLUETOOTH_ERROR_LMP_RESPONSE_TIMEOUT:
- return "LMP response timeout";
- case (int)BLUETOOTH_ERROR_LMP_TRANSACTION_COLLISION:
- return "LMP transaction collision";
- case (int)BLUETOOTH_ERROR_INSTANT_PASSED:
- return "Instant passed";
- case (int)BLUETOOTH_ERROR_INSUFFICIENT_SECURITY:
- return "Insufficient security";
- case (int)BLUETOOTH_ERROR_CONNECTION_TERMINATED_DUE_TO_MIC_FAILURE:
- return "Connection terminated due to MIC failure";
- case (int)BLUETOOTH_ERROR_CONNECTION_FAILED_TO_BE_ESTABLISHED:
- return "Connection failed to be established";
- default:
- return "Unknown";
- }
-}
-
-const char *_bt_convert_profile_state_to_string(bt_profile_state_t state)
-{
- switch (state) {
- case BT_PROFILE_STATE_UNAVAILABLE:
- return "UNAVAILABLE";
- case BT_PROFILE_STATE_DISCONNECTED:
- return "DISCONNECTED";
- case BT_PROFILE_STATE_CONNECTING:
- return "CONNECTING";
- case BT_PROFILE_STATE_CONNECTED:
- return "CONNECTED";
- case BT_PROFILE_STATE_DISCONNECTING:
- return "DISCONNECTING";
- }
-
- return NULL;
-}
-
-const char *_bt_convert_service_function_to_string(int function)
-{
- int i;
-
- typedef struct {
- int function;
- const char *function_name;
- } bt_function_name_t;
-
- const bt_function_name_t bt_functions[] = {
- {BT_CHECK_ADAPTER, "BT_CHECK_ADAPTER"},
- {BT_ENABLE_ADAPTER, "BT_ENABLE_ADAPTER"},
- {BT_DISABLE_ADAPTER, "BT_DISABLE_ADAPTER"},
- {BT_RECOVER_ADAPTER, "BT_RECOVER_ADAPTER"},
- {BT_SET_DISCOVERABLE_TIME, "BT_SET_DISCOVERABLE_TIME"},
- {BT_GET_DISCOVERABLE_TIME, "BT_GET_DISCOVERABLE_TIME"},
- {BT_IGNORE_AUTO_PAIRING, "BT_IGNORE_AUTO_PAIRING"},
- {BT_GET_LOCAL_ADDRESS, "BT_GET_LOCAL_ADDRESS"},
- {BT_GET_LOCAL_VERSION, "BT_GET_LOCAL_VERSION"},
- {BT_GET_LOCAL_NAME, "BT_GET_LOCAL_NAME"},
- {BT_SET_LOCAL_NAME, "BT_SET_LOCAL_NAME"},
- {BT_IS_SERVICE_USED, "BT_IS_SERVICE_USED"},
- {BT_GET_DISCOVERABLE_MODE, "BT_GET_DISCOVERABLE_MODE"},
- {BT_SET_DISCOVERABLE_MODE, "BT_SET_DISCOVERABLE_MODE"},
- {BT_START_DISCOVERY, "BT_START_DISCOVERY"},
- {BT_START_CUSTOM_DISCOVERY, "BT_START_CUSTOM_DISCOVERY"},
- {BT_CANCEL_DISCOVERY, "BT_CANCEL_DISCOVERY"},
- {BT_START_LE_DISCOVERY, "BT_START_LE_DISCOVERY"},
- {BT_STOP_LE_DISCOVERY, "BT_STOP_LE_DISCOVERY"},
- {BT_IS_DISCOVERYING, "BT_IS_DISCOVERYING"},
- {BT_IS_LE_DISCOVERYING, "BT_IS_LE_DISCOVERYING"},
- {BT_ENABLE_RSSI, "BT_ENABLE_RSSI"},
- {BT_GET_RSSI, "BT_GET_RSSI"},
- {BT_IS_CONNECTABLE, "BT_IS_CONNECTABLE"},
- {BT_SET_CONNECTABLE, "BT_SET_CONNECTABLE"},
- {BT_GET_BONDED_DEVICES, "BT_GET_BONDED_DEVICES"},
- {BT_RESET_ADAPTER, "BT_RESET_ADAPTER"},
- {BT_SET_ADVERTISING, "BT_SET_ADVERTISING"},
- {BT_SET_CUSTOM_ADVERTISING, "BT_SET_CUSTOM_ADVERTISING"},
- {BT_SET_ADVERTISING_PARAMETERS, "BT_SET_ADVERTISING_PARAMETERS"},
- {BT_GET_ADVERTISING_DATA, "BT_GET_ADVERTISING_DATA"},
- {BT_SET_ADVERTISING_DATA, "BT_SET_ADVERTISING_DATA"},
- {BT_SET_SCAN_PARAMETERS, "BT_SET_SCAN_PARAMETERS"},
- {BT_SET_SCAN_TYPE, "BT_SET_SCAN_TYPE"},
- {BT_GET_SCAN_RESPONSE_DATA, "BT_GET_SCAN_RESPONSE_DATA"},
- {BT_SET_SCAN_RESPONSE_DATA, "BT_SET_SCAN_RESPONSE_DATA"},
- {BT_IS_ADVERTISING, "BT_IS_ADVERTISING"},
- {BT_SET_MANUFACTURER_DATA, "BT_SET_MANUFACTURER_DATA"},
- {BT_LE_CONN_UPDATE, "BT_LE_CONN_UPDATE"},
- {BT_LE_READ_MAXIMUM_DATA_LENGTH, "BT_LE_READ_MAXIMUM_DATA_LENGTH"},
- {BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH, "BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH"},
- {BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH, "BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH"},
- {BT_LE_SET_DATA_LENGTH, "BT_LE_SET_DATA_LENGTH"},
- {BT_ADD_WHITE_LIST, "BT_ADD_WHITE_LIST"},
- {BT_REMOVE_WHITE_LIST, "BT_REMOVE_WHITE_LIST"},
- {BT_CLEAR_WHITE_LIST, "BT_CLEAR_WHITE_LIST"},
- {BT_REGISTER_SCAN_FILTER, "BT_REGISTER_SCAN_FILTER"},
- {BT_IS_SCAN_FILTER_SUPPORTED, "BT_IS_SCAN_FILTER_SUPPORTED"},
- {BT_GET_PROFILE_CONNECTED_DEVICES, "BT_GET_PROFILE_CONNECTED_DEVICES"},
- {BT_ENABLE_FORCE_HCI_DUMP, "BT_ENABLE_FORCE_HCI_DUMP"},
- {BT_SET_PASSKEY_NOTIFICATION, "BT_SET_PASSKEY_NOTIFICATION"},
- {BT_DISCONNECT_DEVICE, "BT_DISCONNECT_DEVICE"},
- {BT_BOND_DEVICE, "BT_BOND_DEVICE"},
- {BT_BOND_DEVICE_BY_TYPE, "BT_BOND_DEVICE_BY_TYPE"},
- {BT_CANCEL_BONDING, "BT_CANCEL_BONDING"},
- {BT_PASSKEY_REPLY, "BT_PASSKEY_REPLY"},
- {BT_PASSKEY_CONFIRMATION_REPLY, "BT_PASSKEY_CONFIRMATION_REPLY"},
- {BT_UNBOND_DEVICE, "BT_UNBOND_DEVICE"},
- {BT_SEARCH_SERVICE, "BT_SEARCH_SERVICE"},
- {BT_CANCEL_SEARCH_SERVICE, "BT_CANCEL_SEARCH_SERVICE"},
- {BT_GET_BONDED_DEVICE, "BT_GET_BONDED_DEVICE"},
- {BT_GET_IS_ALIAS_SET, "BT_GET_IS_ALIAS_SET"},
- {BT_SET_ALIAS, "BT_SET_ALIAS"},
- {BT_SET_AUTHORIZATION, "BT_SET_AUTHORIZATION"},
- {BT_UNSET_AUTHORIZATION, "BT_UNSET_AUTHORIZATION"},
- {BT_IS_DEVICE_CONNECTED, "BT_IS_DEVICE_CONNECTED"},
- {BT_GET_CONNECTED_LINK_TYPE, "BT_GET_CONNECTED_LINK_TYPE"},
- {BT_SET_PIN_CODE, "BT_SET_PIN_CODE"},
- {BT_UNSET_PIN_CODE, "BT_UNSET_PIN_CODE"},
- {BT_UPDATE_LE_CONNECTION_MODE, "BT_UPDATE_LE_CONNECTION_MODE"},
- {BT_SET_PROFILE_TRUSTED, "BT_SET_PROFILE_TRUSTED"},
- {BT_GET_PROFILE_TRUSTED, "BT_GET_PROFILE_TRUSTED"},
- {BT_HID_CONNECT, "BT_HID_CONNECT"},
- {BT_HID_DISCONNECT, "BT_HID_DISCONNECT"},
- {BT_HID_DEVICE_ACTIVATE, "BT_HID_DEVICE_ACTIVATE"},
- {BT_HID_DEVICE_DEACTIVATE, "BT_HID_DEVICE_DEACTIVATE"},
- {BT_HID_DEVICE_CONNECT, "BT_HID_DEVICE_CONNECT"},
- {BT_HID_DEVICE_DISCONNECT, "BT_HID_DEVICE_DISCONNECT"},
- {BT_HID_DEVICE_SEND_MOUSE_EVENT, "BT_HID_DEVICE_SEND_MOUSE_EVENT"},
- {BT_HID_DEVICE_SEND_KEY_EVENT, "BT_HID_DEVICE_SEND_KEY_EVENT"},
- {BT_HID_DEVICE_SEND_CUSTOM_EVENT, "BT_HID_DEVICE_SEND_CUSTOM_EVENT"},
- {BT_HID_DEVICE_SEND_REPLY_TO_REPORT, "BT_HID_DEVICE_SEND_REPLY_TO_REPORT"},
- {BT_HID_ENABLE_BARCODE_FEATURE, "BT_HID_ENABLE_BARCODE_FEATURE"},
- {BT_NETWORK_ACTIVATE, "BT_NETWORK_ACTIVATE"},
- {BT_NETWORK_DEACTIVATE, "BT_NETWORK_DEACTIVATE"},
- {BT_NETWORK_CONNECT, "BT_NETWORK_CONNECT"},
- {BT_NETWORK_DISCONNECT, "BT_NETWORK_DISCONNECT"},
- {BT_NETWORK_SERVER_DISCONNECT, "BT_NETWORK_SERVER_DISCONNECT"},
- {BT_AUDIO_CONNECT, "BT_AUDIO_CONNECT"},
- {BT_AUDIO_DISCONNECT, "BT_AUDIO_DISCONNECT"},
- {BT_AG_CONNECT, "BT_AG_CONNECT"},
- {BT_AG_DISCONNECT, "BT_AG_DISCONNECT"},
- {BT_AV_CONNECT, "BT_AV_CONNECT"},
- {BT_AV_DISCONNECT, "BT_AV_DISCONNECT"},
- {BT_AV_SOURCE_CONNECT, "BT_AV_SOURCE_CONNECT"},
- {BT_AV_SOURCE_DISCONNECT, "BT_AV_SOURCE_DISCONNECT"},
- {BT_HF_CONNECT, "BT_HF_CONNECT"},
- {BT_HF_DISCONNECT, "BT_HF_DISCONNECT"},
- {BT_GET_SPEAKER_GAIN, "BT_GET_SPEAKER_GAIN"},
- {BT_SET_SPEAKER_GAIN, "BT_SET_SPEAKER_GAIN"},
- {BT_SET_CONTENT_PROTECT, "BT_SET_CONTENT_PROTECT"},
- {BT_OOB_READ_LOCAL_DATA, "BT_OOB_READ_LOCAL_DATA"},
- {BT_OOB_ADD_REMOTE_DATA, "BT_OOB_ADD_REMOTE_DATA"},
- {BT_OOB_REMOVE_REMOTE_DATA, "BT_OOB_REMOVE_REMOTE_DATA"},
- {BT_LE_OOB_READ_LOCAL_DATA, "BT_LE_OOB_READ_LOCAL_DATA"},
- {BT_LE_OOB_ADD_REMOTE_DATA, "BT_LE_OOB_ADD_REMOTE_DATA"},
- {BT_AVRCP_SET_TRACK_INFO, "BT_AVRCP_SET_TRACK_INFO"},
- {BT_AVRCP_SET_PROPERTY, "BT_AVRCP_SET_PROPERTY"},
- {BT_AVRCP_SET_PROPERTIES, "BT_AVRCP_SET_PROPERTIES"},
- {BT_AVRCP_CONTROL_CONNECT, "BT_AVRCP_CONTROL_CONNECT"},
- {BT_AVRCP_CONTROL_DISCONNECT, "BT_AVRCP_CONTROL_DISCONNECT"},
- {BT_AVRCP_TARGET_CONNECT, "BT_AVRCP_TARGET_CONNECT"},
- {BT_AVRCP_TARGET_DISCONNECT, "BT_AVRCP_TARGET_DISCONNECT"},
- {BT_AVRCP_HANDLE_CONTROL, "BT_AVRCP_HANDLE_CONTROL"},
- {BT_AVRCP_CONTROL_SET_PROPERTY, "BT_AVRCP_CONTROL_SET_PROPERTY"},
- {BT_AVRCP_CONTROL_GET_PROPERTY, "BT_AVRCP_CONTROL_GET_PROPERTY"},
- {BT_AVRCP_GET_TRACK_INFO, "BT_AVRCP_GET_TRACK_INFO"},
- {BT_OPP_PUSH_FILES, "BT_OPP_PUSH_FILES"},
- {BT_OPP_CANCEL_PUSH, "BT_OBT_OPP_IS_PUSHING_FILESPP_CANCEL_PUSH"},
- {BT_OPP_IS_PUSHING_FILES, "BT_OPP_IS_PUSHING_FILES"},
- {BT_OPP_GET_TRANSFER_PROGRESS, "BT_OPP_GET_TRANSFER_PROGRESS"},
- {BT_MAP_CREATE_SESSION, "BT_MAP_CREATE_SESSION"},
- {BT_MAP_DESTROY_SESSION, "BT_MAP_DESTROY_SESSION"},
- {BT_MAP_SET_FOLDER, "BT_MAP_SET_FOLDER"},
- {BT_MAP_LIST_FOLDERS, "BT_MAP_LIST_FOLDERS"},
- {BT_MAP_LIST_FILTER_FIELDS, "BT_MAP_LIST_FILTER_FIELDS"},
- {BT_MAP_LIST_MESSAGES, "BT_MAP_LIST_MESSAGES"},
- {BT_MAP_UPDATE_INBOX, "BT_MAP_UPDATE_INBOX"},
- {BT_MAP_PUSH_MESSAGE, "BT_MAP_PUSH_MESSAGE"},
- {BT_MAP_GET_MESSAGE, "BT_MAP_GET_MESSAGE"},
- {BT_OBEX_SERVER_ALLOCATE, "BT_OBEX_SERVER_ALLOCATE"},
- {BT_OBEX_SERVER_DEALLOCATE, "BT_OBEX_SERVER_DEALLOCATE"},
- {BT_OBEX_SERVER_IS_ACTIVATED, "BT_OBEX_SERVER_IS_ACTIVATED"},
- {BT_OBEX_SERVER_ACCEPT_CONNECTION, "BT_OBEX_SERVER_ACCEPT_CONNECTION"},
- {BT_OBEX_SERVER_REJECT_CONNECTION, "BT_OBEX_SERVER_REJECT_CONNECTION"},
- {BT_OBEX_SERVER_ACCEPT_FILE, "BT_OBEX_SERVER_ACCEPT_FILE"},
- {BT_OBEX_SERVER_REJECT_FILE, "BT_OBEX_SERVER_REJECT_FILE"},
- {BT_OBEX_SERVER_SET_PATH, "BT_OBEX_SERVER_SET_PATH"},
- {BT_OBEX_SERVER_SET_ROOT, "BT_OBEX_SERVER_SET_ROOT"},
- {BT_OBEX_SERVER_CANCEL_TRANSFER, "BT_OBEX_SERVER_CANCEL_TRANSFER"},
- {BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS, "BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS"},
- {BT_OBEX_SERVER_IS_RECEIVING, "BT_OBEX_SERVER_IS_RECEIVING"},
- {BT_RFCOMM_CLIENT_CONNECT, "BT_RFCOMM_CLIENT_CONNECT"},
- {BT_RFCOMM_CLIENT_CANCEL_CONNECT, "BT_RFCOMM_CLIENT_CANCEL_CONNECT"},
- {BT_RFCOMM_CLIENT_IS_CONNECTED, "BT_RFCOMM_CLIENT_IS_CONNECTED"},
- {BT_RFCOMM_SOCKET_DISCONNECT, "BT_RFCOMM_SOCKET_DISCONNECT"},
- {BT_RFCOMM_SOCKET_WRITE, "BT_RFCOMM_SOCKET_WRITE"},
- {BT_RFCOMM_CREATE_SOCKET, "BT_RFCOMM_CREATE_SOCKET"},
- {BT_RFCOMM_REMOVE_SOCKET, "BT_RFCOMM_REMOVE_SOCKET"},
- {BT_RFCOMM_LISTEN, "BT_RFCOMM_LISTEN"},
- {BT_RFCOMM_IS_UUID_AVAILABLE, "BT_RFCOMM_IS_UUID_AVAILABLE"},
- {BT_RFCOMM_ACCEPT_CONNECTION, "BT_RFCOMM_ACCEPT_CONNECTION"},
- {BT_RFCOMM_REJECT_CONNECTION, "BT_RFCOMM_REJECT_CONNECTION"},
- {BT_RFCOMM_CREATE_SOCKET_EX, "BT_RFCOMM_CREATE_SOCKET_EX"},
- {BT_RFCOMM_REMOVE_SOCKET_EX, "BT_RFCOMM_REMOVE_SOCKET_EX"},
- {BT_PBAP_CONNECT, "BT_PBAP_CONNECT"},
- {BT_PBAP_DISCONNECT, "BT_PBAP_DISCONNECT"},
- {BT_PBAP_GET_PHONEBOOK_SIZE, "BT_PBAP_GET_PHONEBOOK_SIZE"},
- {BT_PBAP_GET_PHONEBOOK, "BT_PBAP_GET_PHONEBOOK"},
- {BT_PBAP_GET_LIST, "BT_PBAP_GET_LIST"},
- {BT_PBAP_PULL_VCARD, "BT_PBAP_PULL_VCARD"},
- {BT_PBAP_PHONEBOOK_SEARCH, "BT_PBAP_PHONEBOOK_SEARCH"},
- {BT_ENABLE_ADAPTER_LE, "BT_ENABLE_ADAPTER_LE"},
- {BT_DISABLE_ADAPTER_LE, "BT_DISABLE_ADAPTER_LE"},
- {BT_CONNECT_LE, "BT_CONNECT_LE"},
- {BT_DISCONNECT_LE, "BT_DISCONNECT_LE"},
- {BT_SET_LE_PRIVACY, "BT_SET_LE_PRIVACY"},
- {BT_REQ_ATT_MTU, "BT_REQ_ATT_MTU"},
- {BT_GET_ATT_MTU, "BT_GET_ATT_MTU"},
- {BT_GET_DEVICE_IDA, "BT_GET_DEVICE_IDA"},
- {BT_SET_LE_STATIC_RANDOM_ADDRESS, "BT_SET_LE_STATIC_RANDOM_ADDRESS"},
- {BT_HDP_CONNECT, "BT_HDP_CONNECT"},
- {BT_HDP_DISCONNECT, "BT_HDP_DISCONNECT"},
- {BT_HDP_SEND_DATA, "BT_HDP_SEND_DATA"},
- {BT_HDP_REGISTER_SINK_APP, "BT_HDP_REGISTER_SINK_APP"},
- {BT_HDP_UNREGISTER_SINK_APP, "BT_HDP_UNREGISTER_SINK_APP"},
- {BT_GATT_GET_PRIMARY_SERVICES, "BT_GATT_GET_PRIMARY_SERVICES"},
- {BT_GATT_DISCOVER_CHARACTERISTICS, "BT_GATT_DISCOVER_CHARACTERISTICS"},
- {BT_GATT_SET_PROPERTY_REQUEST, "BT_GATT_SET_PROPERTY_REQUEST"},
- {BT_GATT_READ_CHARACTERISTIC, "BT_GATT_READ_CHARACTERISTIC"},
- {BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR, "BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR"},
- {BT_GATT_REGISTER_APPLICATION, "BT_GATT_REGISTER_APPLICATION"},
- {BT_GATT_REGISTER_SERVICE, "BT_GATT_REGISTER_SERVICE"},
- {BT_GATT_SEND_RESPONSE, "BT_GATT_SEND_RESPONSE"},
- {BT_LE_IPSP_INIT, "BT_LE_IPSP_INIT"},
- {BT_LE_IPSP_DEINIT, "BT_LE_IPSP_DEINIT"},
- {BT_LE_IPSP_CONNECT, "BT_LE_IPSP_CONNECT"},
- {BT_LE_IPSP_DISCONNECT, "BT_LE_IPSP_DISCONNECT"},
- {BT_DPM_SET_ALLOW_BT_MODE, "BT_DPM_SET_ALLOW_BT_MODE"},
- {BT_DPM_GET_ALLOW_BT_MODE, "BT_DPM_GET_ALLOW_BT_MODE"},
- {BT_DPM_SET_DEVICE_RESTRITION, "BT_DPM_SET_DEVICE_RESTRITION"},
- {BT_DPM_GET_DEVICE_RESTRITION, "BT_DPM_GET_DEVICE_RESTRITION"},
- {BT_DPM_SET_UUID_RESTRITION, "BT_DPM_SET_UUID_RESTRITION"},
- {BT_DPM_GET_UUID_RESTRITION, "BT_DPM_GET_UUID_RESTRITION"},
- {BT_DPM_ADD_DEVICES_BLACKLIST, "BT_DPM_ADD_DEVICES_BLACKLIST"},
- {BT_DPM_ADD_DEVICES_WHITELIST, "BT_DPM_ADD_DEVICES_WHITELIST"},
- {BT_DPM_ADD_UUIDS_BLACKLIST, "BT_DPM_ADD_UUIDS_BLACKLIST"},
- {BT_DPM_ADD_UUIDS_WHITELIST, "BT_DPM_ADD_UUIDS_WHITELIST"},
- {BT_DPM_CLEAR_DEVICES_BLACKLIST, "BT_DPM_CLEAR_DEVICES_BLACKLIST"},
- {BT_DPM_CLEAR_DEVICES_WHITELIST, "BT_DPM_CLEAR_DEVICES_WHITELIST"},
- {BT_DPM_CLEAR_UUIDS_BLACKLIST, "BT_DPM_CLEAR_UUIDS_BLACKLIST"},
- {BT_DPM_CLEAR_UUIDS_WHITELIST, "BT_DPM_CLEAR_UUIDS_WHITELIST"},
- {BT_DPM_REMOVE_DEVICE_BLACKLIST, "BT_DPM_REMOVE_DEVICE_BLACKLIST"},
- {BT_DPM_REMOVE_DEVICE_WHITELIST, "BT_DPM_REMOVE_DEVICE_WHITELIST"},
- {BT_DPM_REMOVE_UUID_BLACKLIST, "BT_DPM_REMOVE_UUID_BLACKLIST"},
- {BT_DPM_REMOVE_UUID_WHITELIST, "BT_DPM_REMOVE_UUID_WHITELIST"},
- {BT_DPM_GET_DEVICES_BLACKLIST, "BT_DPM_GET_DEVICES_BLACKLIST"},
- {BT_DPM_GET_DEVICES_WHITELIST, "BT_DPM_GET_DEVICES_WHITELIST"},
- {BT_DPM_GET_UUIDS_BLACKLIST, "BT_DPM_GET_UUIDS_BLACKLIST"},
- {BT_DPM_GET_UUIDS_WHITELIST, "BT_DPM_GET_UUIDS_WHITELIST"},
- {BT_DPM_SET_ALLOW_OUTGOING_CALL, "BT_DPM_SET_ALLOW_OUTGOING_CALL"},
- {BT_DPM_GET_ALLOW_OUTGOING_CALL, "BT_DPM_GET_ALLOW_OUTGOING_CALL"},
- {BT_DPM_SET_PAIRING_STATE, "BT_DPM_SET_PAIRING_STATE"},
- {BT_DPM_GET_PAIRING_STATE, "BT_DPM_GET_PAIRING_STATE"},
- {BT_DPM_SET_PROFILE_STATE, "BT_DPM_SET_PROFILE_STATE"},
- {BT_DPM_GET_PROFILE_STATE, "BT_DPM_GET_PROFILE_STATE"},
- {BT_DPM_SET_DESKROP_CONNECTIVITY_STATE, "BT_DPM_SET_DESKROP_CONNECTIVITY_STATE"},
- {BT_DPM_GET_DESKROP_CONNECTIVITY_STATE, "BT_DPM_GET_DESKROP_CONNECTIVITY_STATE"},
- {BT_DPM_SET_DISCOVERABLE_STATE, "BT_DPM_SET_DISCOVERABLE_STATE"},
- {BT_DPM_GET_DISCOVERABLE_STATE, "BT_DPM_GET_DISCOVERABLE_STATE"},
- {BT_DPM_SET_LIMITED_DISCOVERABLE_STATE, "BT_DPM_SET_LIMITED_DISCOVERABLE_STATE"},
- {BT_DPM_GET_LIMITED_DISCOVERABLE_STATE, "BT_DPM_GET_LIMITED_DISCOVERABLE_STATE"},
- {BT_DPM_SET_DATA_TRANSFER_STATE, "BT_DPM_SET_DATA_TRANSFER_STATE"},
- {BT_DPM_GET_DATA_TRANSFER_STATE, "BT_DPM_GET_DATA_TRANSFER_STATE"},
- {BT_PXP_MONITOR_SET_PROPERTY, "BT_PXP_MONITOR_SET_PROPERTY"},
- {BT_PXP_MONITOR_GET_PROPERTY, "BT_PXP_MONITOR_GET_PROPERTY"},
- {BT_PXP_MONITOR_GET_SUPPORTED_SERIVCES, "BT_PXP_MONITOR_GET_SUPPORTED_SERIVCES"},
- {BT_PXP_REPORTER_REGISTER, "BT_PXP_REPORTER_REGISTER"},
- {BT_PXP_REPORTER_UNREGISTER, "BT_PXP_REPORTER_UNREGISTER"},
- {BT_PXP_REPORTER_GET_PROPERTY, "BT_PXP_REPORTER_GET_PROPERTY"},
- {BT_TDS_PROVIDER_REGISTER, "BT_TDS_PROVIDER_REGISTER"},
- {BT_TDS_PROVIDER_UNREGISTER, "BT_TDS_PROVIDER_UNREGISTER"},
- {BT_TDS_PROVIDER_SET_MANUF_DATA, "BT_TDS_PROVIDER_SET_MANUF_DATA"},
- {BT_TDS_PROVIDER_CREATE, "BT_TDS_PROVIDER_CREATE"},
- {BT_TDS_PROVIDER_DESTROY, "BT_TDS_PROVIDER_DESTROY"},
- {BT_TDS_PROVIDER_SET_TRANSPORT_DATA, "BT_TDS_PROVIDER_SET_TRANSPORT_DATA"},
- {BT_TDS_SEND_ACTIVATION_RESPONSE, "BT_TDS_SEND_ACTIVATION_RESPONSE"},
- {BT_TDS_READ_TRANSPORT_DATA, "BT_TDS_READ_TRANSPORT_DATA"},
- {BT_TDS_ENABLE_CONTROL_POINT, "BT_TDS_ENABLE_CONTROL_POINT"},
- {BT_TDS_ACTIVATE_CONTROL_POINT, "BT_TDS_ACTIVATE_CONTROL_POINT"},
- {-1, ""},
- };
-
- for (i = 0; bt_functions[i].function != -1; i++) {
- if (bt_functions[i].function == function)
- return bt_functions[i].function_name;
- }
-
- return NULL;
-}
-
-void _bt_logging_connection(gboolean connect, int addr_type)
-{
- static int le_conn = 0;
- static int le_disc = 0;
- static int edr_conn = 0;
- static int edr_disc = 0;
-
- if (connect) {
- if (addr_type)
- le_conn++;
- else
- edr_conn++;
- } else {
- if (addr_type)
- le_disc++;
- else
- edr_disc++;
- }
-
- BT_INFO("[PM] Number of LE conn: %d disc: %d, Number of BR/EDR conn: %d disc: %d",
- le_conn, le_disc, edr_conn, edr_disc);
-}
-
-void _bt_swap_byte_ordering(char *data, int data_len)
-{
- char temp;
- int i, j;
- int half = data_len / 2;
-
- ret_if(data == NULL);
- /* Swap to opposite endian */
- for (i = 0, j = data_len - 1; i < half; i++, j--) {
- temp = data[i];
- data[i] = data[j];
- data[j] = temp;
- }
-}
-
-int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len)
-{
- int i;
-
- retv_if(data1 == NULL, -1);
- retv_if(data2 == NULL, -1);
- for (i = 0; i < data_len; i++) {
- if (data1[i] != data2[i])
- return data1[i] - data2[i];
- }
- return 0;
-}
-int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2,
- const char *mask, int data_len)
-{
- int i;
- char a, b;
-
- retv_if(data1 == NULL, -1);
- retv_if(data2 == NULL, -1);
- retv_if(mask == NULL, -1);
- for (i = 0; i < data_len; i++) {
- a = data1[i] & mask[i];
- b = data2[i] & mask[i];
- if (a != b)
- return (int)(a - b);
- }
- return 0;
-}
-
-int _bt_eventsystem_set_value(const char *event, const char *key, const char *value)
-{
- int ret = ES_R_OK;
-/* Send event system event in bt-core process because bt-service's permission is not system in now */
-
-#if 0
- bundle *b = NULL;
-
- b = bundle_create();
-
- bundle_add_str(b, key, value);
-
- ret = eventsystem_send_system_event(event, b);
-
- BT_DBG("eventsystem_send_system_event result: %d", ret);
-
- bundle_free(b);
-#endif
- return ret;
-}
-
-void __bt_get_auth_info(GVariant *reply, char *auth_info)
-{
- int cursor;
- GVariant *tmp_value;
- char *manufacturer_data = NULL;
- int manufacturer_data_len;
- gboolean is_alias_set;
- GVariantIter *value_iter;
- guint8 m_value;
- int i = 0;
-
- tmp_value = g_variant_lookup_value(reply, "IsAliasSet",
- G_VARIANT_TYPE_BOOLEAN);
- if (tmp_value) {
- is_alias_set = g_variant_get_boolean(tmp_value);
- g_variant_unref(tmp_value);
- } else {
- is_alias_set = FALSE;
- }
- if (is_alias_set == FALSE) {
- tmp_value = g_variant_lookup_value(reply, "LegacyManufacturerDataLen",
- G_VARIANT_TYPE_UINT16);
- if (tmp_value) {
- manufacturer_data_len = g_variant_get_uint16(tmp_value);
- if (manufacturer_data_len >
- BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
- BT_ERR("manufacturer_data_len is too long");
- manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
- }
- g_variant_unref(tmp_value);
- } else
- manufacturer_data_len = 0;
-
- tmp_value = g_variant_lookup_value(reply, "LegacyManufacturerData",
- G_VARIANT_TYPE_ARRAY);
- if (tmp_value) {
- if ((manufacturer_data_len == 0) ||
- manufacturer_data_len != g_variant_get_size(tmp_value)) {
- BT_ERR("manufacturer data length doesn't match");
- manufacturer_data_len = 0;
- manufacturer_data = NULL;
- } else {
- manufacturer_data = g_malloc0(manufacturer_data_len);
- g_variant_get(tmp_value, "ay", &value_iter);
- while (g_variant_iter_loop(value_iter, "y", &m_value))
- manufacturer_data[i++] = m_value;
-
- g_variant_iter_free(value_iter);
- }
- g_variant_unref(tmp_value);
- } else {
- BT_INFO("manufacture data is not a G_VARIANT_TYPE_ARRAY ");
- manufacturer_data_len = 0;
- manufacturer_data = NULL;
- }
- /*minimum Size of the samsung specific manufacturer data is greater than 30 */
- if (manufacturer_data_len < 30) {
- g_free(manufacturer_data);
- return;
- }
- if (manufacturer_data[0] != 0x00 || manufacturer_data[1] != 0x75) {
- BT_DBG("This is not a samsung specific manufaturer data");
- g_free(manufacturer_data);
- return;
- }
-
- /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
- 1 (discovery version) + 1 (associated service ID)
- 2 (Proxamity and locality) + 2 (Device type and icon) */
-
- cursor = 10;
-
- memcpy(auth_info, &(manufacturer_data[cursor]), 5);
- }
- g_free(manufacturer_data);
-}
-
-int _bt_convert_gerror(GError *g_error)
-{
- int ret = BLUETOOTH_ERROR_INTERNAL;
- gchar *str;
-
- if (!g_dbus_error_strip_remote_error(g_error))
- return ret;
-
- str = g_error->message;
-
- if (g_strcmp0(str, "Connection refused") == 0)
- ret = BLUETOOTH_ERROR_AUTHENTICATION_REJECTED;
- else if (g_strcmp0(str, "Connection timed out") == 0)
- ret = BLUETOOTH_ERROR_TIMEOUT;
- else if (g_strcmp0(str, "In Progress") == 0)
- ret = BLUETOOTH_ERROR_IN_PROGRESS;
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <gio/gio.h>
-#include <dlog.h>
-#include <string.h>
-#include <syspopup_caller.h>
-#include <vconf.h>
-#include <bundle_internal.h>
-
-
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-
-#include "bt-service-common.h"
-#include "bt-service-adapter-le.h"
-#include "bt-service-event.h"
-#include "bt-service-device.h"
-#include "bt-service-rfcomm-client.h"
-#include "bt-service-util.h"
-#include "bt-service-agent.h"
-#include "bt-service-network.h"
-#include "bt-service-adapter.h"
-#include "bt-service-gap-agent.h"
-
-#define BT_SYSPOPUP_IPC_RESPONSE_OBJECT "/org/projectx/bt_syspopup_res"
-#define BT_SYSPOPUP_INTERFACE "User.Bluetooth.syspopup"
-#define BT_SYSPOPUP_METHOD_RESPONSE "Response"
-
-#define BT_LE_CONN_INTERVAL_MIN 7.5 /* msec */
-#define BT_LE_CONN_INTERVAL_MAX 4000 /* msec */
-#define BT_LE_CONN_SUPER_TO_MIN 100 /* msec */
-#define BT_LE_CONN_SUPER_TO_MAX 32000 /* msec */
-#define BT_LE_CONN_SLAVE_LATENCY_MAX 499
-#define BT_LE_CONN_INTERVAL_SPLIT 1.25 /* msec */
-#define BT_LE_CONN_TO_SPLIT 10 /* msec */
-#define BT_DEVICE_PIN_CODE_SLOT_MAX 10
-
-#define BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT 6000 /* msec */
-
-#define BT_LE_CONN_PARAM_BALANCED_MIN_INTERVAL 30 /* msec */
-#define BT_LE_CONN_PARAM_BALANCED_MAX_INTERVAL 50 /* msec */
-#define BT_LE_CONN_PARAM_BALANCED_SLAVE_LATENCY 0 /* event */
-
-#define BT_LE_CONN_PARAM_LOW_LATENCY_MIN_INTERVAL 10 /* msec */
-#define BT_LE_CONN_PARAM_LOW_LATENCY_MAX_INTERVAL 30 /* msec */
-#define BT_LE_CONN_PARAM_LOW_LATENCY_SLAVE_LATENCY 0 /* event */
-
-#define BT_LE_CONN_PARAM_LOW_POWER_MIN_INTERVAL 80 /* msec */
-#define BT_LE_CONN_PARAM_LOW_POWER_MAX_INTERVAL 100 /* msec */
-#define BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY 2 /* event */
-
-#define PROFILE_SUPPORTED 0x3 /* This corresponds to binary 0b11*/
-
-typedef struct {
- int req_id;
- int result;
- char *addr;
- gboolean is_autopair;
- GDBusProxy *device_proxy;
- GDBusProxy *adapter_proxy;
- void *agent;
- unsigned short conn_type;
- gboolean bonding_wo_discovery;
-} bt_funcion_data_t;
-
-typedef struct {
- char *address;
- char *pin_code;
-} bt_pin_code_info_t;
-
-typedef struct {
- int req_id;
- bluetooth_device_address_t bd_addr;
- gboolean auto_connect;
-} bt_pending_le_conn_info_s;
-
-typedef struct {
- char *address;
- float interval_min;
- float interval_max;
- GSList *senders;
-} bt_connected_le_dev_t;
-
-typedef struct {
- char *sender;
- float interval_min;
- float interval_max;
- guint16 latency;
- guint16 time_out;
- float key;
-} bt_le_conn_param_t;
-
-gboolean is_device_creating;
-bt_funcion_data_t *bonding_info;
-bt_funcion_data_t *searching_info;
-bt_funcion_data_t *att_mtu_req_info;
-
-static GSList *le_connected_dev_list = NULL;
-static GSList *pin_info_list = NULL;
-static bt_pending_le_conn_info_s *pending_le_conn_info = NULL;
-static guint pending_le_conn_timer_id = 0;
-
-/* This HID Mouse does not support pairing precedure. need to skip it. */
-#define SMB_MOUSE_LAP_ADDR "00:12:A1"
-
-static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data);
-
-/*static void __bt_decline_pair_request()
-{
- GVariant *out_param1;
- GVariant *out_param2;
- request_info_t *req_info;
- bluetooth_device_info_t dev_info;
- bt_remote_dev_info_t *remote_dev_info;
- GVariant *uuid_list, *manufacture_data;
- GVariant *param;
-
- BT_DBG("+");
- if (bonding_info) {
- req_info = _bt_get_request_info(bonding_info->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- goto done;
- }
- remote_dev_info = _bt_get_remote_device_info(bonding_info->addr);
- } else {
- BT_DBG("bonding_info is NULL");
- BT_DBG("-");
- return;
- }
-
- uuid_list = g_variant_new_from_data((const GVariantType *)"as",
- remote_dev_info->uuids, remote_dev_info->uuid_count,
- TRUE, NULL, NULL);
-
- manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
- remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
- TRUE, NULL, NULL);
-
- param = g_variant_new("isunsbuba{s}na{y})",
- bonding_info->result,
- bonding_info->addr,
- remote_dev_info->class,
- remote_dev_info->rssi,
- remote_dev_info->name,
- remote_dev_info->paired,
- remote_dev_info->connected,
- remote_dev_info->trust,
- uuid_list,
- remote_dev_info->manufacturer_data_len,
- manufacture_data);
-
-
- //Send the event to application
- if (remote_dev_info != NULL) {
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_BONDING_FINISHED,
- param);
-
- _bt_free_device_info(remote_dev_info);
- }
-
- if (req_info->context == NULL)
- goto done;
-
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
- _bt_convert_addr_string_to_type(dev_info.device_address.addr,
- bonding_info->addr);
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
-
- out_param2 = g_variant_new_from_data((const GVariantType *)"i",
- &bonding_info->result, sizeof(int), TRUE, NULL, NULL);
-
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("@ayi", out_param1, out_param2));
-
-
- _bt_delete_request_list(req_info->req_id);
-done:
-
- g_free(bonding_info->addr);
- g_free(bonding_info);
- bonding_info = NULL;
-
- BT_DBG("-");
-} */
-
-#ifdef TIZEN_PROFILE_WEARABLE
-static gboolean __bt_syspopup_timer_cb(gpointer user_data)
-{
- int ret;
- bundle *b;
- retv_if(user_data == NULL, FALSE);
-
- b = (bundle *)user_data;
-
- ret = syspopup_launch("bt-syspopup", b);
- if (ret < 0) {
- BT_ERR("Sorry!! Cannot launch popup return = %d, Retrying...", ret);
- } else {
- BT_DBG("Hurray!!! Finally Popup launched");
- bundle_free(b);
- }
- return (ret < 0) ? TRUE : FALSE;
-}
-
-static gboolean __bt_launch_unable_to_pairing_syspopup(int result)
-{
- BT_DBG("+");
- int ret = 0;
- bundle *b = NULL;
- GDBusConnection *conn;
-
- conn = _bt_gdbus_get_system_gconn();
- if (conn == NULL)
- return FALSE;
-
- b = bundle_create();
- if (b == NULL)
- return FALSE;
-
- bundle_add(b, "event-type", "unable-to-pairing");
-
- if (result == BLUETOOTH_ERROR_TIMEOUT)
- bundle_add(b, "error", "timeout");
- else if (result == BLUETOOTH_ERROR_AUTHENTICATION_FAILED)
- bundle_add(b, "error", "authfailed");
- else
- bundle_add(b, "error", "error");
-
- ret = syspopup_launch("bt-syspopup", b);
- if (0 > ret) {
- BT_ERR("Popup launch failed...retry %d \n", ret);
- g_timeout_add(200, (GSourceFunc) __bt_syspopup_timer_cb,
- b);
- } else {
- bundle_free(b);
- }
-
- BT_DBG("-");
- return TRUE;
-}
-#endif
-
-gboolean _bt_is_device_creating(void)
-{
- return is_device_creating;
-}
-
-gboolean _bt_is_bonding_device_address(const char *address)
-{
- if (bonding_info == NULL || bonding_info->addr == NULL)
- return FALSE;
-
- if (g_strcmp0(bonding_info->addr, address) == 0) {
- BT_DBG("[%s] is bonding device", address);
- return TRUE;
- }
-
- BT_DBG("[%s] is NOT bonding device", address);
- return FALSE;
-}
-
-void _bt_set_autopair_status_in_bonding_info(gboolean is_autopair)
-{
- ret_if(bonding_info == NULL);
- bonding_info->is_autopair = is_autopair;
-}
-
-void __bt_cancel_search_service_done(void)
-{
- int result = BLUETOOTH_ERROR_CANCEL_BY_USER;
- request_info_t *req_info;
- bluetooth_device_info_t dev_info;
- GVariant *out_param1;
-
- ret_if(searching_info == NULL);
-
- req_info = _bt_get_request_info(searching_info->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- goto done;
- }
-
- if (req_info->context == NULL)
- goto done;
-
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
- _bt_convert_addr_string_to_type(dev_info.device_address.addr,
- searching_info->addr);
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
-
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("(iv)", result, out_param1));
-
- _bt_delete_request_list(req_info->req_id);
-
-done:
-
- g_free(searching_info->addr);
- g_free(searching_info);
- searching_info = NULL;
-}
-
-static void __bt_get_uuids(GVariant *value, bt_remote_dev_info_t *info)
-{
- ret_if(value == NULL);
- ret_if(info == NULL);
-
- info->uuid_count = g_variant_get_size(value);
- info->uuids = g_variant_dup_strv(value, &info->uuid_count);
-}
-
-bt_remote_dev_info_t *_bt_get_remote_device_info(char *address)
-{
- char *object_path = NULL;
- bt_remote_dev_info_t *dev_info;
-
- retv_if(address == NULL, NULL);
-
- object_path = _bt_get_device_object_path(address);
- retv_if(object_path == NULL, NULL);
-
- dev_info = _bt_get_remote_device_info_by_object_path(object_path);
-
- g_free(object_path);
- return dev_info;
-}
-
-bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
- const char *object_path)
-{
- bt_remote_dev_info_t *dev_info;
- GDBusProxy *adapter_proxy;
- GDBusProxy *device_proxy;
- GVariant *value;
- GVariant *tmp_value;
- gchar *name;
- gchar * address;
- GDBusConnection *conn;
- GError *error = NULL;
- GVariant *result = NULL;
- GVariantIter *value_iter;
- guint8 m_value;
- int i = 0;
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, NULL);
-
- retv_if(object_path == NULL, NULL);
-
- conn = _bt_gdbus_get_system_gconn();
- if (conn == NULL) {
- BT_ERR("conn == NULL");
- return NULL;
- }
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME, object_path,
- BT_PROPERTIES_INTERFACE, NULL, NULL);
-
- retv_if(device_proxy == NULL, NULL);
-
- result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
- g_variant_new("(s)", BT_DEVICE_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- g_object_unref(device_proxy);
-
- dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
-
- if (result != NULL) {
- g_variant_get(result , "(@a{sv})", &value);
- g_variant_unref(result);
-
- tmp_value = g_variant_lookup_value(value, "Alias", G_VARIANT_TYPE_STRING);
-
- g_variant_get(tmp_value, "s", &name);
- g_variant_unref(tmp_value);
- if (name != NULL)
- DBG_SECURE("Alias Name [%s]", name);
- else {
- tmp_value = g_variant_lookup_value(value, "Name", G_VARIANT_TYPE_STRING);
- g_variant_get(tmp_value, "s", &name);
- g_variant_unref(tmp_value);
- }
-
- tmp_value = g_variant_lookup_value(value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN);
- if (tmp_value) {
- dev_info->is_alias_set = g_variant_get_boolean(tmp_value);
- g_variant_unref(tmp_value);
- } else {
- dev_info->is_alias_set = FALSE;
- }
- BT_DBG("IsAliasSet: [%s]", dev_info->is_alias_set ? "TRUE" : "FALSE");
-
- tmp_value = g_variant_lookup_value(value, "Class", G_VARIANT_TYPE_UINT32);
- if (tmp_value) {
- dev_info->class = g_variant_get_uint32(tmp_value);
- g_variant_unref(tmp_value);
- } else
- dev_info->class = 0;
-
- tmp_value = g_variant_lookup_value(value, "Connected", G_VARIANT_TYPE_BYTE);
- if (tmp_value) {
- dev_info->connected = g_variant_get_byte(tmp_value);
- g_variant_unref(tmp_value);
- } else
- dev_info->connected = BLUETOOTH_CONNECTED_LINK_NONE;
- BT_DBG("connected link : %d", dev_info->connected);
-
- tmp_value = g_variant_lookup_value(value, "Trusted", G_VARIANT_TYPE_BOOLEAN);
- if (tmp_value) {
- dev_info->trust = g_variant_get_boolean(tmp_value);
- g_variant_unref(tmp_value);
- } else
- dev_info->trust = FALSE;
-
- tmp_value = g_variant_lookup_value(value, "Paired", G_VARIANT_TYPE_BOOLEAN);
- if (tmp_value) {
- dev_info->paired = g_variant_get_boolean(tmp_value);
- g_variant_unref(tmp_value);
- } else
- dev_info->paired = FALSE;
-
- tmp_value = g_variant_lookup_value(value, "RSSI", G_VARIANT_TYPE_INT16);
- if (tmp_value) {
- dev_info->rssi = g_variant_get_int16(tmp_value);
- g_variant_unref(tmp_value);
- } else
- dev_info->rssi = 0;
-
- tmp_value = g_variant_lookup_value(value, "LastAddrType", G_VARIANT_TYPE_BYTE);
- if (tmp_value) {
- dev_info->addr_type = g_variant_get_byte(tmp_value);
- g_variant_unref(tmp_value);
- } else
- dev_info->addr_type = 0;
-
- tmp_value = g_variant_lookup_value(value, "UUIDs", G_VARIANT_TYPE_STRING_ARRAY);
- if (tmp_value) {
- __bt_get_uuids(tmp_value, dev_info);
- g_variant_unref(tmp_value);
- }
-
- tmp_value = g_variant_lookup_value(value, "LegacyManufacturerDataLen", G_VARIANT_TYPE_UINT16);
- if (tmp_value) {
- dev_info->manufacturer_data_len = g_variant_get_uint16(tmp_value);
- if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
- BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
- dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
- }
- g_variant_unref(tmp_value);
- } else
- dev_info->manufacturer_data_len = 0;
-
- tmp_value = g_variant_lookup_value(value, "LegacyManufacturerData", G_VARIANT_TYPE_ARRAY);
- if (tmp_value) {
- if ((dev_info->manufacturer_data_len == 0) ||
- dev_info->manufacturer_data_len != g_variant_get_size(tmp_value)) {
- BT_ERR("manufacturer data length doesn't match");
- dev_info->manufacturer_data_len = 0;
- dev_info->manufacturer_data = NULL;
- } else {
- dev_info->manufacturer_data = g_malloc0(dev_info->manufacturer_data_len);
- g_variant_get(tmp_value, "ay", &value_iter);
- while (g_variant_iter_loop(value_iter, "y", &m_value))
- dev_info->manufacturer_data[i++] = m_value;
-
- g_variant_iter_free(value_iter);
- }
- g_variant_unref(tmp_value);
- } else {
- BT_INFO("manufacture data is not a G_VARIANT_TYPE_ARRAY ");
- dev_info->manufacturer_data_len = 0;
- dev_info->manufacturer_data = NULL;
- }
-
- tmp_value = g_variant_lookup_value(value, "Address", G_VARIANT_TYPE_STRING);
- g_variant_get(tmp_value, "s", &address);
- g_variant_unref(tmp_value);
-
- dev_info->address = address;
- dev_info->name = name;
- g_variant_unref(value);
- } else {
- BT_ERR("result is NULL\n");
- g_free(dev_info);
- dev_info = NULL;
- }
-
- return dev_info;
-}
-
-char *_bt_get_device_name(const char *bdaddress)
-{
- char *device_path = NULL;
- const gchar *name = NULL;
- gchar *dev_name = NULL;
- gsize name_len = 0;
- GVariant *result = NULL;
- GError *err = NULL;
- GDBusProxy *device_proxy;
- GDBusConnection *conn;
-
- retv_if(bdaddress == NULL, NULL);
-
- device_path = _bt_get_device_object_path((char *)bdaddress);
- retv_if(device_path == NULL, NULL);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, NULL);
- INFO_SECURE("Device_path %s", device_path);
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME, device_path,
- BT_PROPERTIES_INTERFACE, NULL, &err);
-
- g_free(device_path);
- retv_if(device_proxy == NULL, NULL);
-
- result = g_dbus_proxy_call_sync(device_proxy, "Get",
- g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Alias"),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
- if (err) {
- BT_ERR("DBus Error : %s", err->message);
- g_clear_error(&err);
- } else {
- GVariant *value;
- g_variant_get(result, "(v)", &value);
- name = g_variant_get_string(value, &name_len);
- INFO_SECURE("Alias Name [%s]", name);
- if (name_len)
- dev_name = g_strdup(name);
- g_variant_unref(value);
- g_variant_unref(result);
- }
-
- if (name_len == 0) {
- GVariant *value;
- result = g_dbus_proxy_call_sync(device_proxy, "Get",
- g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Name"),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
- if (err) {
- ERR("DBus Error : %s", err->message);
- g_clear_error(&err);
- } else {
- g_variant_get(result, "(v)", &value);
- name = g_variant_get_string(value, &name_len);
- INFO_SECURE("Name = %s", name);
- if (name_len)
- dev_name = g_strdup(name);
- g_variant_unref(value);
- g_variant_unref(result);
- }
- }
-
- g_object_unref(device_proxy);
- return dev_name;
-}
-
-static gboolean __ignore_auto_pairing_request(const char *address)
-{
- gchar *buffer;
- char **lines;
- int i;
- char lap_address[BT_LOWER_ADDRESS_LENGTH + 1] = {0,};
- char *temp_buffer;
- FILE *fp;
- long size;
- size_t result;
-
- BT_DBG("+\n");
-
- if (address == NULL)
- return FALSE;
-
- /* Get the LAP(Lower Address part) */
- /* User BT_LOWER_ADDRESS_LENGTH+1 for lap_address to accomodate
- a "," */
- snprintf(lap_address, sizeof(lap_address), ",%s", address);
-
- fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "r");
-
- if (fp == NULL) {
- BT_ERR("fopen failed \n");
- return FALSE;
- }
-
- fseek(fp, 0, SEEK_END);
- size = ftell(fp);
- rewind(fp);
-
- if (size < 0) {
- BT_ERR("Get file size failed \n");
- fclose(fp);
- return FALSE;
- }
-
- buffer = g_malloc0(sizeof(char) * size);
- result = fread((char *)buffer, 1, size, fp);
- fclose(fp);
- if (result != size) {
- BT_ERR("Read Error\n");
- g_free(buffer);
- return FALSE;
- }
-
- BT_DBG("Buffer = %s\n", buffer);
-
- lines = g_strsplit_set(buffer, BT_AGENT_NEW_LINE, 0);
- g_free(buffer);
-
- if (lines == NULL)
- return FALSE;
-
- /* Write the data and insert new device data */
- for (i = 0; lines[i] != NULL; i++) {
- if (g_str_has_prefix(lines[i], "AddressBlacklist")) {
- temp_buffer = g_strconcat(lines[i], lap_address, NULL);
- g_free(lines[i]);
- lines[i] = temp_buffer;
- }
- }
- buffer = g_strjoinv(BT_AGENT_NEW_LINE, lines);
- g_strfreev(lines);
- /* Fix : NULL_RETURNS */
- retv_if(buffer == NULL, FALSE);
-
- fp = fopen(BT_AGENT_AUTO_PAIR_BLACKLIST_FILE, "w");
-
- if (fp == NULL) {
- BT_ERR("fopen failed \n");
- g_free(buffer);
- return FALSE;
- }
-
- BT_DBG("Buffer = %s\n", buffer);
- fwrite(buffer, 1, strlen(buffer), fp);
- fclose(fp);
-
- g_free(buffer);
-
- BT_DBG("-\n");
-
- return FALSE;
-}
-
-static int __bt_cancel_bonding(void)
-{
- BT_CHECK_PARAMETER(bonding_info, return);
- BT_CHECK_PARAMETER(bonding_info->addr, return);
- /* First Cancel the ongoing pairing in bluez otherwise if we send
- * pair request bluez will send inprogress and we again retry bond so
- * this cycle continues */
- GError *err = NULL;
- GVariant *result;
- result = g_dbus_proxy_call_sync(bonding_info->device_proxy, "CancelPairing",
- NULL, G_DBUS_CALL_FLAGS_NONE,
- 10000, NULL, &err);
- if (!result) {
- if (err) {
- BT_ERR("Cancelling bonding request error msg (%s)", err->message);
- g_clear_error(&err);
- return BLUETOOTH_ERROR_PARING_FAILED;
- }
- } else {
- g_variant_unref(result);
- }
- return BLUETOOTH_ERROR_NONE;
-}
-
-static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data)
-{
- int result = BLUETOOTH_ERROR_NONE;
- GError *err = NULL;
- GVariant *reply;
- GVariant *out_param1;
- request_info_t *req_info;
- bluetooth_device_info_t dev_info;
-
- /* Terminate ALL system popup */
- syspopup_destroy_all();
-
- reply = g_dbus_proxy_call_finish(proxy, res, &err);
- if (reply)
- g_variant_unref(reply);
-
- is_device_creating = FALSE;
-
- if (bonding_info == NULL) {
- /* Send reply */
- BT_ERR("bonding_info == NULL");
- if (err)
- g_error_free(err);
- return;
- }
-
- req_info = _bt_get_request_info(bonding_info->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- goto done;
- }
-
- if (err != NULL) {
- g_dbus_error_strip_remote_error(err);
- BT_ERR("Error occured in CreateBonding [%s]", err->message);
-
- if (g_strrstr(err->message, "Already Exists")) {
- BT_INFO("Existing Bond");
- result = BLUETOOTH_ERROR_ALREADY_CONNECT;
- } else if (_bt_agent_is_canceled() ||
- g_strrstr(err->message, "Authentication Canceled")) {
- BT_INFO("Cancelled by USER");
- result = BLUETOOTH_ERROR_CANCEL_BY_USER;
- } else if (g_strrstr(err->message, "Authentication Rejected")) {
- BT_INFO("REJECTED");
- result = BLUETOOTH_ERROR_ACCESS_DENIED;
- } else if (g_strrstr(err->message, "In Progress")) {
- BT_INFO("Bond in progress");
- result = BLUETOOTH_ERROR_IN_PROGRESS;
- } else if (g_strrstr(err->message, "Authentication Failed")) {
- BT_INFO("Authentication Failed");
- if (bonding_info->is_autopair == TRUE) {
- _bt_set_autopair_status_in_bonding_info(FALSE);
- __ignore_auto_pairing_request(bonding_info->addr);
- }
- result = BLUETOOTH_ERROR_AUTHENTICATION_FAILED;
- } else if (g_strrstr(err->message, "Page Timeout")) {
- BT_INFO("Page Timeout");
- /* This is the special case
- As soon as call bluetooth_bond_device, try to cancel bonding.
- In this case, before completing to call 'CreatePairedDevice' method
- the procedure is stopped. So 'Cancle' error is not return.
- */
- result = BLUETOOTH_ERROR_HOST_DOWN;
- } else if (g_strrstr(err->message, BT_DBUS_TIMEOUT_MESSAGE)) {
- BT_INFO("Cancel already running bonding");
- if (__bt_cancel_bonding() != BLUETOOTH_ERROR_NONE) {
- BT_INFO("Error while Cancelling bonding");
- /* we need to unref proxy so continue */
- }
- result = BLUETOOTH_ERROR_INTERNAL;
- } else if (g_strrstr(err->message, "Connection Timeout")) {
- /* Pairing request timeout */
- result = BLUETOOTH_ERROR_TIMEOUT;
- } else if (g_strrstr(err->message, "Authentication Timeout")) {
- /* Pairing request timeout */
- result = BLUETOOTH_ERROR_TIMEOUT;
- } else {
- BT_DBG("Default case");
- result = BLUETOOTH_ERROR_PARING_FAILED;
- }
- }
-
- if (result == BLUETOOTH_ERROR_PARING_FAILED ||
- result == BLUETOOTH_ERROR_AUTHENTICATION_FAILED ||
- result == BLUETOOTH_ERROR_TIMEOUT ||
- result == BLUETOOTH_ERROR_HOST_DOWN) {
-#ifdef TIZEN_PROFILE_WEARABLE
- int is_sw_running = 0;
-
- if (vconf_get_int(VCONFKEY_SETUP_WIZARD_STATE, &is_sw_running))
- BT_ERR("vconf_get_int for setup wizard state failed");
-
- if (!is_sw_running)
- __bt_launch_unable_to_pairing_syspopup(result);
- else
- BT_ERR("Unable to pair");
-#endif
- bonding_info->result = result;
- }
-
- g_object_unref(proxy);
- bonding_info->device_proxy = NULL;
-
- if (result != BLUETOOTH_ERROR_NONE) {
- if (bonding_info->bonding_wo_discovery) {
- GDBusProxy *adapter_proxy;
- GVariant *ret = NULL;
- GError *error = NULL;
- char *device_path;
-
- BT_ERR("Bond was tried without discovery. Remove it");
-
- adapter_proxy = _bt_get_adapter_proxy();
- if (adapter_proxy == NULL) {
- BT_ERR("Cannot get adapter_proxy");
- goto dbus_return;
- }
-
- device_path = _bt_get_device_object_path(bonding_info->addr);
- if (device_path == NULL) {
- BT_ERR("Cannot get device path");
- goto dbus_return;
- }
-
- ret = g_dbus_proxy_call_sync(adapter_proxy,
- "RemoveDevice",
- g_variant_new("(o)", device_path),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- &error);
- if (error != NULL) {
- BT_ERR("RemoveDevice Fail: %s", error->message);
- g_clear_error(&error);
- }
-
- if (ret)
- g_variant_unref(ret);
-
- g_free(device_path);
- }
-
- goto dbus_return;
- }
-
-dbus_return:
- if (req_info->context == NULL)
- goto done;
-
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
- _bt_convert_addr_string_to_type(dev_info.device_address.addr,
- bonding_info->addr);
-
- if (_bt_adapter_get_status() != BT_ACTIVATED)
- result = BLUETOOTH_ERROR_NOT_IN_OPERATION;
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("(iv)", result, out_param1));
-
- g_variant_unref(out_param1);
-
- _bt_delete_request_list(req_info->req_id);
-done:
- if (err)
- g_error_free(err);
-
- _bt_agent_set_canceled(FALSE);
-
-
- g_free(bonding_info->addr);
- g_free(bonding_info);
- bonding_info = NULL;
-}
-
-int _bt_bond_device(int request_id,
- bluetooth_device_address_t *device_address,
- unsigned short conn_type, GArray **out_param1)
-{
- GDBusProxy *proxy;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- bluetooth_device_info_t dev_info;
-
- GDBusConnection *conn;
- char *device_path = NULL;
- GDBusProxy *adapter_proxy;
- GError *error = NULL;
- gboolean bonding_wo_discovery = FALSE;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- if (bonding_info) {
- BT_ERR("Bonding in progress");
-
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
- memcpy(dev_info.device_address.addr, device_address->addr,
- BLUETOOTH_ADDRESS_LENGTH);
-
- g_array_append_vals(*out_param1, &dev_info,
- sizeof(bluetooth_device_info_t));
-
- return BLUETOOTH_ERROR_DEVICE_BUSY;
- }
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- device_path = _bt_get_device_object_path(address);
-
- if (device_path == NULL) {
- BT_ERR("No searched device");
- GVariant *ret = NULL;
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- ret = g_dbus_proxy_call_sync(adapter_proxy, "CreateDevice",
- g_variant_new("(s)", address),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error != NULL) {
- BT_ERR("CreateDevice Fail: %s", error->message);
- g_clear_error(&error);
- }
- if (ret)
- g_variant_unref(ret);
- device_path = _bt_get_device_object_path(address);
- if (device_path == NULL) {
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
- memcpy(dev_info.device_address.addr, device_address->addr,
- BLUETOOTH_ADDRESS_LENGTH);
-
- g_array_append_vals(*out_param1, &dev_info,
- sizeof(bluetooth_device_info_t));
-
- return BLUETOOTH_ERROR_NOT_PAIRED;
- } else {
- BT_INFO("device_path is created[%s]", device_path);
- }
- bonding_wo_discovery = TRUE;
- }
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_DEVICE_INTERFACE, NULL, NULL);
-
- g_free(device_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- bonding_info = g_malloc0(sizeof(bt_funcion_data_t));
- bonding_info->addr = g_strdup(address);
- bonding_info->req_id = request_id;
-
- bonding_info->device_proxy = proxy;
- bonding_info->conn_type = conn_type;
- bonding_info->bonding_wo_discovery = bonding_wo_discovery;
-
- is_device_creating = TRUE;
-
- g_dbus_proxy_call(proxy, "Pair",
- g_variant_new("(y)", conn_type),
- G_DBUS_CALL_FLAGS_NONE,
- BT_MAX_DBUS_TIMEOUT,
- NULL,
- (GAsyncReadyCallback)__bt_bond_device_cb,
- NULL);
-
-/* TODO: We need to check if we can pair the specific device using 'pair' API of bluez 5.x */
-
- return BLUETOOTH_ERROR_NONE;
-/*fail:
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
- _bt_convert_addr_string_to_type(dev_info.device_address.addr,
- bonding_info->addr);
-
- g_array_append_vals(*out_param1, &dev_info,
- sizeof(bluetooth_device_info_t));
-
- is_device_creating = FALSE;
-
- g_free(bonding_info->addr);
- g_free(bonding_info);
- bonding_info = NULL;
-
- return BLUETOOTH_ERROR_INTERNAL;*/
-}
-
-int _bt_cancel_bonding(void)
-{
- int ret = BLUETOOTH_ERROR_NONE;
-
- retv_if(bonding_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
-
- ret = _bt_agent_reply_cancellation();
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Fail to call reply cancellation");
- return ret;
- }
-
- _bt_agent_set_canceled(TRUE);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-static void __bt_unbond_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data)
-{
- GError *err = NULL;
- GVariant *reply;
- GVariant *out_param1;
- int result = BLUETOOTH_ERROR_NONE;
- bt_funcion_data_t *unbonding_info;
- bluetooth_device_info_t dev_info;
- request_info_t *req_info;
-
- reply = g_dbus_proxy_call_finish(proxy, res, &err);
- if (reply)
- g_variant_unref(reply);
-
- unbonding_info = user_data;
-
- if (unbonding_info == NULL) {
- /* Send reply */
- BT_ERR("unbonding_info == NULL");
- goto done;
- }
-
- req_info = _bt_get_request_info(unbonding_info->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- goto done;
- }
-
- if (err != NULL) {
- BT_ERR("Error occured in RemoveBonding [%s]\n", err->message);
- result = BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (req_info->context == NULL)
- goto done;
-
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
- _bt_convert_addr_string_to_type(dev_info.device_address.addr,
- unbonding_info->addr);
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("(iv)", result, out_param1));
-
-
- _bt_delete_request_list(req_info->req_id);
-
-done:
- if (err)
- g_error_free(err);
-
- if (unbonding_info) {
- g_free(unbonding_info->addr);
- g_free(unbonding_info);
- }
-}
-
-int _bt_unbond_device(int request_id,
- bluetooth_device_address_t *device_address,
- GArray **out_param1)
-{
- char *device_path = NULL;
- bt_funcion_data_t *unbonding_info;
- GDBusProxy *adapter_proxy = NULL;
- GDBusProxy *device_proxy = NULL;
- GDBusConnection *conn;
- int result = BLUETOOTH_ERROR_INTERNAL;
- bluetooth_device_info_t dev_info;
- GError *error = NULL;
- GVariant *ret = NULL;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- /* allocate user data so that it can be retrieved in callback */
- unbonding_info = g_malloc0(sizeof(bt_funcion_data_t));
- unbonding_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
- unbonding_info->req_id = request_id;
-
- _bt_convert_addr_type_to_string(unbonding_info->addr,
- device_address->addr);
-
- device_path = _bt_get_device_object_path(unbonding_info->addr);
-
- if (device_path == NULL) {
- BT_ERR("No paired device");
- result = BLUETOOTH_ERROR_NOT_PAIRED;
- goto fail;
- }
-
- conn = _bt_gdbus_get_system_gconn();
- if (conn == NULL) {
- BT_ERR("conn is NULL");
- result = BLUETOOTH_ERROR_INTERNAL;
- goto fail;
- }
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
-
- if (device_proxy != NULL) {
-
- ret = g_dbus_proxy_call_sync(device_proxy, "Get",
- g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Paired"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (error) {
- BT_ERR("Getting property failed: [%s]\n", error->message);
- g_error_free(error);
- result = BLUETOOTH_ERROR_NOT_PAIRED;
- goto fail;
- } else {
- if (!ret) {
- BT_ERR("No paired device");
- g_object_unref(device_proxy);
- result = BLUETOOTH_ERROR_NOT_PAIRED;
- goto fail;
- }
- g_variant_unref(ret);
- }
- g_object_unref(device_proxy);
- }
-
- g_dbus_proxy_call(adapter_proxy, "UnpairDevice",
- g_variant_new("(o)", device_path),
- G_DBUS_CALL_FLAGS_NONE,
- BT_MAX_DBUS_TIMEOUT,
- NULL,
- (GAsyncReadyCallback)__bt_unbond_cb,
- unbonding_info);
-
- g_free(device_path);
- return BLUETOOTH_ERROR_NONE;
-
-fail:
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
- _bt_convert_addr_string_to_type(dev_info.device_address.addr,
- unbonding_info->addr);
-
- g_array_append_vals(*out_param1, &dev_info,
- sizeof(bluetooth_device_info_t));
- g_free(device_path);
- g_free(unbonding_info->addr);
- g_free(unbonding_info);
- return result;
-}
-
-static void __bt_discover_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data)
-{
- GError *err = NULL;
- GVariant *reply;
- GVariant *out_param1;
- int result = BLUETOOTH_ERROR_NONE;
- bluetooth_device_info_t dev_info;
- bt_remote_dev_info_t *remote_dev_info;
- request_info_t *req_info;
- GVariant *uuid_list, *manufacture_data;
- GVariant *param;
- GVariantBuilder *builder = NULL;
- int i = 0;
-
- reply = g_dbus_proxy_call_finish(proxy, res, &err);
- if (reply)
- g_variant_unref(reply);
-
- g_object_unref(proxy);
-
- if (searching_info == NULL) {
- /* Send reply */
- BT_ERR("unbonding_info == NULL");
- goto done;
- }
-
- req_info = _bt_get_request_info(searching_info->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- goto done;
- }
-
- if (err != NULL) {
- g_dbus_error_strip_remote_error(err);
- BT_ERR("Error occured in Proxy call [%s]\n", err->message);
-
- if (g_strrstr("Operation canceled", err->message))
- result = BLUETOOTH_ERROR_CANCEL_BY_USER;
- else if (g_strrstr("In Progress", err->message))
- result = BLUETOOTH_ERROR_IN_PROGRESS;
- else if (g_strrstr("Host is down", err->message))
- result = BLUETOOTH_ERROR_HOST_DOWN;
- else
- result = BLUETOOTH_ERROR_CONNECTION_ERROR;
-
- if (result == BLUETOOTH_ERROR_HOST_DOWN ||
- result == BLUETOOTH_ERROR_CONNECTION_ERROR) {
- remote_dev_info = _bt_get_remote_device_info(searching_info->addr);
- if (remote_dev_info && remote_dev_info->uuids != NULL &&
- remote_dev_info->uuid_count > 0) {
- result = BLUETOOTH_ERROR_NONE;
- goto event;
- }
- _bt_free_device_info(remote_dev_info);
- }
- goto dbus_return;
- }
-
- remote_dev_info = _bt_get_remote_device_info(searching_info->addr);
- if (!remote_dev_info)
- goto dbus_return;
-
-event:
- builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
- for (i = 0; i < remote_dev_info->uuid_count; i++) {
- g_variant_builder_add(builder, "s",
- remote_dev_info->uuids[i]);
- }
- uuid_list = g_variant_new("as", builder);
- g_variant_builder_unref(builder);
- manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
- remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
- TRUE, NULL, NULL);
-
- param = g_variant_new("(isunsbub@asn@ay)",
- result,
- searching_info->addr,
- remote_dev_info->class,
- remote_dev_info->rssi,
- remote_dev_info->name,
- remote_dev_info->paired,
- remote_dev_info->connected,
- remote_dev_info->trust,
- uuid_list,
- remote_dev_info->manufacturer_data_len,
- manufacture_data);
-
- /* Send the event to application */
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_SERVICE_SEARCHED,
- param);
-
- _bt_free_device_info(remote_dev_info);
-
-dbus_return:
- if (req_info->context == NULL)
- goto done;
-
- memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
- _bt_convert_addr_string_to_type(dev_info.device_address.addr,
- searching_info->addr);
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- &dev_info, sizeof(bluetooth_device_info_t), TRUE, NULL, NULL);
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("(iv)", result, out_param1));
-
-
- _bt_delete_request_list(req_info->req_id);
-done:
- if (err)
- g_error_free(err);
-
- if (searching_info) {
- g_free(searching_info->addr);
- g_free(searching_info);
- searching_info = NULL;
- }
-}
-
-int _bt_search_device(int request_id,
- bluetooth_device_address_t *device_address)
-{
- char *device_path = NULL;
- GDBusProxy *device_proxy = NULL;
- GDBusConnection *conn;
-
- GDBusProxy *adapter_proxy;
- int result = BLUETOOTH_ERROR_INTERNAL;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- if (bonding_info) {
- BT_ERR("Bonding in progress");
- return BLUETOOTH_ERROR_DEVICE_BUSY;
- }
-
- if (searching_info) {
- BT_ERR("Service searching in progress");
- return BLUETOOTH_ERROR_DEVICE_BUSY;
- }
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- /* allocate user data so that it can be retrieved in callback */
- searching_info = g_malloc0(sizeof(bt_funcion_data_t));
- searching_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
- searching_info->req_id = request_id;
-
- _bt_convert_addr_type_to_string(searching_info->addr,
- device_address->addr);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-
- device_path = _bt_get_device_object_path(searching_info->addr);
-
- if (device_path == NULL) {
- BT_ERR("No paired device");
- result = BLUETOOTH_ERROR_NOT_PAIRED;
- goto fail;
- }
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_DEVICE_INTERFACE, NULL, NULL);
- g_free(device_path);
- if (device_proxy == NULL) {
- result = BLUETOOTH_ERROR_INTERNAL;
- goto fail;
- }
-
- g_dbus_proxy_call(device_proxy, "DiscoverServices",
- g_variant_new("(s)", ""),
- G_DBUS_CALL_FLAGS_NONE,
- BT_MAX_DBUS_TIMEOUT,
- NULL,
- (GAsyncReadyCallback)__bt_discover_cb,
- searching_info);
-
- searching_info->device_proxy = device_proxy;
-
- return BLUETOOTH_ERROR_NONE;
-fail:
-
- g_free(searching_info->addr);
- g_free(searching_info);
- searching_info = NULL;
- return result;
-}
-
-int _bt_cancel_search_device(void)
-{
- GVariant *ret = NULL;
- GError *err = NULL;
-
- retv_if(searching_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
-
- if (searching_info->device_proxy) {
- ret = g_dbus_proxy_call_sync(searching_info->device_proxy, "CancelDiscovery",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &err);
- if (ret)
- g_variant_unref(ret);
- }
- __bt_cancel_search_service_done();
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_set_alias(bluetooth_device_address_t *device_address,
- const char *alias)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- gchar *device_path = NULL;
- GDBusProxy *adapter_proxy;
- GDBusProxy *device_proxy;
- GVariant *ret = NULL;
- GError *error = NULL;
- GDBusConnection *conn;
-
- BT_CHECK_PARAMETER(device_address, return);
- BT_CHECK_PARAMETER(alias, return);
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- device_path = _bt_get_device_object_path(address);
-
- if (device_path == NULL) {
- BT_ERR("No paired device");
- return BLUETOOTH_ERROR_NOT_PAIRED;
- }
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
-
- g_free(device_path);
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- ret = g_dbus_proxy_call_sync(device_proxy, "Set",
- g_variant_new("(ssv)", BT_DEVICE_INTERFACE, "Alias", g_variant_new("s", alias)),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (ret)
- g_variant_unref(ret);
-
- g_object_unref(device_proxy);
-
- if (error) {
- BT_ERR("SetProperty error: [%s]", error->message);
- g_error_free(error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_set_authorization(bluetooth_device_address_t *device_address,
- gboolean authorize)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- gchar *device_path = NULL;
- GDBusProxy *device_proxy;
- gboolean previous_value;
- GError *error = NULL;
- GDBusConnection *conn;
- GVariant *result = NULL;
- GVariant *temp = NULL;
- int ret = BLUETOOTH_ERROR_NONE;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- device_path = _bt_get_device_object_path(address);
-
- if (device_path == NULL) {
- BT_ERR("No paired device");
- return BLUETOOTH_ERROR_NOT_PAIRED;
- }
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
-
- g_free(device_path);
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(device_proxy, "Get",
- g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Trusted"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (error != NULL) {
- BT_ERR("Getting property failed: [%s]\n", error->message);
- g_error_free(error);
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(result, "(v)", &temp);
- previous_value = g_variant_get_boolean(temp);
- g_variant_unref(temp);
- g_variant_unref(result);
- /* If the input is same with previous value, return error. */
- if (previous_value == authorize) {
- BT_ERR("Same value: %d", previous_value);
- g_object_unref(device_proxy);
- ret = BLUETOOTH_ERROR_INVALID_PARAM;
- goto done;
- }
-
- result = g_dbus_proxy_call_sync(device_proxy, "Set",
- g_variant_new("(ssv)", BT_DEVICE_INTERFACE, "Trusted", g_variant_new("b", authorize)),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- g_object_unref(device_proxy);
- if (error) {
- BT_ERR("SetProperty error: [%s]", error->message);
- g_error_free(error);
- ret = BLUETOOTH_ERROR_INTERNAL;
- }
-done:
- if (result)
- g_variant_unref(result);
-
- return ret;
-}
-
-int _bt_is_gatt_connected(bluetooth_device_address_t *device_address,
- gboolean *is_connected)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char *object_path = NULL;
-
- GDBusProxy *device_proxy;
- GError *error = NULL;
- GVariant *value;
- GDBusConnection *conn;
- GVariant *result = NULL;
- int ret = BLUETOOTH_ERROR_NONE;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- object_path = _bt_get_device_object_path(address);
- retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME, object_path,
- BT_PROPERTIES_INTERFACE, NULL, NULL);
- g_free(object_path);
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(device_proxy, "Get",
- g_variant_new("(ss)", BT_DEVICE_INTERFACE,
- "GattConnected"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (result == NULL) {
- if (error != NULL) {
- BT_ERR("Error occured in Proxy call [%s]\n", error->message);
- g_error_free(error);
- }
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(result, "(v)", &value);
- *is_connected = g_variant_get_boolean(value);
- g_variant_unref(result);
-
- BT_DBG("gatt is connected : %d", *is_connected);
-
- g_variant_unref(value);
- g_object_unref(device_proxy);
-
- return ret;
-}
-
-int _bt_is_device_connected(bluetooth_device_address_t *device_address,
- int connection_type, gboolean *is_connected)
-{
- char *object_path = NULL;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- GDBusProxy *device_proxy = NULL;
- GDBusProxy *adapter_proxy = NULL;
- GDBusConnection *conn;
- GError *error = NULL;
- GVariant *tmp_value = NULL;
- GVariant *value = NULL;
- GVariant *result = NULL;
- char *uuid = NULL;
-
- retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
- retv_if(is_connected == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
- _bt_convert_addr_string_to_secure_string(secure_address, address);
-
- *is_connected = FALSE;
- BT_DBG("%s connection_type: 0x%02x", secure_address, connection_type);
-
- if (connection_type == BLUETOOTH_RFCOMM_SERVICE)
- return _bt_rfcomm_is_device_connected(device_address,
- is_connected);
- else if (connection_type == BLUETOOTH_GATT_SERVICE)
- return _bt_is_gatt_connected(device_address, is_connected);
- else if (connection_type == BLUETOOTH_PBAP_SERVICE)
- return _bt_pbap_is_connected(device_address, is_connected);
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- if (connection_type == BLUETOOTH_NAP_SERVER_SERVICE) {
- object_path = _bt_get_adapter_path();
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- object_path, BT_NETWORK_SERVER_INTERFACE, NULL, NULL);
- g_free(object_path);
- if (device_proxy == NULL) {
- BT_DBG("Device don't have this service");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- result = g_dbus_proxy_call_sync(device_proxy, "GetProperties",
- g_variant_new("(s)", address),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (result == NULL) {
- BT_ERR("[GetProperties] Error occured in Proxy call");
- if (error) {
- BT_ERR("%s", error->message);
- g_error_free(error);
- }
- *is_connected = FALSE;
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_NONE;
- }
- g_variant_get(result , "(@a{sv})", &value);
- g_variant_unref(result);
-
- if (value) {
- tmp_value = g_variant_lookup_value(value,
- "Connected",
- G_VARIANT_TYPE_BOOLEAN);
- if (tmp_value) {
- *is_connected = g_variant_get_boolean(tmp_value);
- g_variant_unref(tmp_value);
- }
- g_variant_unref(value);
- }
- } else if (connection_type == BLUETOOTH_NAP_SERVICE) {
- return _bt_is_network_connected(_bt_get_net_conn(),
- device_address->addr, is_connected);
- } else {
- uuid = _bt_get_profile_uuid128(connection_type);
- if (uuid == NULL) {
- BT_ERR("connection_type: %d, uuid is NULL", connection_type);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- BT_DBG("uuid %s [%s]", uuid, _bt_convert_uuid_to_string(uuid));
-
- object_path = _bt_get_device_object_path(address);
- retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
- BT_DBG("object_path: %s", object_path);
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- object_path, BT_DEVICE_INTERFACE, NULL, NULL);
- g_free(object_path);
- if (device_proxy == NULL) {
- BT_DBG("Device don't have this service");
- g_free(uuid);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- result = g_dbus_proxy_call_sync(device_proxy, "IsConnectedProfile",
- g_variant_new("(s)", uuid),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (result == NULL) {
- BT_ERR("[IsConnectedProfile] Error occured in Proxy call");
- if (error) {
- BT_ERR("%s", error->message);
- if (g_strrstr(error->message, "Not Connected"))
- BT_DBG("Not connected");
- g_error_free(error);
- }
- *is_connected = FALSE;
- g_object_unref(device_proxy);
- g_free(uuid);
- return BLUETOOTH_ERROR_NONE;
- }
- g_variant_get(result, "(b)", is_connected);
- g_free(uuid);
- g_variant_unref(result);
- }
-
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_get_connected_link(bluetooth_device_address_t *device_address,
- bluetooth_connected_link_t *connected)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char *object_path = NULL;
-
- GDBusProxy *device_proxy;
- GError *error = NULL;
- GDBusConnection *conn;
- GVariant *value = NULL;
- GVariant *result = NULL;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- object_path = _bt_get_device_object_path(address);
- retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- object_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
- g_free(object_path);
- if (device_proxy == NULL) {
- *connected = BLUETOOTH_CONNECTED_LINK_NONE;
- return BLUETOOTH_ERROR_NONE;
- }
-
- result = g_dbus_proxy_call_sync(device_proxy, "Get",
- g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Connected"),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
- if (error != NULL) {
- BT_ERR("Error occured in Proxy call [%s]\n", error->message);
- g_error_free(error);
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_INTERNAL;
- } else {
- g_variant_get(result, "(v)", &value);
- *connected = g_variant_get_byte(value);
- g_variant_unref(value);
- g_variant_unref(result);
- }
-
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_NONE;
-}
-
-static void __le_connection_req_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data)
-{
- GError *err = NULL;
- GVariant *out_param1;
- GVariant *reply;
- int result = BLUETOOTH_ERROR_NONE;
- bt_function_data_t *func_data = user_data;
- request_info_t *req_info = NULL;
- bluetooth_device_address_t device_addr = { {0} };
-
- reply = g_dbus_proxy_call_finish(proxy, res, &err);
- g_object_unref(proxy);
-
- if (reply == NULL) {
- BT_ERR("ConnectLE / DisconnectLE DBus call error");
- if (err) {
- BT_ERR("Error: %s", err->message);
- g_clear_error(&err);
- }
- result = BLUETOOTH_ERROR_INTERNAL;
- } else {
- g_variant_unref(reply);
- }
-
- if (func_data == NULL) {
- BT_ERR("func_data is NULL");
- goto done;
- }
-
- req_info = _bt_get_request_info(func_data->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info is NULL");
- goto done;
- }
-
- if (req_info->context == NULL) {
- BT_ERR("req_info->context is NULL");
- goto done;
- }
-
- _bt_convert_addr_string_to_type(device_addr.addr,
- (const char *)func_data->address);
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- &device_addr, sizeof(bluetooth_device_address_t), TRUE,
- NULL, NULL);
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("(iv)", result, out_param1));
-
-done:
- if (req_info)
- _bt_delete_request_list(req_info->req_id);
-
- if (func_data) {
- g_free(func_data->address);
- g_free(func_data);
- }
-}
-
-static int __bt_connect_le_device_internal(int req_id, const bluetooth_device_address_t *bd_addr,
- gboolean auto_connect)
-{
- char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- gchar *device_path = NULL;
- GDBusProxy *device_proxy = NULL;
- GDBusConnection *conn;
- int ret = BLUETOOTH_ERROR_NONE;
- bt_function_data_t *func_data;
-
- BT_CHECK_PARAMETER(bd_addr, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(device_address,
- (unsigned char *)bd_addr->addr);
- device_path = _bt_get_device_object_path(device_address);
- if (device_path == NULL) {
- BT_ERR_C("device_path NULL : [%s]", device_address);
- ret = BLUETOOTH_ERROR_INTERNAL;
- return ret;
- }
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_DEVICE_INTERFACE, NULL, NULL);
- g_free(device_path);
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- func_data = g_malloc0(sizeof(bt_function_data_t));
- func_data->address = g_strdup(device_address);
- if (func_data->address == NULL) {
- BT_ERR("Unable to allocate memory for address");
- ret = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
- goto fail;
- }
-
- _bt_convert_addr_string_to_secure_string(secure_address, device_address);
- BT_INFO("Connect LE [%s]", secure_address);
-
- func_data->req_id = req_id;
-
- g_dbus_proxy_call(device_proxy, "ConnectLE",
- g_variant_new("(b)", auto_connect),
- G_DBUS_CALL_FLAGS_NONE,
- BT_MAX_DBUS_TIMEOUT,
- NULL,
- (GAsyncReadyCallback)__le_connection_req_cb, func_data);
-
- return ret;
-
-fail:
- if (device_proxy)
- g_object_unref(device_proxy);
-
- g_free(func_data->address);
- g_free(func_data);
-
- return ret;
-}
-
-static gboolean __bt_connect_le_timer_cb(gpointer user_data)
-{
- BT_INFO("Try to initiate pending LE connection");
-
- pending_le_conn_timer_id = 0;
-
- __bt_connect_le_device_internal(pending_le_conn_info->req_id,
- &pending_le_conn_info->bd_addr,
- pending_le_conn_info->auto_connect);
-
- g_free(pending_le_conn_info);
- pending_le_conn_info = NULL;
-
- return FALSE;
-}
-
-void _bt_pending_connect_le_device(void)
-{
- if (pending_le_conn_timer_id > 0) {
- g_source_remove(pending_le_conn_timer_id);
- __bt_connect_le_timer_cb(NULL);
- }
-}
-
-int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
- gboolean auto_connect)
-{
- int ret = BLUETOOTH_ERROR_NONE;
-
- BT_CHECK_PARAMETER(bd_addr, return);
-
- ret = _bt_hold_current_advertising();
- if (ret == BLUETOOTH_ERROR_NONE) {
- BT_INFO("Current advertising is held");
- pending_le_conn_info = g_malloc0(sizeof(bt_pending_le_conn_info_s));
- pending_le_conn_info->req_id = req_id;
- memcpy(pending_le_conn_info->bd_addr.addr, bd_addr->addr,
- BLUETOOTH_ADDRESS_LENGTH);
- pending_le_conn_info->auto_connect = auto_connect;
-
- pending_le_conn_timer_id =
- g_timeout_add(1000, __bt_connect_le_timer_cb, NULL);
-
- return BLUETOOTH_ERROR_NONE;
- } else if (ret != BLUETOOTH_ERROR_NOT_IN_OPERATION) {
- BT_ERR("Unable to hold advertising");
- }
-
- return __bt_connect_le_device_internal(req_id, bd_addr, auto_connect);
-}
-
-int _bt_disconnect_le_device(int req_id,
- const bluetooth_device_address_t *bd_addr)
-{
- char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- gchar *device_path;
- GDBusProxy *device_proxy;
- GDBusConnection *conn;
- int ret = BLUETOOTH_ERROR_NONE;
- bt_function_data_t *func_data;
-
- BT_CHECK_PARAMETER(bd_addr, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(device_address,
- (unsigned char *)bd_addr->addr);
- device_path = _bt_get_device_object_path(device_address);
- if (device_path == NULL) {
- BT_DBG("device_path NULL");
- ret = BLUETOOTH_ERROR_INTERNAL;
- return ret;
- }
-
- retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_DEVICE_INTERFACE, NULL, NULL);
- g_free(device_path);
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- func_data = g_malloc0(sizeof(bt_function_data_t));
- func_data->address = g_strdup(device_address);
- if (func_data->address == NULL) {
- BT_ERR("Unable to allocate memory for address");
- ret = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
- goto fail;
- }
-
- _bt_convert_addr_string_to_secure_string(secure_address, device_address);
- BT_INFO("Disconnect LE [%s]", secure_address);
-
- func_data->req_id = req_id;
-
- g_dbus_proxy_call(device_proxy, "DisconnectLE",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- BT_MAX_DBUS_TIMEOUT,
- NULL,
- (GAsyncReadyCallback)__le_connection_req_cb, func_data);
- return ret;
-
-fail:
- if (device_proxy)
- g_object_unref(device_proxy);
-
- g_free(func_data->address);
- g_free(func_data);
-
- return ret;
-}
-
-int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
-{
- char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- gchar *device_path = NULL;
- GError *error = NULL;
- GDBusProxy *device_proxy = NULL;
- GDBusProxy *adapter_proxy;
- GDBusConnection *conn;
- int ret = BLUETOOTH_ERROR_NONE;
- GVariant *result;
-
- BT_CHECK_PARAMETER(bd_addr, return);
-
- _bt_convert_addr_type_to_string(device_address,
- (unsigned char *)bd_addr->addr);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- device_path = _bt_get_device_object_path(device_address);
- if (device_path == NULL) {
- BT_DBG("device_path NULL");
- ret = BLUETOOTH_ERROR_INTERNAL;
- return ret;
- }
-
- retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_DEVICE_INTERFACE, NULL, NULL);
- g_free(device_path);
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(device_proxy, "ConnectIpsp",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (!result) {
- if (error) {
- BT_ERR("ConnectIpsp Call Error %s[%s]", error->message, device_address);
- g_error_free(error);
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- } else {
- g_variant_unref(result);
- }
-
- g_object_unref(device_proxy);
-
- return ret;
-}
-
-int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
-{
- char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- gchar *device_path = NULL;
- GError *error = NULL;
- GDBusProxy *device_proxy = NULL;
- GDBusProxy *adapter_proxy;
- GDBusConnection *conn;
- int ret = BLUETOOTH_ERROR_NONE;
- GVariant *result;
-
- BT_CHECK_PARAMETER(bd_addr, return);
-
- _bt_convert_addr_type_to_string(device_address,
- (unsigned char *)bd_addr->addr);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- device_path = _bt_get_device_object_path(device_address);
- if (device_path == NULL) {
- BT_DBG("device_path NULL");
- ret = BLUETOOTH_ERROR_INTERNAL;
- return ret;
- }
-
- retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_DEVICE_INTERFACE, NULL, NULL);
- g_free(device_path);
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(device_proxy, "DisconnectIpsp",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (!result) {
- if (error) {
- BT_ERR("DisconnectIpsp Call Error %s[%s]", error->message, device_address);
- g_error_free(error);
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- } else {
- g_variant_unref(result);
- }
-
- g_object_unref(device_proxy);
-
- return ret;
-}
-
-int _bt_connect_profile(char *address, char *uuid,
- void *cb, gpointer func_data)
-{
- char *object_path;
- GDBusProxy *proxy;
- GDBusConnection *conn;
- GDBusProxy *adapter_proxy;
- GVariant *result = NULL;
- GError *error = NULL;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- object_path = _bt_get_device_object_path(address);
- if (object_path == NULL) {
- BT_ERR("No searched device");
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(adapter_proxy, "CreateDevice",
- g_variant_new("(s)", address),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error != NULL) {
- BT_ERR("CreateDevice Fail: %s", error->message);
- g_error_free(error);
- }
- if (result)
- g_variant_unref(result);
-
- object_path = _bt_get_device_object_path(address);
- }
- retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- object_path, BT_DEVICE_INTERFACE, NULL, NULL);
- g_free(object_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- g_dbus_proxy_call(proxy, "ConnectProfile",
- g_variant_new("(s)", uuid),
- G_DBUS_CALL_FLAGS_NONE,
- BT_MAX_DBUS_TIMEOUT,
- NULL,
- (GAsyncReadyCallback)cb,
- func_data);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_disconnect_all(char *address)
-{
- int ret = BLUETOOTH_ERROR_NONE;
- char *object_path;
- GDBusProxy *proxy;
- GDBusConnection *conn;
- GVariant *result = NULL;
- GError *err = NULL;
-
- BT_DBG("");
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- object_path = _bt_get_device_object_path(address);
- retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- object_path, BT_DEVICE_INTERFACE, NULL, NULL);
- g_free(object_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy, "Disconnect",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- &err);
-
- if (err != NULL) {
- BT_ERR("Dbus Call Error:[%s]", err->message);
- g_error_free(err);
- ret = BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_object_unref(proxy);
- if (result)
- g_variant_unref(result);
-
- return ret;
-}
-
-int _bt_disconnect_profile(char *address, char *uuid,
- void *cb, gpointer func_data)
-{
- char *object_path;
- GDBusProxy *proxy;
- GDBusConnection *conn;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- object_path = _bt_get_device_object_path(address);
- retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- object_path, BT_DEVICE_INTERFACE, NULL, NULL);
- g_free(object_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- g_dbus_proxy_call(proxy, "DisconnectProfile",
- g_variant_new("(s)", uuid),
- G_DBUS_CALL_FLAGS_NONE,
- BT_MAX_DBUS_TIMEOUT,
- NULL,
- (GAsyncReadyCallback)cb,
- func_data);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_enable_rssi(bluetooth_device_address_t *bd_addr, int link_type,
- int low_threshold, int in_range_threshold, int high_threshold)
-{
- int ret = BLUETOOTH_ERROR_NONE;
- GDBusProxy *proxy;
- GVariant *result = NULL;
- GError *error = NULL;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
-
- BT_CHECK_PARAMETER(bd_addr, return);
- BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] Link Type[%d]",
- bd_addr->addr[0], bd_addr->addr[1],
- bd_addr->addr[2], bd_addr->addr[3],
- bd_addr->addr[4], bd_addr->addr[5],
- link_type);
- BT_DBG("Enable RSSI: [Threshold %d %d %d]", low_threshold,
- in_range_threshold, high_threshold);
-
- _bt_convert_addr_type_to_string(address, bd_addr->addr);
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy, "EnableRssi",
- g_variant_new("(siiii)", address, link_type, low_threshold, in_range_threshold, high_threshold),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (error != NULL) {
- BT_ERR("Dbus Call Error:[%s]", error->message);
- g_error_free(error);
- ret = BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (result)
- g_variant_unref(result);
-
- return ret;
-}
-
-int _bt_get_rssi_strength(bluetooth_device_address_t *bd_addr,
- int link_type)
-{
- int ret = BLUETOOTH_ERROR_NONE;
- GDBusProxy *proxy;
- GVariant *result = NULL;
- GError *error = NULL;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
-
- BT_CHECK_PARAMETER(bd_addr, return);
- BT_DBG("BD Address [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X] Link Type[%d]",
- bd_addr->addr[0], bd_addr->addr[1],
- bd_addr->addr[2], bd_addr->addr[3],
- bd_addr->addr[4], bd_addr->addr[5],
- link_type);
-
- _bt_convert_addr_type_to_string(address, bd_addr->addr);
-
- proxy = _bt_get_adapter_proxy();
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy, "GetRssiStrength",
- g_variant_new("(si)", address, link_type),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (error != NULL) {
- BT_ERR("Dbus Call Error:[%s]", error->message);
- g_error_free(error);
- ret = BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (result)
- g_variant_unref(result);
-
- return ret;
-}
-
-static int __bt_le_set_conn_parameter(const char *address,
- float interval_min, float interval_max,
- guint16 latency, guint16 time_out)
-{
- gchar *device_path = NULL;
- GError *error = NULL;
- GDBusProxy *device_proxy = NULL;
- GDBusConnection *conn;
- GVariant *reply;
- guint32 min, max, to;
- int ret = BLUETOOTH_ERROR_NONE;
-
- BT_CHECK_PARAMETER(address, return);
-
- BT_INFO("Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u",
- interval_min, interval_max, latency, time_out);
-
- device_path = _bt_get_device_object_path((char *)address);
-
- if (device_path == NULL) {
- BT_ERR("device_path NULL");
- ret = BLUETOOTH_ERROR_INTERNAL;
- goto fail;
- }
-
- conn = _bt_gdbus_get_system_gconn();
- if (conn == NULL) {
- BT_ERR("conn NULL");
- ret = BLUETOOTH_ERROR_INTERNAL;
- goto fail;
- }
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_DEVICE_INTERFACE, NULL, NULL);
-
- g_free(device_path);
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- min = interval_min / BT_LE_CONN_INTERVAL_SPLIT;
- max = interval_max / BT_LE_CONN_INTERVAL_SPLIT;
- to = time_out / BT_LE_CONN_TO_SPLIT;
-
- reply = g_dbus_proxy_call_sync(device_proxy, "LeConnUpdate",
- g_variant_new("(uuuu)", min, max, latency, to),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- g_object_unref(device_proxy);
- if (reply == NULL) {
- if (error) {
- BT_ERR("Error %s[%s]", error->message, address);
- if (g_strrstr(error->message, "In Progress"))
- ret = BLUETOOTH_ERROR_IN_PROGRESS;
- else
- ret = BLUETOOTH_ERROR_INTERNAL;
- g_error_free(error);
- return ret;
- }
- }
- g_variant_unref(reply);
-
-fail:
- return ret;
-}
-
-static void __bt_le_conn_param_free(void *data)
-{
- bt_le_conn_param_t *param = (bt_le_conn_param_t *)data;
-
- BT_DBG("%s", param->sender);
- g_free(param->sender);
- g_free(param);
-}
-
-static gint __bt_compare_le_conn_param_key(gpointer *a, gpointer *b)
-{
- bt_le_conn_param_t *parama = (bt_le_conn_param_t *)a;
- bt_le_conn_param_t *paramb = (bt_le_conn_param_t *)b;
-
- return parama->key > paramb->key;
-}
-
-static bt_connected_le_dev_t *__bt_get_le_connected_dev_info(const char *address)
-{
- GSList *l = NULL;
- bt_connected_le_dev_t *dev;
-
- if (!address)
- return NULL;
-
- for (l = le_connected_dev_list; l; l = g_slist_next(l)) {
- dev = l->data;
-
- if (g_strcmp0(dev->address, address) == 0)
- return dev;
- }
- return NULL;
-}
-
-static bt_le_conn_param_t *__bt_get_le_conn_param_info(bt_connected_le_dev_t *dev, const char *sender)
-{
- GSList *l = NULL;
- bt_le_conn_param_t *param = NULL;
-
- if (!dev || !sender)
- return NULL;
-
- for (l = dev->senders; l; l = g_slist_next(l)) {
- param = l->data;
- if (g_strcmp0(param->sender, sender) == 0)
- return param;
- }
-
- return NULL;
-}
-
-int _bt_add_le_conn_param_info(const char *address, const char *sender,
- float interval_min, float interval_max, guint16 latency, guint16 time_out)
-{
- bt_connected_le_dev_t *dev = NULL;
- bt_le_conn_param_t *param = NULL;
- bt_le_conn_param_t *data = NULL;
-
- if (!address || !sender)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- dev = __bt_get_le_connected_dev_info(address);
- if (!dev)
- return BLUETOOTH_ERROR_INTERNAL;
-
- param = __bt_get_le_conn_param_info(dev, sender);
-
- data = g_malloc0(sizeof(bt_le_conn_param_t));
- data->sender = g_strdup(sender);
- data->interval_min = interval_min;
- data->interval_max = interval_max;
- data->latency = latency;
- data->time_out = time_out;
- data->key = interval_min + (interval_max - interval_min)/2;
-
- if (param == NULL) {
- BT_DBG("Add param %s %s %f %f", address, sender, interval_min, interval_max);
- dev->senders = g_slist_append(dev->senders, data);
- } else {
- BT_DBG("Update param %s %s %f %f", address, sender, interval_min, interval_max);
- dev->senders = g_slist_remove(dev->senders, param);
- g_free(param->sender);
- g_free(param);
- dev->senders = g_slist_append(dev->senders, data);
- }
-
- /* Sorting. First element have the minimum interval */
- dev->senders = g_slist_sort(dev->senders,
- (GCompareFunc)__bt_compare_le_conn_param_key);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_remove_le_conn_param_info(const char *address, const char *sender, gboolean *is_removed)
-{
- bt_connected_le_dev_t *dev = NULL;
- bt_le_conn_param_t *param = NULL;
-
- if (!address || !sender)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- dev = __bt_get_le_connected_dev_info(address);
- if (!dev)
- return BLUETOOTH_ERROR_INTERNAL;
-
- param = __bt_get_le_conn_param_info(dev, sender);
- if (param) {
- BT_DBG("Remove param %s %s ", address, sender);
- dev->senders = g_slist_remove(dev->senders, param);
- g_free(param->sender);
- g_free(param);
- *is_removed = TRUE;
- } else
- *is_removed = FALSE;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_remove_all_le_conn_param_info(const char *sender)
-{
- GSList *l = NULL;
- bt_connected_le_dev_t *dev = NULL;
- bt_le_conn_param_t *param = NULL;
- gboolean is_removed = FALSE;
- char *sender_new = NULL;
- unsigned char addr[BLUETOOTH_ADDRESS_LENGTH];
- int ret = BLUETOOTH_ERROR_NONE;
-
- if (!sender)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- for (l = le_connected_dev_list; l; l = g_slist_next(l)) {
- dev = l->data;
- _bt_remove_le_conn_param_info(dev->address, sender, &is_removed);
-
- if (is_removed) {
- BT_INFO("Sender terminated. Update le conn interval [senders %d]",
- g_slist_length(dev->senders));
- if (g_slist_length(dev->senders) > 0) {
- param = dev->senders->data;
- BT_DBG("dev %f %f, param %f %f", dev->interval_min, dev->interval_max,
- param->interval_min, param->interval_max);
-
- if (dev->interval_min != param->interval_min ||
- dev->interval_max != param->interval_max) {
- sender_new = g_strdup(param->sender);
-
- _bt_convert_addr_string_to_type(addr, dev->address);
- ret = _bt_le_conn_update(sender_new, addr,
- param->interval_min, param->interval_max,
- param->latency, param->time_out);
- g_free(sender_new);
-
- if (ret != BLUETOOTH_ERROR_NONE)
- BT_ERR("Unable to set le connection parameter");
- }
- } else {
- BT_INFO("Set the default interval");
-
- bluetooth_le_connection_param_t param = { 0 };
- _bt_get_le_connection_parameter(
- BLUETOOTH_LE_CONNECTION_MODE_LOW_POWER,
- ¶m);
-
- ret = __bt_le_set_conn_parameter(dev->address,
- param.interval_min, param.interval_max,
- param.latency, param.timeout);
- if (ret == BLUETOOTH_ERROR_NONE) {
- dev->interval_min = param.interval_min;
- dev->interval_max = param.interval_max;
- }
- }
- }
- }
-
- return ret;
-}
-
-void _bt_add_le_connected_dev_info(const char *address)
-{
- bt_connected_le_dev_t *dev = NULL;
-
- if (!address)
- return;
-
- dev = g_malloc0(sizeof(bt_connected_le_dev_t));
- dev->address = g_strdup(address);
-
- le_connected_dev_list = g_slist_append(le_connected_dev_list, dev);
-
- return;
-}
-
-void _bt_remove_le_connected_dev_info(const char *address)
-{
- bt_connected_le_dev_t *dev = NULL;
-
- if (!address)
- return;
-
- dev = __bt_get_le_connected_dev_info(address);
- if (!dev)
- return;
-
- g_slist_free_full(dev->senders, __bt_le_conn_param_free);
- le_connected_dev_list = g_slist_remove(le_connected_dev_list, dev);
- g_free(dev->address);
- g_free(dev);
-
- return;
-}
-
-int _bt_le_conn_update(const char *sender,
- unsigned char *device_address,
- float interval_min, float interval_max,
- guint16 latency, guint16 time_out)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- guint32 min_supervision_to;
- bt_connected_le_dev_t *dev = NULL;
- bt_le_conn_param_t *param = NULL;
- gboolean is_removed = FALSE;
- int ret = BLUETOOTH_ERROR_NONE;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- BT_DBG("Sender %s, Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u",
- sender, interval_min, interval_max, latency, time_out);
-
- if (interval_min > interval_max ||
- interval_min < BT_LE_CONN_INTERVAL_MIN ||
- interval_max > BT_LE_CONN_INTERVAL_MAX) {
- ret = BLUETOOTH_ERROR_INVALID_PARAM;
- goto fail;
- }
-
- if (time_out < BT_LE_CONN_SUPER_TO_MIN ||
- time_out > BT_LE_CONN_SUPER_TO_MAX) {
- ret = BLUETOOTH_ERROR_INVALID_PARAM;
- goto fail;
- }
-
- if (latency > BT_LE_CONN_SLAVE_LATENCY_MAX) {
- ret = BLUETOOTH_ERROR_INVALID_PARAM;
- goto fail;
- }
-
- /*
- * The Supervision_Timeout in milliseconds shall be larger than
- * (1 + Conn_Latency) * Conn_Interval_Max * 2,
- * where Conn_Interval_Max is given in milliseconds.
- */
- min_supervision_to = (1 + latency) * interval_max * 2;
- if (time_out <= min_supervision_to) {
- ret = BLUETOOTH_ERROR_INVALID_PARAM;
- goto fail;
- }
-
- _bt_convert_addr_type_to_string(address, device_address);
- BT_DBG("Remote device address: %s", address);
-
- _bt_add_le_conn_param_info(address, sender, interval_min, interval_max, 0, 2000);
-
- dev = __bt_get_le_connected_dev_info(address);
- if (dev == NULL) {
- ret = BLUETOOTH_ERROR_NOT_CONNECTED;
- goto fail;
- }
-
- if (g_slist_length(dev->senders) == 1)
- goto update;
- else {
- param = dev->senders->data;
-
- BT_DBG("dev %f, param %f, input %f", dev->interval_min, param->interval_min, interval_min);
-
- if (dev->interval_min == param->interval_min && dev->interval_max == param->interval_max) {
- BT_DBG("Skip due to same interval");
- return ret;
- }
-
- interval_min = param->interval_min;
- interval_max = param->interval_max;
- }
-
-update:
- ret = __bt_le_set_conn_parameter(address, interval_min, interval_max, latency, time_out);
-
- if (ret != BLUETOOTH_ERROR_NONE) {
- _bt_remove_le_conn_param_info(address, sender, &is_removed);
- return ret;
- }
-
- dev->interval_min = interval_min;
- dev->interval_max = interval_max;
-
-fail:
- return ret;
-}
-
-int _bt_set_pin_code(bluetooth_device_address_t *device_address,
- bluetooth_device_pin_code_t *pin_code)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- GSList *l = NULL;
- bt_pin_code_info_t *pin_info = NULL;
-
- BT_CHECK_PARAMETER(device_address, return);
- BT_CHECK_PARAMETER(pin_code, return);
- retv_if(g_slist_length(pin_info_list) >= BT_DEVICE_PIN_CODE_SLOT_MAX,
- BLUETOOTH_ERROR_NO_RESOURCES);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- for (l = pin_info_list; l != NULL; l = l->next) {
- pin_info = l->data;
-
- if (g_strcmp0(pin_info->address, address) == 0) {
- g_free(pin_info->pin_code);
- pin_info->pin_code = g_strdup(pin_code->pin_code);
- return BLUETOOTH_ERROR_NONE;
- }
- }
-
- pin_info = g_malloc0(sizeof(bt_pin_code_info_t));
- pin_info->address = g_strdup(address);
- pin_info->pin_code = g_strdup(pin_code->pin_code);
- pin_info_list = g_slist_append(pin_info_list, pin_info);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-gint __bt_compare_address(gpointer *a, gpointer *b)
-{
- bt_pin_code_info_t *pin_info = (bt_pin_code_info_t *)a;
- char *address = (char *)b;
- return g_strcmp0(pin_info->address, address);
-}
-
-int _bt_unset_pin_code(bluetooth_device_address_t *device_address)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- GSList *l = NULL;
- bt_pin_code_info_t *pin_info = NULL;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- l = g_slist_find_custom(pin_info_list, address,
- (GCompareFunc)__bt_compare_address);
- if (l)
- pin_info = l->data;
- if (pin_info) {
- pin_info_list = g_slist_remove(pin_info_list, pin_info);
- g_free(pin_info->address);
- g_free(pin_info->pin_code);
- g_free(pin_info);
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_get_device_pin_code(const char *address, char *pin_code)
-{
- GSList *l = NULL;
-
- BT_CHECK_PARAMETER(address, return);
- BT_CHECK_PARAMETER(pin_code, return);
-
- for (l = pin_info_list; l != NULL; l = l->next) {
- bt_pin_code_info_t *pin_info = l->data;
-
- if (g_strcmp0(pin_info->address, address) == 0) {
- g_strlcpy(pin_code, pin_info->pin_code,
- BLUETOOTH_PIN_CODE_MAX_LENGTH + 1);
-
- return BLUETOOTH_ERROR_NONE;
- }
- }
-
- return BLUETOOTH_ERROR_NOT_FOUND;
-}
-
-int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode,
- bluetooth_le_connection_param_t *param)
-{
- if (param == NULL)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- if (mode < BLUETOOTH_LE_CONNECTION_MODE_BALANCED ||
- mode > BLUETOOTH_LE_CONNECTION_MODE_LOW_POWER)
- return BLUETOOTH_ERROR_INVALID_PARAM;
-
- memset(param, 0x00, sizeof(bluetooth_le_connection_param_t));
-
- switch (mode) {
- case BLUETOOTH_LE_CONNECTION_MODE_BALANCED:
- param->interval_min = BT_LE_CONN_PARAM_BALANCED_MIN_INTERVAL;
- param->interval_max = BT_LE_CONN_PARAM_BALANCED_MAX_INTERVAL;
- param->latency = BT_LE_CONN_PARAM_BALANCED_SLAVE_LATENCY;
- param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
- break;
-
- case BLUETOOTH_LE_CONNECTION_MODE_LOW_LATENCY:
- param->interval_min = BT_LE_CONN_PARAM_LOW_LATENCY_MIN_INTERVAL;
- param->interval_max = BT_LE_CONN_PARAM_LOW_LATENCY_MAX_INTERVAL;
- param->latency = BT_LE_CONN_PARAM_LOW_LATENCY_SLAVE_LATENCY;
- param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
- break;
-
- case BLUETOOTH_LE_CONNECTION_MODE_LOW_POWER:
- param->interval_min = BT_LE_CONN_PARAM_LOW_POWER_MIN_INTERVAL;
- param->interval_max = BT_LE_CONN_PARAM_LOW_POWER_MAX_INTERVAL;
- param->latency = BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY;
- param->timeout = BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT;
- break;
-
- default:
- BT_ERR("Unhandled mode : %d", mode);
- break;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile,
- guint trusted_profile_flag, guint *trusted)
-{
- int trust_profile;
- *trusted = FALSE;
-
- switch (profile) {
- case TRUSTED_PROFILE_PBAP:
- if (trusted_profile_flag & (PROFILE_SUPPORTED << 0))
- trust_profile = trusted_profile_flag & (1 << 1);
- else
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- break;
- case TRUSTED_PROFILE_MAP:
- if (trusted_profile_flag & (PROFILE_SUPPORTED << 2))
- trust_profile = trusted_profile_flag & (1 << 3);
- else
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- break;
- case TRUSTED_PROFILE_SAP:
- if (trusted_profile_flag & (PROFILE_SUPPORTED << 4))
- trust_profile = trusted_profile_flag & (1 << 5);
- else
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- break;
- case TRUSTED_PROFILE_ALL: /* Return Flag for All profiles*/
- *trusted = trusted_profile_flag;
- return BLUETOOTH_ERROR_NONE;
- default:
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- if (trust_profile)
- *trusted = TRUE;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_get_restricted_profile_from_flag(bluetooth_restricted_profile_t profile,
- guint restricted_profile_flag, guint *restricted)
-{
- int restrict_profile;
- *restricted = FALSE;
-
- switch (profile) {
- case RESTRICTED_PROFILE_HFP_HS:
- restrict_profile = restricted_profile_flag & (1 << 0);
- break;
- case RESTRICTED_PROFILE_A2DP:
- restrict_profile = restricted_profile_flag & (1 << 2);
- break;
- default:
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- if (restrict_profile)
- *restricted = TRUE;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile)
-{
- switch (profile) {
- case TRUSTED_PROFILE_PBAP:
- return g_strdup("00001130-0000-1000-8000-00805f9b34fb");
- case TRUSTED_PROFILE_MAP:
- return g_strdup("00001134-0000-1000-8000-00805f9b34fb");
- case TRUSTED_PROFILE_SAP:
- return g_strdup("0000112D-0000-1000-8000-00805f9b34fb");
- case TRUSTED_PROFILE_ALL:
- return NULL;
- }
-
- return NULL;
-}
-
-char *_bt_get_restricted_profile_uuid(bluetooth_restricted_profile_t profile)
-{
- switch (profile) {
- case RESTRICTED_PROFILE_HFP_HS:
- return g_strdup("0000111e-0000-1000-8000-00805f9b34fb");
- case RESTRICTED_PROFILE_A2DP:
- return g_strdup("0000110b-0000-1000-8000-00805f9b34fb");
- }
-
- return NULL;
-}
-
-bluetooth_trusted_profile_t _bt_get_trusted_profile_enum(const char *uuid)
-{
- if (g_strcmp0("0000112f-0000-1000-8000-00805f9b34fb", uuid) == 0)
- return TRUSTED_PROFILE_PBAP;
- else if (g_strcmp0("00001132-0000-1000-8000-00805f9b34fb", uuid) == 0)
- return TRUSTED_PROFILE_MAP;
- else if (g_strcmp0("0000112D-0000-1000-8000-00805f9b34fb", uuid) == 0)
- return TRUSTED_PROFILE_SAP;
-
- return 0; /* 0 - Unknown Profile */
-}
-
-int _bt_set_trust_profile(bluetooth_device_address_t *bd_addr,
- bluetooth_trusted_profile_t profile, gboolean trust)
-{
- int ret = BLUETOOTH_ERROR_NONE;
- GDBusConnection *conn;
- GDBusProxy *proxy;
- GError *error = NULL;
- char *device_path = NULL;
- char *uuid = NULL;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- GVariant *reply;
-
- BT_CHECK_PARAMETER(bd_addr, return);
- BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] trust[%d]",
- bd_addr->addr[0], bd_addr->addr[1],
- bd_addr->addr[2], bd_addr->addr[3],
- bd_addr->addr[4], bd_addr->addr[5],
- profile, trust);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, bd_addr->addr);
-
- device_path = _bt_get_device_object_path(address);
- retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME, device_path,
- BT_DEVICE_INTERFACE, NULL, NULL);
-
- g_free(device_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- uuid = _bt_get_trusted_profile_uuid(profile);
- if (uuid == NULL) {
- g_object_unref(proxy);
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- reply = g_dbus_proxy_call_sync(proxy, "SetTrustedProfile",
- g_variant_new("(sb)", uuid, trust),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
- g_object_unref(proxy);
-
- if (reply == NULL) {
- BT_ERR("Failed to Set Profile Trusted");
- ret = BLUETOOTH_ERROR_INTERNAL;
- if (error) {
- BT_ERR("Error %s[%s]", error->message, address);
- g_error_free(error);
- }
- goto finish;
- }
- g_variant_unref(reply);
-
-finish:
- g_free(uuid);
- return ret;
-}
-
-int _bt_get_trust_profile(bluetooth_device_address_t *bd_addr,
- bluetooth_trusted_profile_t profile, guint *trust)
-{
- int ret = BLUETOOTH_ERROR_NONE;
- GDBusConnection *conn;
- GDBusProxy *proxy;
- GError *error = NULL;
- char *device_path = NULL;
- guint trusted_profile_flag;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- GVariant *reply;
-
- BT_CHECK_PARAMETER(bd_addr, return);
- BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] trust[%d]",
- bd_addr->addr[0], bd_addr->addr[1],
- bd_addr->addr[2], bd_addr->addr[3],
- bd_addr->addr[4], bd_addr->addr[5],
- profile, *trust);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, bd_addr->addr);
-
- device_path = _bt_get_device_object_path(address);
- retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME, device_path,
- BT_PROPERTIES_INTERFACE, NULL, NULL);
-
- g_free(device_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- reply = g_dbus_proxy_call_sync(proxy, "Get",
- g_variant_new("(ss)", BT_DEVICE_INTERFACE, "TrustedProfiles"),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
- g_object_unref(proxy);
-
- if (reply == NULL) {
- BT_ERR("Failed to Get Profile Trusted");
- ret = BLUETOOTH_ERROR_INTERNAL;
- if (error) {
- BT_ERR("Error %s[%s]", error->message, address);
- g_error_free(error);
- }
- *trust = 0;
- } else {
- GVariant *temp;
- g_variant_get(reply, "(v)", &temp);
- trusted_profile_flag = g_variant_get_uint32(temp);
- BT_DBG("TRUST_FLAG %d", trusted_profile_flag);
-
- ret = _bt_get_trusted_profile_from_flag(profile,
- trusted_profile_flag, trust);
- g_variant_unref(temp);
- g_variant_unref(reply);
- }
-
- BT_DBG("TRUST %d", *trust);
- return ret;
-}
-
-int _bt_set_restrict_profile(bluetooth_device_address_t *bd_addr,
- bluetooth_restricted_profile_t profile, gboolean restricted)
-{
- int ret = BLUETOOTH_ERROR_NONE;
- GDBusConnection *conn;
- GDBusProxy *proxy;
- GError *error = NULL;
- char *device_path = NULL;
- char *uuid = NULL;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- GVariant *reply;
-
- BT_CHECK_PARAMETER(bd_addr, return);
- BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] restricted[%d]",
- bd_addr->addr[0], bd_addr->addr[1],
- bd_addr->addr[2], bd_addr->addr[3],
- bd_addr->addr[4], bd_addr->addr[5],
- profile, restricted);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, bd_addr->addr);
-
- device_path = _bt_get_device_object_path(address);
- retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME, device_path,
- BT_DEVICE_INTERFACE, NULL, NULL);
-
- g_free(device_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- uuid = _bt_get_restricted_profile_uuid(profile);
- if (uuid == NULL) {
- g_object_unref(proxy);
- return BLUETOOTH_ERROR_NOT_SUPPORT;
- }
-
- reply = g_dbus_proxy_call_sync(proxy, "SetRestrictedProfile",
- g_variant_new("(sb)", uuid, restricted),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
- g_object_unref(proxy);
-
- if (reply == NULL) {
- BT_ERR("Failed to Set Profile Restricted");
- ret = BLUETOOTH_ERROR_INTERNAL;
- if (error) {
- BT_ERR("Error %s[%s]", error->message, address);
- g_error_free(error);
- }
- goto finish;
- }
- g_variant_unref(reply);
-
-finish:
- g_free(uuid);
- return ret;
-}
-
-int _bt_get_restrict_profile(bluetooth_device_address_t *bd_addr,
- bluetooth_restricted_profile_t profile, guint *restricted)
-{
- int ret = BLUETOOTH_ERROR_NONE;
- GDBusConnection *conn;
- GDBusProxy *proxy;
- GError *error = NULL;
- char *device_path = NULL;
- guint restricted_profile_flag;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- GVariant *reply;
-
- BT_CHECK_PARAMETER(bd_addr, return);
- BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] restricted[%d]",
- bd_addr->addr[0], bd_addr->addr[1],
- bd_addr->addr[2], bd_addr->addr[3],
- bd_addr->addr[4], bd_addr->addr[5],
- profile, *restricted);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, bd_addr->addr);
-
- device_path = _bt_get_device_object_path(address);
- retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME, device_path,
- BT_PROPERTIES_INTERFACE, NULL, NULL);
-
- g_free(device_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- reply = g_dbus_proxy_call_sync(proxy, "Get",
- g_variant_new("(ss)", BT_DEVICE_INTERFACE, "RestrictedProfiles"),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
- g_object_unref(proxy);
-
- if (reply == NULL) {
- BT_ERR("Failed to Get Profile Restricted");
- ret = BLUETOOTH_ERROR_INTERNAL;
- if (error) {
- BT_ERR("Error %s[%s]", error->message, address);
- g_error_free(error);
- }
- *restricted = 0;
- } else {
- GVariant *temp;
- g_variant_get(reply, "(v)", &temp);
- restricted_profile_flag = g_variant_get_uint32(temp);
- BT_DBG("Restricted_FLAG %d", restricted_profile_flag);
-
- ret = _bt_get_restricted_profile_from_flag(profile,
- restricted_profile_flag, restricted);
- g_variant_unref(temp);
- g_variant_unref(reply);
- }
-
- BT_DBG("TRUST %d", *restricted);
- return ret;
-}
-
-static void __bt_request_att_mtu_device_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data)
-{
- GError *err = NULL;
- GVariant *out_param1;
- request_info_t *req_info;
- GVariant *val = NULL;
- GVariant *param = NULL;
- guint8 status = 0;
- guint16 mtu = 0;
- bluetooth_device_address_t device_addr = { {0} };
- int result = BLUETOOTH_ERROR_NONE;
-
- BT_DBG("+");
- val = g_dbus_proxy_call_finish(proxy, res, &err);
-
- req_info = _bt_get_request_info(att_mtu_req_info->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- g_object_unref(proxy);
- att_mtu_req_info->device_proxy = NULL;
- goto done;
- }
-
- if (err != NULL) {
- BT_ERR("Error occured in RequestAttMtu [%s]", err->message);
-
- if (g_strrstr(err->message, "NotSupported")) {
- BT_INFO("Connection Not Supported");
- result = BLUETOOTH_ERROR_NOT_SUPPORT;
- } else if (g_strrstr(err->message, "NotConnected")) {
- BT_INFO("Not connected");
- result = BLUETOOTH_ERROR_NOT_CONNECTED;
- } else if (g_strrstr(err->message, "InvalidArguments")) {
- BT_INFO("Not connected");
- result = BLUETOOTH_ERROR_INVALID_PARAM;
- } else {
- BT_DBG("Default case");
- result = BLUETOOTH_ERROR_INTERNAL;
- }
- }
-
- g_object_unref(proxy);
- att_mtu_req_info->device_proxy = NULL;
-
- if (result != BLUETOOTH_ERROR_NONE)
- goto dbus_return;
-
- if (val) {
- g_variant_get(val, "(qy)", &mtu, &status);
- g_variant_unref(val);
- }
-
- BT_DBG("MTU %d, Status %d, %s", mtu, status, att_mtu_req_info->addr);
-
- param = g_variant_new("(isqy)",
- result,
- att_mtu_req_info->addr,
- mtu,
- status);
-
- /* Send the event to application */
- _bt_send_event(BT_DEVICE_EVENT,
- BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
- param);
-
-dbus_return:
- if (req_info->context == NULL)
- goto done;
-
- _bt_convert_addr_string_to_type(device_addr.addr,
- (const char *)att_mtu_req_info->addr);
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("(iv)", result, out_param1));
-
- _bt_delete_request_list(req_info->req_id);
-done:
- if (err)
- g_error_free(err);
-
- g_free(att_mtu_req_info->addr);
- g_free(att_mtu_req_info);
- att_mtu_req_info = NULL;
-
- BT_DBG("-");
-}
-
-int _bt_request_att_mtu(int request_id, bluetooth_device_address_t *device_address,
- unsigned int mtu)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- gchar *device_path = NULL;
- GDBusProxy *adapter_proxy;
- GDBusProxy *device_proxy;
- GDBusConnection *conn;
- int ret = BLUETOOTH_ERROR_NONE;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- if (att_mtu_req_info) {
- BT_ERR("ATT MTU request in progress");
- return BLUETOOTH_ERROR_DEVICE_BUSY;
- }
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- BT_DBG("Remote device address: %s", address);
-
- device_path = _bt_get_device_object_path(address);
-
- retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_DEVICE_INTERFACE, NULL, NULL);
- g_free(device_path);
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- att_mtu_req_info = g_malloc0(sizeof(bt_funcion_data_t));
- att_mtu_req_info->addr = (char *)g_strdup(address);
- att_mtu_req_info->req_id = request_id;
- att_mtu_req_info->device_proxy = device_proxy;
-
- g_dbus_proxy_call(device_proxy, "RequestAttMtu",
- g_variant_new("(q)", mtu),
- G_DBUS_CALL_FLAGS_NONE,
- BT_MAX_DBUS_TIMEOUT,
- NULL,
- (GAsyncReadyCallback)__bt_request_att_mtu_device_cb,
- NULL);
-
- return ret;
-}
-
-int _bt_get_att_mtu(bluetooth_device_address_t *device_address,
- unsigned int *mtu)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char *object_path = NULL;
-
- GDBusProxy *device_proxy;
- GError *error = NULL;
- GVariant *value;
- GDBusConnection *conn;
- GVariant *result = NULL;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- object_path = _bt_get_device_object_path(address);
- retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME, object_path,
- BT_PROPERTIES_INTERFACE, NULL, NULL);
- g_free(object_path);
- retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(device_proxy, "Get",
- g_variant_new("(ss)", BT_DEVICE_INTERFACE, "AttMtu"),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
- if (error) {
- ERR("DBus Error : %s", error->message);
- g_clear_error(&error);
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_INTERNAL;
- } else {
- g_variant_get(result, "(v)", &value);
- *mtu = g_variant_get_uint16(value);
- BT_DBG("ATT MTU : %d", *mtu);
- g_variant_unref(value);
- g_variant_unref(result);
-
- if (*mtu == 0) {
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_NOT_CONNECTED;
- }
- }
-
- g_object_unref(device_proxy);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_get_device_ida(bluetooth_device_address_t *device_address,
- bluetooth_device_address_t *id_address)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- gchar *device_path = NULL;
- const gchar *idaddress = NULL;
- GDBusProxy *device_proxy;
- GError *error = NULL;
- GVariant *result = NULL;
- GDBusConnection *conn;
- int ret = BLUETOOTH_ERROR_NONE;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- device_path = _bt_get_device_object_path(address);
- retv_if(device_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_DEVICE_INTERFACE, NULL, NULL);
- g_free(device_path);
- if (!device_proxy) {
- BT_ERR("Unable to get proxy");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- result = g_dbus_proxy_call_sync(device_proxy, "GetIDAddress", NULL,
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
- if (result == NULL) {
- BT_ERR("Failed to get device ID address");
-
- ret = BLUETOOTH_ERROR_INTERNAL;
- if (error != NULL) {
- g_dbus_error_strip_remote_error(error);
- BT_ERR("Error occured in Proxy call [%s]", error->message);
- if (g_strcmp0(error->message, "Does Not Exist") == 0)
- ret = BLUETOOTH_ERROR_NOT_PAIRED;
- g_error_free(error);
- }
- g_object_unref(device_proxy);
- return ret;
- }
-
- g_variant_get(result , "(&s)", &idaddress);
-
- DBG_SECURE("ID Address : %s", idaddress);
- _bt_convert_addr_string_to_type(id_address->addr, idaddress);
-
- g_variant_unref(result);
- g_object_unref(device_proxy);
-
- return ret;
-}
-
-int _bt_passkey_reply(const char *passkey, gboolean authentication_reply)
-{
- GapAgentPrivate *agent = _bt_get_adapter_agent();
- retv_if(!agent, BLUETOOTH_ERROR_INTERNAL);
-
- if (authentication_reply)
- gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, passkey, NULL);
- else
- gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, passkey, NULL);
-
- BT_DBG("BT_PASSKEY_REPLY");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_passkey_confirmation_reply(gboolean confirmation_reply)
-{
- GapAgentPrivate *agent = _bt_get_adapter_agent();
- retv_if(!agent, BLUETOOTH_ERROR_INTERNAL);
-
- if (confirmation_reply)
- gap_agent_reply_confirmation(agent, GAP_AGENT_ACCEPT, NULL);
- else
- gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL);
-
- BT_DBG("BT_PASSKEY_CONFIRMATION_REPLY");
- return BLUETOOTH_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifdef TIZEN_DPM_ENABLE
-
-#include <glib.h>
-#include <gio/gio.h>
-#include <dlog.h>
-#include <string.h>
-#include <syspopup_caller.h>
-#include <bundle_internal.h>
-#include <vconf.h>
-
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-
-#include "bt-service-common.h"
-#include "bt-service-adapter.h"
-#include "bt-service-dpm.h"
-
-static dpm_policy_t policy_table[DPM_POLICY_END] = {
- [DPM_POLICY_ALLOW_BLUETOOTH] = { {DPM_BT_ERROR} },
- [DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION] = { {DPM_STATUS_ERROR} },
- [DPM_POLICY_BLUETOOTH_UUID_RESTRICTION] = { {DPM_STATUS_ERROR} },
- [DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST] = { {NULL} },
- [DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST] = { {NULL} },
- [DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST] = { {NULL} },
- [DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST] = { {NULL} },
- [DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL] = { {DPM_STATUS_ERROR} },
- [DPM_POLICY_BLUETOOTH_PAIRING_STATE] = { {DPM_STATUS_ERROR} },
- [DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE] = { {DPM_STATUS_ERROR} },
- [DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE] = { {DPM_STATUS_ERROR} },
- [DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE] = { {DPM_STATUS_ERROR} },
- [DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE] = { {DPM_STATUS_ERROR} },
-};
-
-
-/**
- * @brief DPM profile state
- * @see
- */
-static dpm_profile_state_t dpm_profile_state[DPM_PROFILE_NONE] = {
- [DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE] = {DPM_STATUS_ERROR},
- [DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE] = {DPM_STATUS_ERROR},
- [DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE] = {DPM_STATUS_ERROR},
- [DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE] = {DPM_STATUS_ERROR},
- [DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE] = {DPM_STATUS_ERROR},
- [DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE] = {DPM_STATUS_ERROR},
- [DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE] = {DPM_STATUS_ERROR},
- [DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE] = {DPM_STATUS_ERROR},
- [DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE] = {DPM_STATUS_ERROR},
- [DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE] = {DPM_STATUS_ERROR},
-};
-
-int _bt_launch_dpm_popup(char *mode)
-{
- int ret = 0;
- bundle *b;
-
- b = bundle_create();
- retv_if(b == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- bundle_add(b, "mode", mode);
-
- ret = syspopup_launch(BT_DPM_SYSPOPUP, b);
-
- if (ret < 0)
- BT_ERR("Popup launch failed: %d\n", ret);
-
- bundle_free(b);
-
- return ret;
-}
-
-dpm_result_t _bt_dpm_set_allow_bluetooth_mode(dpm_bt_allow_t value)
-{
- BT_INFO("_bt_dpm_set_allow_bluetooth_mode");
-
-#if 0
- if (value == DPM_BT_ALLOWED && value == DPM_BT_HANDSFREE_ONLY) {
- /* Update Bluetooth DPM Status to notify other modules */
- if (vconf_set_int(VCONFKEY_BT_DPM_STATUS, value) != 0)
- BT_ERR("Set vconf failed\n");
- return DPM_RESULT_FAIL;
- } else {
- /* Update Bluetooth DPM Status to notify other modules */
- if (vconf_set_int(VCONFKEY_BT_DPM_STATUS, VCONFKEY_BT_DPM_STATUS_RESTRICTED) != 0)
- BT_ERR("Set vconf failed\n");
- return DPM_RESULT_FAIL;
- }
-#endif
- policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value = value;
-
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_bt_allow_t _bt_dpm_get_allow_bluetooth_mode(void)
-{
- BT_INFO("_bt_dpm_get_allow_bluetooth_mode");
-
- return policy_table[DPM_POLICY_ALLOW_BLUETOOTH].value;
-}
-
-dpm_result_t _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value)
-{
- BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value = value;
-
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void)
-{
- BT_INFO("_bt_dpm_is_bluetooth_device_restriction_active");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- return policy_table[DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION].value;
-}
-
-dpm_result_t _bt_dpm_activate_bluetoooth_uuid_restriction(dpm_status_t value)
-{
- BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value = value;
-
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void)
-{
- BT_INFO("_bt_dpm_is_bluetooth_uuid_restriction_active");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- return policy_table[DPM_POLICY_BLUETOOTH_UUID_RESTRICTION].value;
-}
-
-dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(bluetooth_device_address_t *bd_addr)
-{
- char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char *dev_addr = NULL;
-
- BT_INFO("_bt_dpm_add_bluetooth_devices_to_blacklist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- BT_CHECK_PARAMETER(bd_addr, return);
-
- _bt_convert_addr_type_to_string(device_address,
- (unsigned char *)bd_addr->addr);
-
- dev_addr = g_strdup(device_address);
- if (!dev_addr)
- return DPM_RESULT_FAIL;
- policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, dev_addr);
-
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_result_t _bt_dpm_get_bluetooth_devices_from_blacklist(GArray **out_param1)
-{
- dpm_result_t ret = DPM_RESULT_FAIL;
- bt_dpm_device_list_t device_list;
- GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list;
- int i = 0;
-
- BT_INFO("_bt_dpm_get_bluetooth_devices_from_blacklist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return ret;
-
- if (list) {
- ret = DPM_RESULT_SUCCESS;
- for (; list; list = list->next, i++) {
- memset(device_list.addresses[i].addr, 0, BLUETOOTH_ADDRESS_LENGTH);
- _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
- }
- device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
- g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
- } else {
- ret = DPM_RESULT_SUCCESS;
- device_list.count = 0;
- g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
- }
- return ret;
-}
-
-dpm_result_t _bt_dpm_add_bluetooth_devices_to_whitelist(bluetooth_device_address_t *bd_addr)
-{
- char device_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char *dev_addr = NULL;
-
- BT_INFO("_bt_dpm_add_bluetooth_devices_to_whitelist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- BT_CHECK_PARAMETER(bd_addr, return);
-
- _bt_convert_addr_type_to_string(device_address,
- (unsigned char *)bd_addr->addr);
-
- dev_addr = g_strdup(device_address);
- if (!dev_addr)
- return DPM_RESULT_FAIL;
- policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, dev_addr);
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_result_t _bt_dpm_get_bluetooth_devices_from_whitelist(GArray **out_param1)
-{
- dpm_result_t ret = DPM_RESULT_FAIL;
- bt_dpm_device_list_t device_list;
- GSList *list = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list;
- int i = 0;
-
- BT_INFO("_bt_dpm_get_bluetooth_devices_from_whitelist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return ret;
-
- if (list) {
- ret = DPM_RESULT_SUCCESS;
- for (; list; list = list->next, i++) {
- memset(device_list.addresses[i].addr, 0, BLUETOOTH_ADDRESS_LENGTH);
- _bt_convert_addr_string_to_type(device_list.addresses[i].addr, list->data);
-
- }
- device_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
- g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
- } else {
- ret = DPM_RESULT_SUCCESS;
- device_list.count = 0;
- g_array_append_vals(*out_param1, &device_list, sizeof(bt_dpm_device_list_t));
- }
- return ret;
-}
-
-dpm_result_t _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid)
-{
- char *l_uuid;
- BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- l_uuid = g_strdup(uuid);
- if (!l_uuid)
- return DPM_RESULT_FAIL;
- policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_result_t _bt_dpm_get_bluetooth_uuids_from_blacklist(GArray **out_param1)
-{
- dpm_result_t ret = DPM_RESULT_FAIL;
- bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
- GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list;
- int i = 0;
-
- BT_INFO("_bt_dpm_get_bluetooth_uuids_from_blacklist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return ret;
-
- if (list) {
- ret = DPM_RESULT_SUCCESS;
- uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
- for (; list; list = list->next, i++) {
- memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
- g_strlcpy(uuids_list.uuids[i], list->data,
- BLUETOOTH_UUID_STRING_MAX);
- }
- g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
- } else {
- ret = DPM_RESULT_SUCCESS;
- uuids_list.count = 0;
- g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
- }
-
- return ret;
-}
-
-dpm_result_t _bt_dpm_add_bluetooth_uuids_to_whitelist(const char *uuid)
-{
- char *l_uuid;
- BT_INFO("_bt_dpm_add_bluetooth_uuids_to_whitelist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- l_uuid = g_strdup(uuid);
- if (!l_uuid)
- return DPM_RESULT_FAIL;
- policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
- return DPM_RESULT_SUCCESS;
-}
-
-
-dpm_result_t _bt_dpm_get_bluetooth_uuids_from_whitelist(GArray **out_param1)
-{
- dpm_result_t ret = DPM_RESULT_FAIL;
- bt_dpm_uuids_list_t uuids_list = {0, { {0}, } };
- GSList *list = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list;
- int i = 0;
-
- BT_INFO("_bt_dpm_get_bluetooth_uuids_from_whitelist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return ret;
-
- if (list) {
- ret = DPM_RESULT_SUCCESS;
- uuids_list.count = g_slist_length(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
- for (; list; list = list->next, i++) {
- memset(uuids_list.uuids[i], 0, BLUETOOTH_UUID_STRING_MAX);
- g_strlcpy(uuids_list.uuids[i], list->data,
- BLUETOOTH_UUID_STRING_MAX);
- }
- g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
- } else {
- ret = DPM_RESULT_SUCCESS;
- uuids_list.count = 0;
- g_array_append_vals(*out_param1, &uuids_list, sizeof(bt_dpm_uuids_list_t));
- }
-
- return ret;
-
-}
-
-dpm_result_t _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value)
-{
- BT_INFO("_bt_dpm_activate_bluetooth_device_restriction");
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value = value;
-
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_status_t _bt_dpm_get_allow_bluetooth_outgoing_call(void)
-{
- BT_INFO("_bt_dpm_get_allow_bluetooth_outgoing_call");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- return policy_table[DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL].value;
-}
-
-dpm_result_t _bt_dpm_clear_bluetooth_devices_from_blacklist(void)
-{
- GSList *l = NULL;
- BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
- char *address = l->data;
- if (address) {
- policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list, address);
- g_free(address);
- }
- }
- g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list);
- policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = NULL;
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_result_t _bt_dpm_clear_bluetooth_devices_from_whitelist(void)
-{
- GSList *l = NULL;
- BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
- char *address = l->data;
- if (address) {
- policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, address);
- g_free(address);
- }
- }
- g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list);
- policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = NULL;
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_blacklist(void)
-{
- GSList *l = NULL;
- BT_INFO("_bt_dpm_clear_bluetooth_devices_from_blacklist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
- char *l_uuid = l->data;
- if (l_uuid)
- policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
- g_free(l_uuid);
- }
- g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list);
- policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = NULL;
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_whitelist(void)
-{
- GSList *l = NULL;
- BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_whitelist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
- char *l_uuid = l->data;
- if (l_uuid) {
- policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
- g_free(l_uuid);
- }
- }
- g_slist_free(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list);
- policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = NULL;
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_status_t _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value)
-{
- BT_INFO("_bt_dpm_set_bluetooth_pairing_state");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value = value;
-
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_status_t _bt_dpm_get_bluetooth_pairing_state(void)
-{
- BT_INFO("_bt_dpm_get_bluetooth_pairing_state");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- return policy_table[DPM_POLICY_BLUETOOTH_PAIRING_STATE].value;
-}
-
-dpm_status_t _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value)
-{
- BT_INFO("_bt_dpm_set_bluetooth_profile_state");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- dpm_profile_state[profile].value = value;
-
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_status_t _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile)
-{
- BT_INFO("_bt_dpm_get_bluetooth_profile_state");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- return dpm_profile_state[profile].value;
-}
-
-dpm_status_t _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value)
-{
- BT_INFO("_bt_dpm_set_bluetooth_desktop_connectivity_state");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value = value;
-
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_status_t _bt_dpm_get_bluetooth_desktop_connectivity_state(void)
-{
- BT_INFO("_bt_dpm_get_bluetooth_desktop_connectivity_state");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- return policy_table[DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE].value;
-}
-
-dpm_status_t _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value)
-{
- BT_INFO("_bt_dpm_set_bluetooth_discoverable_state");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- if (value == DPM_RESTRICTED) {
- /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
- _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
- }
-
- policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value = value;
-
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_status_t _bt_dpm_get_bluetooth_discoverable_state(void)
-{
- BT_INFO("_bt_dpm_get_bluetooth_discoverable_state");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- return policy_table[DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE].value;
-}
-
-dpm_status_t _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value)
-{
- BT_INFO("_bt_dpm_set_bluetooth_limited_discoverable_state");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- if (value == DPM_RESTRICTED) {
- /* Since Discoverable mode is restricted, stop the ongoing discoverable mode */
- _bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE, 0);
- }
-
- policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value = value;
-
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_status_t _bt_dpm_get_bluetooth_limited_discoverable_state(void)
-{
- BT_INFO("_bt_dpm_get_bluetooth_limited_discoverable_state");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- return policy_table[DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE].value;
-}
-
-dpm_status_t _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value)
-{
- BT_INFO("_bt_dpm_set_bluetooth_data_transfer_state");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value = value;
-}
-
-dpm_status_t _bt_dpm_get_allow_bluetooth_data_transfer_state(void)
-{
- BT_INFO("_bt_dpm_get_allow_bluetooth_data_transfer_state");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESTRICTED;
-
- return policy_table[DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE].value;
-}
-
-dpm_result_t _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *device_address)
-{
- GSList *l = NULL;
- char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
- BT_INFO("_bt_dpm_remove_bluetooth_devices_from_whitelist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- _bt_convert_addr_type_to_string(bd_addr,
- (unsigned char *)device_address->addr);
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list; l; l = g_slist_next(l)) {
- char *l_device = l->data;
- if (l_device && g_strcmp0(l_device, bd_addr)) {
- policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
- g_free(l_device);
- }
- }
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_result_t _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *device_address)
-{
- GSList *l = NULL;
- char bd_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
-
- BT_INFO("_bt_dpm_remove_bluetooth_devices_from_blacklist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- _bt_convert_addr_type_to_string(bd_addr,
- (unsigned char *)device_address->addr);
-
- for (l = policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list; l; l = g_slist_next(l)) {
- char *l_device = l->data;
- if (l_device && g_strcmp0(l_device, bd_addr)) {
- policy_table[DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST].list, l_device);
- g_free(l_device);
- }
- }
-
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids)
-{
- GSList *l = NULL;
- BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_whitelist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
- for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list; l; l = g_slist_next(l)) {
- char *l_uuid = l->data;
- if (l_uuid && g_strcmp0(l_uuid, uuids)) {
- policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST].list, l_uuid);
- g_free(l_uuid);
- }
- }
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids)
-{
- GSList *l = NULL;
- BT_INFO("_bt_dpm_remove_bluetooth_uuids_from_blacklist");
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- for (l = policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list; l; l = g_slist_next(l)) {
- char *l_uuid = l->data;
- if (l_uuid && g_strcmp0(l_uuid, uuids)) {
- policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_remove(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
- g_free(l_uuid);
- }
- }
- return DPM_RESULT_SUCCESS;
-}
-
-dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_list(void)
-{
- BT_INFO("_bt_dpm_clear_bluetooth_uuids_from_list");
- dpm_result_t err = DPM_RESULT_FAIL;
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
- if (!err)
- err = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
-
- return err;
-}
-
-dpm_result_t _bt_dpm_clear_bluetooth_devices_from_list(void)
-{
- BT_INFO("_bt_dpm_clear_bluetooth_devices_from_list");
- dpm_result_t err = DPM_RESULT_FAIL;
-
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_RESTRICTED)
- return DPM_RESULT_ACCESS_DENIED;
-
- err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
- if (!err)
- err = _bt_dpm_clear_bluetooth_devices_from_blacklist();
-
- return err;
-}
-#endif /* #ifdef TIZEN_DPM_ENABLE */
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <string.h>
-#include <dlog.h>
-#include <vconf.h>
-#include <vconf-internal-bt-keys.h>
-
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-#include "bt-service-main.h"
-#include "bt-service-adapter.h"
-#include "bt-service-adapter-le.h"
-#include "bt-service-device.h"
-#include "bt-service-avrcp.h"
-#include "bt-service-obex-server.h"
-#include "bt-service-rfcomm-server.h"
-#include "bt-service-audio.h"
-#include "bt-service-agent.h"
-#include "bt-service-pbap.h"
-#include "bt-service-headset-connection.h"
-#include "bt-service-avrcp-controller.h"
-#include "bt-service-hid.h"
-#include "bt-service-proximity.h"
-
-#include "bt-service-opp-client.h"
-
-#ifdef TIZEN_DPM_ENABLE
-#include "bt-service-dpm.h"
-#endif
-
-#define DBUS_TIMEOUT 20 * 1000 /* 20 Sec */
-static GDBusConnection *manager_conn;
-static GDBusConnection *obexd_conn;
-static GDBusConnection *opc_obexd_conn;
-
-static GList *p_cache_list = NULL;
-
-static guint event_id;
-static guint session_reinit_timer;
-guint nap_connected_device_count = 0;
-static guint hid_connected_device_count = 0;
-static GList *p_adv_ind_list = NULL;
-
-typedef struct {
- bt_remote_dev_info_t *dev_info;
-} bt_cache_info_t;
-
-/**
- * obexd connection type
- */
-typedef enum {
- OBEX_OPP = (1 << 1),
- OBEX_FTP = (1 << 2),
- OBEX_BIP = (1 << 3),
- OBEX_PBAP = (1 << 4),
- OBEX_IRMC = (1 << 5),
- OBEX_PCSUITE = (1 << 6),
- OBEX_SYNCEVOLUTION = (1 << 7),
- OBEX_MAS = (1 << 8),
-} bluetooth_obex_connection_type_t;
-
-void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
-void _bt_opc_property_changed_event(GVariant *msg, char *path);
-int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
-void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
-void _bt_opp_client_event_deinit(void);
-void _bt_handle_network_client_event(GVariant *msg_iter,
- const char *path);
-void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
- const char *path);
-
-static void __bt_free_bt_le_adv_info_t(gpointer data)
-{
- bt_le_adv_info_t *adv_info = data;
-
- if (adv_info->timer_id)
- g_source_remove(adv_info->timer_id);
- adv_info->timer_id = 0;
-
- g_free(adv_info->addr);
- g_free(adv_info->data);
- g_free(adv_info);
-}
-
-static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
-{
- retv_if(!addr, NULL);
- bt_le_adv_info_t *adv_info = NULL;
- GList *current = g_list_first((GList *)p_adv_ind_list);
- while (current && current->data) {
- adv_info = (bt_le_adv_info_t *)current->data;
- if (adv_info && !g_strcmp0(adv_info->addr, addr))
- return adv_info;
- current = g_list_next(current);
- }
- return NULL;
-}
-
-static int __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
-{
- retv_if(!adv_info, -1);
- if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
- __bt_free_bt_le_adv_info_t(adv_info);
- return -1;
- }
- p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
-
- return 0;
-}
-
-static void __bt_del_adv_ind_info(char *addr)
-{
- ret_if(!addr);
- ret_if(!p_adv_ind_list);
- bt_le_adv_info_t *adv_info = NULL;
- GList *current = g_list_first((GList *)p_adv_ind_list);
- while (current && current->data) {
- adv_info = (bt_le_adv_info_t *)current->data;
- if (adv_info && !g_strcmp0(adv_info->addr, addr)) {
- p_adv_ind_list = g_list_remove(p_adv_ind_list, adv_info);
- __bt_free_bt_le_adv_info_t(adv_info);
- return;
- }
- current = g_list_next(current);
- }
-}
-
-static gboolean __bt_adv_scan_req_timeout_cb(gpointer user_data)
-{
- bt_remote_le_dev_info_t le_dev_info;
- bt_le_adv_info_t *adv_info = (bt_le_adv_info_t*)user_data;
-
- memset(&le_dev_info, 0x00, sizeof(bt_remote_le_dev_info_t));
-
- le_dev_info.address = adv_info->addr;
- le_dev_info.addr_type = adv_info->addr_type;
- le_dev_info.rssi = adv_info->rssi;
- le_dev_info.adv_data = adv_info->data;
- le_dev_info.adv_data_len = adv_info->data_len;
- adv_info->timer_id = 0;
-
- _bt_send_scan_result_event(&le_dev_info, NULL);
- __bt_del_adv_ind_info(adv_info->addr);
-
- return FALSE;
-}
-
-static void __bt_free_cache_info(bt_cache_info_t *cache_info)
-{
- ret_if(cache_info == NULL);
- _bt_free_device_info(cache_info->dev_info);
- g_free(cache_info);
-}
-
-static gboolean __bt_parse_device_properties(GVariant *item,
- bt_remote_dev_info_t *dev_info)
-{
- GVariantIter iter;
- gchar *key;
- GVariant *val;
- gsize len = 0;
- if (item == NULL)
- return FALSE;
-
- g_variant_iter_init(&iter, item);
- while (g_variant_iter_loop(&iter, "{sv}", &key, &val)) {
- if (strcasecmp(key, "Address") == 0) {
- dev_info->address = g_variant_dup_string(val, &len);
- } else if (strcasecmp(key, "Class") == 0) {
- dev_info->class = g_variant_get_uint32(val);
- } else if (strcasecmp(key, "name") == 0) {
- if (dev_info->name == NULL)
- dev_info->name = g_variant_dup_string(val, &len);
- } else if (strcasecmp(key, "Connected") == 0) {
- dev_info->connected = g_variant_get_byte(val);
- } else if (strcasecmp(key, "paired") == 0) {
- dev_info->paired = g_variant_get_boolean(val);
- } else if (strcasecmp(key, "Trusted") == 0) {
- dev_info->trust = g_variant_get_boolean(val);
- } else if (strcasecmp(key, "RSSI") == 0) {
- dev_info->rssi = g_variant_get_int16(val);
- } else if (strcasecmp(key, "LastAddrType") == 0) {
- dev_info->addr_type = g_variant_get_byte(val);
- } else if (strcasecmp(key, "UUIDs") == 0) {
- char **uuid_value;
- gsize size = 0;
- int i = 0;
- size = g_variant_get_size(val);
-
- if (size > 0) {
- uuid_value = (char **)g_variant_get_strv(val, &size);
- if (dev_info->uuids == NULL)
- dev_info->uuids = g_malloc0(sizeof(char *) * size);
-
- for (i = 0; uuid_value[i] != NULL; i++) {
- dev_info->uuid_count++;
- dev_info->uuids[i] = g_strdup(uuid_value[i]);
- }
- g_free(uuid_value);
- }
- } else if (strcasecmp(key, "LegacyManufacturerDataLen") == 0) {
- g_variant_get(val, "q", &dev_info->manufacturer_data_len);
- if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
- BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
- dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
- }
-
- if (dev_info->manufacturer_data_len == 0)
- dev_info->manufacturer_data = g_strdup("");
- } else if (strcasecmp(key, "LegacyManufacturerData") == 0) {
- int i = 0;
- int len = 0;
- GVariantIter *value_iter;
- guint8 m_value;
-
- len = g_variant_get_size(val);
- if (len <= 0)
- continue;
-
- dev_info->manufacturer_data = g_malloc0(len);
-
- g_variant_get(val, "ay", &value_iter);
- while (g_variant_iter_loop(value_iter, "y", &m_value))
- dev_info->manufacturer_data[i++] = m_value;
- g_variant_iter_free(value_iter);
- }
- }
-
- BT_DBG("-");
- return TRUE;
-}
-
-static gboolean __bt_parse_interface(GVariant *msg,
- bt_remote_dev_info_t *dev_info)
-{
- char *path = NULL;
- GVariant *optional_param = NULL;
- GVariantIter iter;
- GVariant *child;
- char *interface_name = NULL;
- GVariant *inner_iter = NULL;
- g_variant_get(msg, "(&o@a{sa{sv}})",
- &path, &optional_param);
- g_variant_iter_init(&iter, optional_param);
-
- retv_if(optional_param == NULL, FALSE);
-
- while ((child = g_variant_iter_next_value(&iter))) {
- g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
- if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
- BT_DBG("Found a device: %s", path);
- if (__bt_parse_device_properties(inner_iter,
- dev_info) == FALSE) {
- g_variant_unref(inner_iter);
- g_variant_unref(child);
- g_variant_unref(optional_param);
- BT_ERR("Fail to parse the properies");
- return FALSE;
- } else {
- g_variant_unref(inner_iter);
- g_variant_unref(child);
- g_variant_unref(optional_param);
- return TRUE;
- }
- }
- g_variant_unref(inner_iter);
- g_variant_unref(child);
- }
-
- g_variant_unref(optional_param);
-
- return FALSE;
-}
-
-static int __bt_get_owner_info(GVariant *msg, char **name,
- char **previous, char **current)
-{
- g_variant_get(msg, "(&s&s&s)", name, previous, current);
- return BLUETOOTH_ERROR_NONE;
-}
-
-static int __bt_get_agent_signal_info(GVariant *msg, char **address,
- char **name, char **uuid)
-{
- g_variant_get(msg, "(sss)", address, name, uuid);
- return BLUETOOTH_ERROR_NONE;
-}
-
-void __bt_set_device_values(gboolean connected, int state)
-{
- int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
-
- if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
- BT_ERR("vconf_get_int failed");
-
- if (connected == TRUE)
- bt_device_state |= state;
- else if (bt_device_state & state)
- bt_device_state ^= state;
-
- if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
- BT_ERR("vconf_set_int failed");
-}
-
-gboolean _bt_discovery_finished_cb(gpointer user_data)
-{
- int result = BLUETOOTH_ERROR_NONE;
- event_id = 0;
- GVariant *param = NULL;
- if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
- if (_bt_get_cancel_by_user() == TRUE)
- result = BLUETOOTH_ERROR_CANCEL_BY_USER;
-
- _bt_set_cancel_by_user(FALSE);
- _bt_set_discovery_status(FALSE);
- param = g_variant_new("(i)", result);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERY_FINISHED,
- param);
- }
-
- return FALSE;
-}
-
-static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
-{
- int result = BLUETOOTH_ERROR_NONE;
- event_id = 0;
- GVariant *param = NULL;
- if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
- if (_bt_get_cancel_by_user() == TRUE)
- result = BLUETOOTH_ERROR_CANCEL_BY_USER;
-
- g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t);
- p_adv_ind_list = NULL;
-
- _bt_set_cancel_by_user(FALSE);
- _bt_disable_all_scanner_status();
- _bt_set_le_scan_status(FALSE);
- param = g_variant_new("(i)", result);
- _bt_send_event(BT_LE_ADAPTER_EVENT,
- BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED,
- param);
- }
-
- return FALSE;
-}
-
-void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_status)
-{
- BT_DBG("+");
-
- ret_if(address == NULL);
-
- GList * node;
- bt_cache_info_t *cache_info;
- bt_remote_dev_info_t *dev_info;
-
- node = g_list_first(p_cache_list);
-
- while (node != NULL) {
- cache_info = (bt_cache_info_t *)node->data;
-
- if (cache_info == NULL) {
- node = g_list_next(node);
- continue;
- }
-
- dev_info = cache_info->dev_info;
- if (strcasecmp(dev_info->address,
- address) == 0) {
- BT_DBG("Device Found");
- if (paired_status == TRUE)
- cache_info->dev_info->paired = TRUE;
- else
- cache_info->dev_info->paired = FALSE;
- break;
- }
- node = g_list_next(node);
- }
- BT_DBG("-");
-}
-
-static void __bt_device_remote_connected_properties(
- bt_remote_dev_info_t *remote_dev_info,
- char *address, gboolean connected)
-{
- int result = BLUETOOTH_ERROR_NONE;
- int i;
- GVariant *param = NULL;
- BT_DBG("+");
-
- if (remote_dev_info->uuid_count > 0) {
- for (i = 0; i < remote_dev_info->uuid_count; i++) {
- char *uuid = remote_dev_info->uuids[i];
- if (strcasecmp(uuid, HID_UUID) == 0) {
- int event = BLUETOOTH_EVENT_NONE;
-
- event = (connected == TRUE) ?
- BLUETOOTH_HID_CONNECTED :
- BLUETOOTH_HID_DISCONNECTED;
- param = g_variant_new("(is)", result,
- address);
- _bt_send_event(BT_HID_EVENT, event,
- param);
- break;
- }
- }
- }
-
- BT_DBG("-");
-}
-
-void _bt_handle_adapter_event(GVariant *msg, const char *member)
-{
- BT_DBG("+");
-
- int result = BLUETOOTH_ERROR_NONE;
- GVariant *param = NULL;
- ret_if(member == NULL);
-
- if (strcasecmp(member, "DeviceCreated") == 0) {
- char *object_path = NULL;
- char *address;
- bt_remote_dev_info_t *remote_dev_info;
-
- ret_if(_bt_is_device_creating() == FALSE);
-
- /* Bonding from remote device */
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- g_variant_get(msg, "(&o)", &object_path);
- _bt_convert_device_path_to_address((const char*)object_path, address);
-
- remote_dev_info = _bt_get_remote_device_info_by_object_path(object_path);
- if (remote_dev_info == NULL) {
- g_free(address);
- return;
- }
-
- _bt_free_device_info(remote_dev_info);
- g_free(address);
- } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
- char *object_path = NULL;
- char *address;
- bt_cache_info_t *cache_info;
- bt_remote_dev_info_t *dev_info;
- GList * node;
-
- /* Bonding from remote device */
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- g_variant_get(msg, "(&o)", &object_path);
-
- _bt_convert_device_path_to_address((const char *)object_path, address);
-
- node = g_list_first(p_cache_list);
-
- while (node != NULL) {
- cache_info = (bt_cache_info_t *)node->data;
-
- if (cache_info == NULL) {
- node = g_list_next(node);
- continue;
- }
-
- dev_info = cache_info->dev_info;
- if (strcasecmp(dev_info->address,
- address) == 0) {
- p_cache_list = g_list_remove(p_cache_list,
- cache_info);
- __bt_free_cache_info(cache_info);
- break;
- }
- node = g_list_next(node);
- }
- g_free(address);
- } else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
- BT_DBG("Advertising Enabled");
- int slot_id;
- int event;
- int adv_handle;
- gboolean status = FALSE;
-
- g_variant_get(msg, "(ib)", &slot_id, &status);
-
- BT_DBG("Advertising Enabled : slot_id [%d] status [%d]", slot_id, status);
-
- /* Send event to application */
- _bt_set_advertising_status(slot_id, status);
-
- adv_handle = _bt_get_adv_slot_adv_handle(slot_id);
-
- if (status)
- event = BLUETOOTH_EVENT_ADVERTISING_STARTED;
- else
- event = BLUETOOTH_EVENT_ADVERTISING_STOPPED;
- param = g_variant_new("(ii)", result,
- adv_handle);
-
-#if 0
- const char *sender;
- sender = _bt_get_adv_slot_owner(slot_id);
- _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
- event,
- param);
-#else
- _bt_send_event(BT_ADAPTER_EVENT, event, param);
-#endif
-
- if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
- _bt_unregister_adv_slot_owner(slot_id);
- } else if (strcasecmp(member, "RssiEnabled") == 0) {
- BT_DBG("RSSI Enabled");
- gboolean status = FALSE;
- char *address = NULL;
- int link_type;
- g_variant_get(msg, "(sib)", &address, &link_type, &status);
-
- BT_DBG("RSSI Enabled [%s %d]", address, status);
- param = g_variant_new("(isib)", result,
- address, link_type, status);
- _bt_send_event(BT_DEVICE_EVENT,
- BLUETOOTH_EVENT_RSSI_ENABLED,
- param);
- g_free(address);
- } else if (strcasecmp(member, "RssiAlert") == 0) {
- BT_DBG("RSSI Alert");
- int alert_type;
- int rssi_dbm;
- int link_type;
- char *address = NULL;
- g_variant_get(msg, "(siii)", &address, &link_type, &alert_type, &rssi_dbm);
-
- BT_DBG("RSSI Alert: [Address %s LinkType %d] [Type %d DBM %d]",
- address, alert_type, rssi_dbm);
- param = g_variant_new("(isiii)", result,
- address, link_type, alert_type, rssi_dbm);
- _bt_send_event(BT_DEVICE_EVENT,
- BLUETOOTH_EVENT_RSSI_ALERT,
- param);
- g_free(address);
- } else if (strcasecmp(member, "RawRssi") == 0) {
- BT_DBG("RSSI Raw");
- int rssi_dbm;
- int link_type;
- char *address = NULL;
- g_variant_get(msg, "(sii)", &address, &link_type, &rssi_dbm);
-
- BT_DBG("Raw RSSI: [Address %s] [Link Type %d][RSSI DBM %d]",
- address, link_type, rssi_dbm);
- param = g_variant_new("(isii)", result,
- address, link_type, rssi_dbm);
- _bt_send_event(BT_DEVICE_EVENT,
- BLUETOOTH_EVENT_RAW_RSSI,
- param);
- g_free(address);
- } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
- BT_ERR_C("### Hardware error received from BLUEZ");
-/* Don't add the recovery logic into platform */
-#if 0
- _bt_recover_adapter();
-#endif
- } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
- BT_ERR_C("### Tx timeout error received from BLUEZ");
-/* Don't add the recovery logic into platform */
-#if 0
- _bt_recover_adapter();
-#endif
- }
- BT_DBG("-");
-}
-
-static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
-{
- GDBusProxy *adapter_proxy;
- int mode = 0;
- int result = BLUETOOTH_ERROR_NONE;
- GVariantIter value_iter;
- GVariant *val = NULL;
- GVariant *ret = NULL;
- GError *err = NULL;
- char *property = NULL;
- GVariant *param = NULL;
-
- g_variant_iter_init(&value_iter, msg);
- while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
- BT_INFO("Property %s", property);
-
- if (strcasecmp(property, "Discovering") == 0) {
- gboolean discovering = FALSE;
-
- if (_bt_adapter_get_status() != BT_ACTIVATED)
- continue;
-
- g_variant_get(val, "b", &discovering);
- BT_DBG("Discovering %d", discovering);
-
- /* Send event to application */
- if (discovering == TRUE) {
- _bt_set_discovery_status(TRUE);
- param = g_variant_new("(i)", result);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERY_STARTED,
- param);
- } else {
- if (event_id > 0)
- continue;
-
- adapter_proxy = _bt_get_adapter_proxy();
- if (adapter_proxy == NULL)
- continue;
-
- /* Need to stop searching */
- ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL,
- &err);
- if (err) {
- BT_ERR("Dbus Error : %s", err->message);
- g_clear_error(&err);
- }
- if (ret)
- g_variant_unref(ret);
-
- event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
- (GSourceFunc)_bt_discovery_finished_cb, NULL);
- }
- } else if (strcasecmp(property, "LEDiscovering") == 0) {
- gboolean le_discovering = FALSE;
-
- if (_bt_adapter_get_status() != BT_ACTIVATED ||
- _bt_adapter_get_le_status() != BT_LE_ACTIVATED)
- continue;
-
- g_variant_get(val, "b", &le_discovering);
- BT_DBG("LEDiscovering %d", le_discovering);
-
- /* Send event to application */
- if (le_discovering == TRUE) {
- _bt_set_le_scan_status(TRUE);
- param = g_variant_new("(i)", result);
- _bt_send_event(BT_LE_ADAPTER_EVENT,
- BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
- param);
- } else {
- if (event_id > 0)
- continue;
-
- adapter_proxy = _bt_get_adapter_proxy();
- if (adapter_proxy == NULL)
- continue;
-
- /* Need to stop searching */
- ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL,
- &err);
- if (err) {
- BT_ERR("Dbus Error %s", err->message);
- g_clear_error(&err);
- }
- if (ret)
- g_variant_unref(ret);
-
- event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
- (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
- }
- } else if (strcasecmp(property, "Name") == 0) {
- char *name = NULL;
- g_variant_get(val, "&s", &name);
- param = g_variant_new("(is)", result, name);
- /* Send event to application */
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
- param);
- } else if (strcasecmp(property, "Alias") == 0) {
- char *alias = NULL;
- g_variant_get(val, "&s", &alias);
- param = g_variant_new("(is)", result, alias);
- /* Send event to application */
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
- param);
- } else if (strcasecmp(property, "Discoverable") == 0) {
- gboolean discoverable = FALSE;
-
- g_variant_get(val, "b", &discoverable);
- BT_DBG("discoverable %d", discoverable);
-
- if (discoverable == FALSE) {
- if (_bt_get_discoverable_timeout_property() > 0) {
- unsigned int time = 0;
-
- adapter_proxy = _bt_get_adapter_properties_proxy();
- if (adapter_proxy == NULL)
- continue;
-
- ret = g_dbus_proxy_call_sync(adapter_proxy, "Set",
- g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
- "DiscoverableTimeout",
- g_variant_new("u", time)),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL,
- &err);
-
- if (err != NULL) {
- BT_ERR("Set DiscoverableTimeout Failed: %s", err->message);
- g_clear_error(&err);
- }
- if (ret)
- g_variant_unref(ret);
- }
-
- mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
-
- /* Send event to application */
- BT_INFO("[Non Discoverable]");
- param = g_variant_new("(in)", result, mode);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
- param);
- } else {
- _bt_get_discoverable_mode(&mode);
-
- /* Event will be sent by "DiscoverableTimeout" signal */
- if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
- g_free(property);
- g_variant_unref(val);
- return;
- }
-
- /* Send event to application */
- BT_INFO("[General Discoverable]");
- param = g_variant_new("(in)", result, mode);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
- param);
- }
- } else if (strcasecmp(property, "DiscoverableTimeout") == 0) {
- _bt_get_discoverable_mode(&mode);
-
- /* Event was already sent by "Discoverable" signal */
- if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
- mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE)
- continue;
-
- /* Send event to application */
- BT_INFO("[Limited Discoverable (Timeout %u secs)]",
- _bt_get_discoverable_timeout_property());
- param = g_variant_new("(in)", result, mode);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
- param);
- } else if (strcasecmp(property, "Powered") == 0) {
- gboolean powered = FALSE;
- int bt_state = VCONFKEY_BT_STATUS_OFF;
- int le_state = VCONFKEY_BT_LE_STATUS_OFF;
-
- g_variant_get(val, "b", &powered);
- BT_DBG("Powered = %d", powered);
-
-#ifdef USB_BLUETOOTH
- if (powered) {
- _bt_handle_adapter_added();
- continue;
- }
-
- _bt_handle_adapter_removed();
-
- vconf_get_int(VCONFKEY_BT_LE_STATUS, &le_state);
- if (le_state != VCONFKEY_BT_LE_STATUS_OFF)
- _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
-#else
- if (powered)
- continue;
-
- vconf_get_int(VCONFKEY_BT_STATUS, &bt_state);
- if (bt_state != VCONFKEY_BT_STATUS_OFF)
- _bt_disable_adapter();
-
- vconf_get_int(VCONFKEY_BT_LE_STATUS, &le_state);
- if (le_state != VCONFKEY_BT_LE_STATUS_OFF)
- _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
-#endif
- } else if (strcasecmp(property, "Connectable") == 0) {
- gboolean connectable = FALSE;
-
- g_variant_get(val, "b", &connectable);
-
- BT_DBG("Connectable property is changed : %d", connectable);
- param = g_variant_new("(b)", connectable);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_CONNECTABLE_CHANGED,
- param);
-#if 0
- if (_bt_adapter_get_status() == BT_DEACTIVATING &&
- _bt_adapter_get_le_status() == BT_LE_ACTIVATED &&
- connectable == 0)
- _bt_set_disabled(BLUETOOTH_ERROR_NONE);
-#endif
- } else if (strcasecmp(property, "SupportedLEFeatures") == 0) {
- char *name = NULL;
- char *value = NULL;
- GVariantIter *iter = NULL;
-
- g_variant_get(val, "as", &iter);
- if (iter == NULL)
- continue;
-
- while (g_variant_iter_next(iter, "&s", &name) &&
- g_variant_iter_next(iter, "&s", &value)) {
- BT_DBG("name = %s, Value = %s", name, value);
- if (!_bt_update_le_feature_support(name, value))
- BT_ERR("Failed to update LE feature (name = %s, value = %s)", name, value);
- }
- g_variant_iter_free(iter);
- } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
- gboolean ipsp_initialized = FALSE;
-
- g_variant_get(val, "b", &ipsp_initialized);
- BT_DBG("IPSP init state changed: %d", ipsp_initialized);
- param = g_variant_new("(b)", ipsp_initialized);
-
- /* Send event to application */
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
- param);
- } else {
- BT_DBG("Unhandled property : [%s]", property);
- }
- }
-}
-
-static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
-{
- BT_DBG("+");
-
- GVariantIter value_iter;
- GVariant *child = NULL, *val = NULL;
- char *property = NULL;
- g_variant_iter_init(&value_iter, msg);
- while ((child = g_variant_iter_next_value(&value_iter))) {
- g_variant_get(child, "{sv}", &property, &val);
-
- ret_if(property == NULL);
-
- BT_DBG("property :%s", property);
-
- if (strcasecmp(property, "Status") == 0) {
- char *status;
- g_variant_get(val, "s", &status);
-
- if (strcasecmp(status, "active") == 0) {
- _bt_obex_transfer_started(path);
- } else if (strcasecmp(status, "complete") == 0) {
- _bt_obex_transfer_completed(path, TRUE);
- _bt_pbap_obex_transfer_completed(path, TRUE);
- } else if (strcasecmp(status, "error") == 0) {
- _bt_obex_transfer_completed(path, FALSE);
- _bt_pbap_obex_transfer_completed(path, FALSE);
- }
- g_free(status);
- } else if (strcasecmp(property, "Transferred") == 0) {
- guint64 transferred = 0;
- /* As Transferred is expected guint64 so change int to guint64 and
- * eariler transferred is static because of it can overwrite data
- * on present on opc_obex_conn or obexd_conn as these are
- * static memory are in sequential */
- g_variant_get(val, "t", &transferred);
-
- _bt_obex_transfer_progress(path, transferred);
- }
- g_free(property);
- g_variant_unref(val);
- g_variant_unref(child);
- }
- BT_DBG("-");
-}
-
-static void __bt_device_property_changed_event(GVariant *msg, const char *path)
-{
- BT_DBG("+");
-
- int event;
- int result = BLUETOOTH_ERROR_NONE;
- GVariantIter value_iter;
- GVariant *val;
- char *property = NULL;
- char *address;
- GVariant *param = NULL;
- bt_remote_dev_info_t *remote_dev_info;
- g_variant_iter_init(&value_iter, msg);
- while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
- BT_DBG("Property %s", property);
- if (strcasecmp(property, "Connected") == 0) {
- guint connected = 0;
-
- g_variant_get(val, "i", &connected);
-
- event = (connected != BLUETOOTH_CONNECTED_LINK_NONE) ?
- BLUETOOTH_EVENT_DEVICE_CONNECTED :
- BLUETOOTH_EVENT_DEVICE_DISCONNECTED;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- BT_DBG("connected: %d", connected);
- BT_DBG("address: %s", address);
-
- remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
-
- if (remote_dev_info != NULL) {
- __bt_device_remote_connected_properties(
- remote_dev_info, address,
- connected != BLUETOOTH_CONNECTED_LINK_NONE ?
- TRUE : FALSE);
- _bt_free_device_info(remote_dev_info);
- }
- param = g_variant_new("(is)", result, address);
- /* Send event to application */
- _bt_send_event(BT_DEVICE_EVENT,
- event,
- param);
- g_free(address);
- } else if (strcasecmp(property, "RSSI") == 0) {
- bt_remote_dev_info_t *remote_dev_info;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
- BT_DBG("address: %s", address);
-
- remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
- if (remote_dev_info == NULL) {
- g_free(property);
- g_variant_unref(val);
- g_free(address);
- return;
- }
- BT_DBG("Address type %d", remote_dev_info->addr_type);
-
- if (remote_dev_info->addr_type == 0) {
- BT_DBG("Name %s", remote_dev_info->name);
-
-#ifdef TIZEN_DPM_ENABLE
- if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
- DPM_RESTRICTED) {
- bluetooth_device_class_t device_class;
- _bt_divide_device_class(&device_class, remote_dev_info->class);
-
- if (device_class.major_class ==
- BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
- _bt_free_device_info(remote_dev_info);
- g_free(property);
- g_variant_unref(val);
- g_free(address);
- return;
- }
- }
-#endif
-
- GVariant *uuids = NULL;
- GVariantBuilder *builder = NULL;
- int i = 0;
- builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
- for (i = 0; i < remote_dev_info->uuid_count; i++) {
- g_variant_builder_add(builder, "s",
- remote_dev_info->uuids[i]);
- }
- uuids = g_variant_new("as", builder);
- g_variant_builder_unref(builder);
- GVariant *manufacturer_data = NULL;
- manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
- remote_dev_info->manufacturer_data,
- remote_dev_info->manufacturer_data_len,
- TRUE,
- NULL, NULL);
- param = g_variant_new("(isunsbub@asn@ay)", result,
- remote_dev_info->address,
- remote_dev_info->class,
- remote_dev_info->rssi,
- remote_dev_info->name,
- remote_dev_info->paired,
- remote_dev_info->connected,
- remote_dev_info->trust,
- uuids,
- remote_dev_info->manufacturer_data_len,
- manufacturer_data);
-
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
- param);
- g_free(address);
- }
- _bt_free_device_info(remote_dev_info);
- } else if (strcasecmp(property, "GattConnected") == 0) {
- gboolean gatt_connected = FALSE;
-
- g_variant_get(val, "b", &gatt_connected);
-
- event = gatt_connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
- BLUETOOTH_EVENT_GATT_DISCONNECTED;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- BT_DBG("gatt_connected: %d", gatt_connected);
- BT_DBG("address: %s", address);
- param = g_variant_new("(is)", result, address);
- /* Send event to application */
- _bt_send_event(BT_DEVICE_EVENT,
- event,
- param);
- g_free(address);
- } else if (strcasecmp(property, "Paired") == 0) {
- gboolean paired = FALSE;
- bt_remote_dev_info_t *remote_dev_info;
- g_variant_get(val, "b", &paired);
- _bt_agent_set_canceled(FALSE);
- /* BlueZ sends paired signal for each paired device */
- /* during activation, We should ignore this, otherwise*/
- /* application thinks that a new device got paired */
- if (_bt_adapter_get_status() != BT_ACTIVATED) {
- BT_DBG("BT is not activated, so ignore this");
- g_free(property);
- g_variant_unref(val);
- return;
- }
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
- if (remote_dev_info == NULL) {
- g_free(property);
- g_variant_unref(val);
- g_free(address);
- return;
- }
-
- if (paired == FALSE) {
- BT_INFO("Unpaired: %s", address);
- __bt_update_remote_cache_devinfo(address, FALSE);
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
- param);
-#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
- {
- char *last_connected = NULL;
- last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
- if (!g_strcmp0(address, last_connected))
- _bt_audio_set_auto_connect_device_addr("");
- if (last_connected)
- free(last_connected);
- }
-#endif
- } else {
- char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
-
- _bt_convert_addr_string_to_secure_string(secure_addr, address);
- BT_INFO(" ### Paired: %s", secure_addr);
- __bt_update_remote_cache_devinfo(address, TRUE);
-
- GVariant *uuids = NULL;
- GVariantBuilder *builder = NULL;
- int i = 0;
- builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
- for (i = 0; i < remote_dev_info->uuid_count; i++) {
- g_variant_builder_add(builder, "s",
- remote_dev_info->uuids[i]);
- }
- uuids = g_variant_new("as", builder);
- g_variant_builder_unref(builder);
- GVariant *manufacturer_data = NULL;
- manufacturer_data = g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING,
- remote_dev_info->manufacturer_data,
- remote_dev_info->manufacturer_data_len,
- TRUE,
- NULL, NULL);
-
- param = g_variant_new("(isunsbub@asn@ay)", result,
- address, remote_dev_info->class,
- remote_dev_info->rssi,
- remote_dev_info->name,
- remote_dev_info->paired,
- remote_dev_info->connected,
- remote_dev_info->trust,
- uuids,
- remote_dev_info->manufacturer_data_len,
- manufacturer_data);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_BONDING_FINISHED,
- param);
- }
- _bt_free_device_info(remote_dev_info);
- g_free(address);
- } else if (strcasecmp(property, "LegacyPaired") == 0) {
- gboolean paired = FALSE;
- bt_remote_dev_info_t *remote_dev_info;
- unsigned char auth_info[5] = {0, };
-
- if (_bt_adapter_get_status() != BT_ACTIVATED) {
- BT_DBG("BT is not activated, so ignore this");
- g_free(property);
- g_variant_unref(val);
- return;
- }
-
- g_variant_get(val, "b", &paired);
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- BT_DBG("LegacyPaired: %d", paired);
- _bt_convert_device_path_to_address(path, address);
-
- remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
- if (remote_dev_info == NULL) {
- g_free(address);
- g_free(property);
- g_variant_unref(val);
- return;
- }
- if (remote_dev_info->is_alias_set == FALSE) {
- /*minimum Size of the samsung specific manufacturer data is greater than 30 */
- if ((remote_dev_info->manufacturer_data_len > 30) &&
- (remote_dev_info->manufacturer_data[0] == 0x00) &&
- (remote_dev_info->manufacturer_data[1] == 0x75)) {
-
- /* 2 samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
- 1 (discovery version) + 1 (associated service ID)
- 2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
-
- memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
- }
- }
-
- BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
- _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
- remote_dev_info->name, auth_info, NULL, NULL, NULL);
-
- _bt_free_device_info(remote_dev_info);
- g_free(address);
- } else if (strcasecmp(property, "Trusted") == 0) {
- gboolean trusted = FALSE;
-
- g_variant_get(val, "b", &trusted);
-
- event = trusted ? BLUETOOTH_EVENT_DEVICE_AUTHORIZED :
- BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- BT_DBG("trusted: %d", trusted);
- BT_DBG("address: %s", address);
- param = g_variant_new("(is)", result, address);
- /* Send event to application */
- _bt_send_event(BT_DEVICE_EVENT,
- event,
- param);
- g_free(address);
- } else if (strcasecmp(property, "TrustedProfiles") == 0) {
- int trusted = 0;
-
- g_variant_get(val, "u", &trusted);
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- _bt_convert_device_path_to_address(path, address);
-
- BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
- _bt_send_event(BT_DEVICE_EVENT,
- BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
- g_variant_new("(isi)", result, address, trusted));
- g_free(address);
- } else if (strcasecmp(property, "IpspConnected") == 0) {
- gboolean connected = FALSE;
-
- g_variant_get(val, "b", &connected);
-
-
- event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
- BLUETOOTH_EVENT_IPSP_DISCONNECTED;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- BT_DBG("Ipspconnected: %d", connected);
- BT_DBG("address: %s", address);
- param = g_variant_new("(is)", result, address);
-
- /* Send event to application */
- _bt_send_event(BT_DEVICE_EVENT,
- event,
- param);
- g_free(address);
- } else if (strcasecmp(property, "IpspBtInterfaceInfo") == 0) {
- char *ifname = NULL;
-
- g_variant_get(val, "&s", &ifname);
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- BT_DBG("Ipsp BT Interface Name: %s", ifname);
- BT_DBG("address: %s", address);
- param = g_variant_new("(iss)", result, address, ifname);
-
- /* Send event to application */
- _bt_send_event(BT_DEVICE_EVENT,
- BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
- param);
- g_free(address);
- }
- }
- BT_DBG("-");
-}
-
-static void __bt_media_control_changed_event(GVariant *msg, const char *path)
-{
- int event;
- int result = BLUETOOTH_ERROR_NONE;
- GVariantIter value_iter;
- char *property = NULL;
- char *address;
- GVariant *val = NULL;
- GVariant *child = NULL;
- bt_remote_dev_info_t *remote_dev_info;
- GVariant *param = NULL;
- g_variant_iter_init(&value_iter, msg);
- while ((child = g_variant_iter_next_value(&value_iter))) {
- g_variant_get(child, "{sv}", &property, &val);
- BT_INFO("Property %s", property);
- if (strcasecmp(property, "Connected") == 0) {
- gboolean connected = FALSE;
-
- g_variant_get(val, "b", &connected);
-
- event = connected ? BLUETOOTH_EVENT_AVRCP_CONNECTED :
- BLUETOOTH_EVENT_AVRCP_DISCONNECTED;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- BT_DBG("connected: %d", connected);
- BT_DBG("address: %s", address);
-
- remote_dev_info = _bt_get_remote_device_info(address);
-
- if (remote_dev_info != NULL) {
- __bt_device_remote_connected_properties(
- remote_dev_info, address, connected);
- _bt_free_device_info(remote_dev_info);
- }
- param = g_variant_new("(is)", result, address);
- /* Send event to application */
- _bt_send_event(BT_AVRCP_EVENT,
- event,
- param);
- g_free(address);
- }
- g_free(property);
- g_variant_unref(child);
- g_variant_unref(val);
- }
- BT_DBG("-");
-}
-
-int get_alert_level_enum(const char *alert)
-{
- int lvl = -1;
-
- if (strcmp(alert, "none") == 0)
- lvl = BT_PXP_ALERT_NONE;
- else if (strcmp(alert, "mild") == 0)
- lvl = BT_PXP_ALERT_MILD;
- else if (strcmp(alert, "high") == 0)
- lvl = BT_PXP_ALERT_HIGH;
-
- return lvl;
-}
-
-static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
-{
- int result = BLUETOOTH_ERROR_NONE;
- int service_type;
- int alert_lvl;
- GVariantIter value_iter;
- char *property = NULL;
- char *address;
- GVariant *val = NULL;
- GVariant *child = NULL;
- GVariant *param = NULL;
- g_variant_iter_init(&value_iter, msg);
-
- BT_DBG("+");
- while ((child = g_variant_iter_next_value(&value_iter))) {
- g_variant_get(child, "{sv}", &property, &val);
- BT_INFO("Property %s", property);
-
- if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
- (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
- char *alert_str = NULL;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- _bt_convert_device_path_to_address(path, address);
-
- if (strcasecmp(property, "LinkLossAlertLevel") == 0)
- service_type = BT_PXP_PROPERTY_LLS;
- else
- service_type = BT_PXP_PROPERTY_IAS;
-
- g_variant_get(val, "s", &alert_str);
- alert_lvl = get_alert_level_enum(alert_str);
-
- param = g_variant_new("(isiii)", result, address,
- role, service_type, alert_lvl);
-
- /* Send event to application */
- _bt_send_event(BT_DEVICE_EVENT,
- BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
- param);
- g_free(address);
- g_free(alert_str);
- }
- g_free(property);
- g_variant_unref(child);
- g_variant_unref(val);
- }
- BT_DBG("-");
-}
-
-void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
-{
- char *interface_name = NULL;
- GVariant *val = NULL;
-
- g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &val, NULL);
-
- if (strcasecmp(interface_name, BT_ADAPTER_INTERFACE) == 0) {
- __bt_adapter_property_changed_event(val,
- object_path);
- } else if (strcasecmp(interface_name, BT_DEVICE_INTERFACE) == 0) {
- __bt_device_property_changed_event(val, object_path);
- } else if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
- BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
- __bt_obex_property_changed_event(val,
- object_path);
- } else if (strcasecmp(interface_name, BT_MEDIA_CONTROL_INTERFACE) == 0) {
- __bt_media_control_changed_event(val,
- object_path);
- } else if (strcasecmp(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
- _bt_handle_avrcp_control_event(val,
- object_path);
- } else if (strcasecmp(interface_name, BT_NETWORK_CLIENT_INTERFACE) == 0) {
- BT_DBG("BT_NETWORK_CLIENT_INTERFACE");
- _bt_handle_network_client_event(val,
- object_path);
- } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
- __bt_gatt_char_property_changed_event(val,
- object_path);
- } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
- BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
- _bt_handle_pxp_property_changed_event(val,
- object_path, BT_PXP_REPORTER_ROLE);
- } else if (strcasecmp(interface_name, BT_PROXIMITY_MONITOR_INTERFACE) == 0) {
- BT_DBG("BT_PROXIMITY_MONITOR_INTERFACE");
- _bt_handle_pxp_property_changed_event(val,
- object_path, BT_PXP_MONITOR_ROLE);
- }
- g_variant_unref(val);
-}
-
-void __bt_opc_property_changed_event(GVariant *msg,
- const char *path)
-{
- GVariantIter value_iter;
- char *property = NULL;
- GVariant *val = NULL;
- GVariant *child = NULL;
-
- g_variant_iter_init(&value_iter, msg);
- while ((child = g_variant_iter_next_value(&value_iter))) {
- g_variant_get(child, "{sv}", &property, &val);
- ret_if(property == NULL);
-
- if (strcasecmp(property, "Status") == 0) {
- char *status = NULL;
- g_variant_get(val, "s", &status);
- BT_DBG("Status is %s", status);
-
- if (strcasecmp(status, "active") == 0)
- _bt_obex_client_started(path);
- else if (strcasecmp(status, "complete") == 0)
- _bt_obex_client_completed(path, TRUE);
- else if (strcasecmp(status, "error") == 0)
- _bt_obex_client_completed(path, FALSE);
-
- g_free(status);
- } else if (strcasecmp(property, "Transferred") == 0) {
- guint64 transferred = 0;
- g_variant_get(val, "t", &transferred);
-
- _bt_obex_client_progress(path, transferred);
- } else {
- BT_DBG("property : [%s]", property);
- }
- g_free(property);
- g_variant_unref(child);
- g_variant_unref(val);
- }
-}
-
-void _bt_opc_property_changed_event(GVariant *msg, char *path)
-{
- char *interface_name = NULL;
- GVariant *value = NULL;
- g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
- BT_INFO("interface_name = %s", interface_name);
- if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
- __bt_opc_property_changed_event(value,
- path);
- } else {
- BT_DBG("interface_name : [%s]", interface_name);
- }
- g_variant_unref(value);
-}
-
-
-void _bt_handle_input_event(GVariant *msg, const char *path)
-{
- int result = BLUETOOTH_ERROR_NONE;
- gboolean property_flag = FALSE;
- GVariantIter value_iter;
- char *property = NULL;
- GVariant *child = NULL, *val = NULL;
- bt_remote_dev_info_t *remote_dev_info;
- GVariant *param = NULL;
- g_variant_iter_init(&value_iter, msg);
- while ((child = g_variant_iter_next_value(&value_iter))) {
- g_variant_get(child, "{sv}", &property, &val);
-
- ret_if(property == NULL);
-
- if (strcasecmp(property, "Connected") == 0) {
- int event = BLUETOOTH_EVENT_NONE;
- char *address;
- g_variant_get(val, "b", &property_flag);
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- event = (property_flag == TRUE) ?
- BLUETOOTH_HID_CONNECTED :
- BLUETOOTH_HID_DISCONNECTED;
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_HID_EVENT, event,
- param);
- /* Check HID connection type (Keyboard or Mouse) and update the status */
- remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
-
- if (property_flag == TRUE) {
- hid_connected_device_count++;
- __bt_set_device_values(TRUE,
- VCONFKEY_BT_DEVICE_HID_CONNECTED);
- } else {
- hid_connected_device_count--;
- if (hid_connected_device_count == 0)
- __bt_set_device_values(FALSE,
- VCONFKEY_BT_DEVICE_HID_CONNECTED);
- }
-
- if (remote_dev_info != NULL) {
- BT_DBG("HID device class [%x]", remote_dev_info->class);
- if (remote_dev_info->class &
- BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
- __bt_set_device_values(property_flag,
- VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
-
- }
-
- if (remote_dev_info->class &
- BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
- __bt_set_device_values(property_flag,
- VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
- }
- _bt_free_device_info(remote_dev_info);
- }
- g_free(address);
- }
- g_free(property);
- g_variant_unref(val);
- g_variant_unref(child);
- }
-}
-
-void _bt_handle_network_server_event(GVariant *msg, const char *member)
-{
- int result = BLUETOOTH_ERROR_NONE;
- char *address = NULL;
- char *device = NULL;
- GVariant *param = NULL;
- ret_if(member == NULL);
- if (strcasecmp(member, "PeerConnected") == 0) {
- g_variant_get(msg, "(ss)", &device, &address);
-
- __bt_set_device_values(TRUE,
- VCONFKEY_BT_DEVICE_PAN_CONNECTED);
- param = g_variant_new("(iss)", result, device, address);
- _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED,
- param);
- g_free(device);
- g_free(address);
- nap_connected_device_count++;
- } else if (strcasecmp(member, "PeerDisconnected") == 0) {
- g_variant_get(msg, "(ss)", &device, &address);
- nap_connected_device_count--;
- if (nap_connected_device_count == 0)
- __bt_set_device_values(FALSE,
- VCONFKEY_BT_DEVICE_PAN_CONNECTED);
- param = g_variant_new("(iss)", result, device, address);
- _bt_send_event(BT_NETWORK_EVENT, BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED,
- param);
- g_free(device);
- g_free(address);
- }
-}
-
-void _bt_handle_network_client_event(GVariant *msg,
- const char *path)
-{
- BT_DBG("+");
-
- int result = BLUETOOTH_ERROR_NONE;
- gboolean property_flag = FALSE;
- char *property = NULL;
- GVariant *val = NULL;
- GVariantIter value_iter;
- GVariant *param = NULL;
- g_variant_iter_init(&value_iter, msg);
- while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
- if (strcasecmp(property, "Connected") == 0) {
- int event = BLUETOOTH_EVENT_NONE;
- char *address;
-
- g_variant_get(val, "b", &property_flag);
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- BT_DBG("property_flag %d", property_flag);
- if (property_flag == TRUE) {
- event = BLUETOOTH_EVENT_NETWORK_CONNECTED;
- nap_connected_device_count++;
- __bt_set_device_values(TRUE,
- VCONFKEY_BT_DEVICE_PAN_CONNECTED);
- } else {
- event = BLUETOOTH_EVENT_NETWORK_DISCONNECTED;
- nap_connected_device_count--;
- if (nap_connected_device_count == 0)
- __bt_set_device_values(FALSE,
- VCONFKEY_BT_DEVICE_PAN_CONNECTED);
- }
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_NETWORK_EVENT, event,
- param);
-
- g_free(address);
- }
- }
- BT_DBG("-");
-}
-
-void __bt_gatt_char_property_changed_event(GVariant *msg,
- const char *path)
-{
- GVariantIter value_iter;
- char *property = NULL;
- char * char_handle = NULL;
- GVariant *val = NULL;
- int result = BLUETOOTH_ERROR_NONE;
- GVariant *param = NULL;
- g_variant_iter_init(&value_iter, msg);
- char_handle = g_strdup(path);
- while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
- BT_DBG("Property %s", property);
-
- ret_if(property == NULL);
-
- if (strcasecmp(property, "Notifying") == 0) {
- gboolean property_flag = FALSE;
- g_variant_get(val, "b", &property_flag);
- BT_INFO("Notifying is %s", property_flag ? "enabled" : "disabled");
- } else if (strcasecmp(property, "ChangedValue") == 0) {
- int len = 0;
- GByteArray *gp_byte_array = NULL;
- BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
-
- if (val) {
- gp_byte_array = g_byte_array_new();
- len = g_variant_get_size(val);
- BT_DBG("Len = %d", len);
- g_byte_array_append(gp_byte_array,
- (const guint8 *) g_variant_get_data(val), len);
- if (gp_byte_array->len != 0) {
- GVariant *byte_array = NULL;
- byte_array = g_variant_new_from_data(
- G_VARIANT_TYPE_BYTESTRING,
- gp_byte_array->data,
- gp_byte_array->len,
- TRUE, NULL, NULL);
- param = g_variant_new("(is@ay)", result, char_handle,
- byte_array);
-
- /* Send event only registered client */
- _bt_send_char_value_changed_event(param);
- }
- g_byte_array_free(gp_byte_array, TRUE);
- }
- }
- }
- g_free(char_handle);
-}
-
-void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
-{
- ret_if(path == NULL);
-
- if (strcasecmp(member, "GattValueChanged") == 0) {
-
-#if 0 // Debug Only
- /*** Debug only ***/
- GVariant *value = NULL;
- int value_len = 0;
- char *buffer = NULL;
-
- g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
- value_len = g_variant_get_size(value);
- if (value_len > 0) {
- char buf[8 * 5 + 1] = { 0 };
- int i;
- int to;
- buffer = (char *)g_variant_get_data(value);
- to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
-
- for (i = 0; i < to; i++)
- snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
- buf[i * 5] = '\0';
- BT_DBG("GATT Val[%d] %s", value_len, buf);
- }
- g_variant_unref(value);
- /******/
-#endif
-
- /* Send event only registered client */
- _bt_send_char_value_changed_event(msg);
- }
-}
-
-
-void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
-{
- int event = 0;
- int result = BLUETOOTH_ERROR_NONE;
- char *address;
- char *dev_name = NULL;
- const char *property = NULL;
- GVariant *param = NULL;
- char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- ret_if(path == NULL);
-
- if (strcasecmp(member, "PropertyChanged") == 0) {
-
- g_variant_get(msg, "(s)", &property);
-
- ret_if(property == NULL);
-
- if (strcasecmp(property, "GattConnected") == 0) {
- gboolean connected = FALSE;
- char *address;
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
- g_variant_get(msg, "(b)", &connected);
-
- event = connected ? BLUETOOTH_EVENT_GATT_CONNECTED :
- BLUETOOTH_EVENT_GATT_DISCONNECTED;
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_DEVICE_EVENT,
- event,
- param);
- g_free(address);
- } else if (strcasecmp(property, "Paired") == 0) {
- gboolean paired = FALSE;
- bt_remote_dev_info_t *remote_dev_info;
- g_variant_get(msg, "(b)", &paired);
-
- ret_if(paired == FALSE);
-
- /* BlueZ sends paired signal for each paired device */
- /* during activation, We should ignore this, otherwise*/
- /* application thinks that a new device got paired */
- if (_bt_adapter_get_status() != BT_ACTIVATED) {
- BT_DBG("BT is not activated, so ignore this");
- return;
- }
-
- if (_bt_is_device_creating() == TRUE) {
- BT_DBG("Try to Pair by me");
- return;
- }
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
- if (remote_dev_info == NULL) {
- g_free(address);
- return;
- }
- GVariant *uuids = NULL;
- GVariantBuilder *builder = NULL;
- int i = 0;
- builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
- for (i = 0; i < remote_dev_info->uuid_count; i++) {
- g_variant_builder_add(builder, "s",
- remote_dev_info->uuids[i]);
- }
- uuids = g_variant_new("as", builder);
- g_variant_builder_unref(builder);
- GVariant *manufacturer_data = NULL;
- manufacturer_data = g_variant_new_from_data(
- G_VARIANT_TYPE_BYTESTRING,
- remote_dev_info->manufacturer_data,
- remote_dev_info->manufacturer_data_len,
- TRUE, NULL, NULL);
- param = g_variant_new("(isunsbub@asn@ay)", result,
- address,
- remote_dev_info->class,
- remote_dev_info->rssi,
- remote_dev_info->name,
- remote_dev_info->paired,
- remote_dev_info->connected,
- remote_dev_info->trust,
- uuids,
- remote_dev_info->manufacturer_data_len,
- manufacturer_data);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_BONDING_FINISHED,
- param);
- _bt_free_device_info(remote_dev_info);
- g_free(address);
-
- } else if (strcasecmp(property, "UUIDs") == 0) {
- /* Once we get the updated uuid information after
- * reverse service search, update it to application */
-
- bt_remote_dev_info_t *remote_dev_info;
-
- ret_if(_bt_is_device_creating() == TRUE);
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
- if (remote_dev_info == NULL) {
- g_free(address);
- return;
- }
-
- BT_DBG("UUID's count = %d", remote_dev_info->uuid_count);
- if (remote_dev_info->paired && remote_dev_info->uuid_count) {
- GVariant *uuids = NULL;
- GVariantBuilder *builder = NULL;
- int i = 0;
- builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
- for (i = 0; i < remote_dev_info->uuid_count; i++) {
- g_variant_builder_add(builder, "s",
- remote_dev_info->uuids[i]);
- }
- uuids = g_variant_new("as", builder);
- g_variant_builder_unref(builder);
- GVariant *manufacture_data = g_variant_new_from_data((const GVariantType *)"ay",
- remote_dev_info->manufacturer_data, remote_dev_info->manufacturer_data_len,
- TRUE, NULL, NULL);
-
- param = g_variant_new("(isunsbub@asn@ay)", result,
- address, remote_dev_info->class,
- remote_dev_info->rssi,
- remote_dev_info->name,
- remote_dev_info->paired,
- remote_dev_info->connected,
- remote_dev_info->trust,
- uuids,
- remote_dev_info->manufacturer_data_len,
- manufacture_data);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_SERVICE_SEARCHED,
- param);
- }
-
- _bt_free_device_info(remote_dev_info);
- g_free(address);
- }
- } else if (strcasecmp(member, "DeviceConnected") == 0) {
- unsigned char addr_type = 0;
-
- g_variant_get(msg, "(y)", &addr_type);
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
- dev_name = _bt_get_device_name(address);
-
- _bt_convert_addr_string_to_secure_string(secure_address, address);
- BT_INFO("Address : %s Type : %d", secure_address, addr_type);
- BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
- !addr_type ? dev_name : secure_address);
- g_free(dev_name);
-
- if (addr_type)
- _bt_add_le_connected_dev_info(address);
-
- _bt_logging_connection(TRUE, addr_type);
- param = g_variant_new("(isy)", result, address, addr_type);
- /*Send event to application*/
- _bt_send_event(BT_DEVICE_EVENT,
- BLUETOOTH_EVENT_DEVICE_CONNECTED,
- param);
- g_free(address);
- } else if (strcasecmp(member, "Disconnected") == 0) {
- unsigned char disc_reason = 0;
- unsigned char addr_type = 0;
- char *dev_name = NULL;
- gboolean sending = FALSE;
-
- g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
-
- result = disc_reason;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- /* 0x00 BDADDR_BRDER
- 0x01 BDADDR_LE_PUBLIC
- 0x02 BDADDR_LE_RANDOM */
- _bt_convert_addr_string_to_secure_string(secure_address, address);
- BT_INFO("Address : %s Type : %d", secure_address, addr_type);
- BT_ERR_C("### Disconnected [%s] [%s] [%d : %s]", !addr_type ? "BREDR" : "LE",
- !addr_type ? dev_name : secure_address,
- disc_reason, _bt_convert_disc_reason_to_string(disc_reason));
- g_free(dev_name);
-
- _bt_headset_set_local_connection(FALSE);
- _bt_logging_connection(FALSE, addr_type);
-
- if (addr_type)
- _bt_remove_le_connected_dev_info(address);
- else {
-#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
- {
- int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
-
- if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
- BT_ERR("vconf_get_int failed");
-
- BT_INFO("conn_state[0x%x], adapter_state [%d]",
- bt_device_state, _bt_adapter_get_status());
-
- if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
- _bt_audio_start_auto_connect(TRUE);
- } else if (bt_device_state &
- VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
- BT_INFO("Disconnected due to turning BT off. Skip a address");
- } else {
- char *last_connected = NULL;
- last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
- if (!g_strcmp0(address, last_connected))
- _bt_audio_set_auto_connect_device_addr("");
- if (last_connected)
- free(last_connected);
- }
- }
-
-#endif
- /*Check for any OPP transfer on the device and cancel
- * the transfer
- */
- _bt_obex_check_pending_transfer(address);
- _bt_opp_client_is_sending(&sending);
- if (sending == TRUE)
- _bt_opp_client_check_pending_transfer(address);
- }
- param = g_variant_new("(isy)", result, address, addr_type);
- _bt_send_event(BT_DEVICE_EVENT,
- BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
- param);
- g_free(address);
- } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
- int state = 0;
- char *profile_uuid = NULL;
- bt_headset_wait_t *wait_list;
- bluetooth_device_address_t bd_addr;
-
- g_variant_get(msg, "(si)", &profile_uuid, &state);
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
- _bt_convert_addr_string_to_type(bd_addr.addr, address);
-
- _bt_convert_addr_string_to_secure_string(secure_address, address);
- BT_INFO_C("[%s] state: %s, addr: %s",
- _bt_convert_uuid_to_string(profile_uuid),
- _bt_convert_profile_state_to_string(state), secure_address);
-
- if (strcmp(profile_uuid, A2DP_SINK_UUID) == 0) {
- if (state == BT_PROFILE_STATE_CONNECTED) {
-
- int event = BLUETOOTH_EVENT_AV_CONNECTED;
- char connected_address[BT_ADDRESS_STRING_SIZE + 1];
- bluetooth_device_address_t device_address;
- gboolean connected;
- bt_headset_wait_t *wait_list;
- guint restricted = 0x0;
-
- __bt_set_device_values(TRUE,
- VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
-
- __bt_connection_manager_set_state(address, event);
-
- _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
-
- if (_bt_headset_get_local_connection() == FALSE) {
- if (restricted == 0x0) /* not restricted*/
- _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
- } else {
- /* Connection Started from local device therefore no need to
- * intiate connection for pending profile */
- _bt_headset_set_local_connection(FALSE);
- }
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_HEADSET_EVENT, event,
- param);
- connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
- connected_address);
- if (connected) {
- if (g_strcmp0(connected_address, address) != 0) {
- _bt_convert_addr_string_to_type(
- device_address.addr,
- connected_address);
- _bt_audio_disconnect(0, BT_AUDIO_A2DP,
- &device_address, NULL);
- }
- }
-
- _bt_add_headset_to_list(BT_AUDIO_A2DP,
- BT_STATE_CONNECTED, address);
-
- wait_list = _bt_get_audio_wait_data();
- if (wait_list != NULL &&
- (g_strcmp0(wait_list->address, address) == 0))
- _bt_rel_wait_data();
-
- } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
-
- int event = BLUETOOTH_EVENT_AV_DISCONNECTED;
-
- if (!_bt_is_service_connected(address, BT_AUDIO_A2DP)) {
- g_free(address);
- g_free(profile_uuid);
- return;
- }
-
- __bt_set_device_values(FALSE,
- VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
-
- __bt_connection_manager_set_state(address, event);
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_HEADSET_EVENT, event,
- param);
- /* Remove data from the connected list */
- _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
- wait_list = _bt_get_audio_wait_data();
-
- if (wait_list == NULL) {
- g_free(address);
- g_free(profile_uuid);
- return;
- }
-
- if (((wait_list->type == BT_AUDIO_ALL) &&
- (wait_list->ag_flag == TRUE)) ||
- (wait_list->type == BT_AUDIO_A2DP) ||
- (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
- bluetooth_device_address_t device_address;
- _bt_convert_addr_string_to_type(
- device_address.addr,
- wait_list->address);
-
- _bt_audio_connect(wait_list->req_id,
- wait_list->type,
- &device_address,
- NULL);
- }
- }
- } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
-
- if (state == BT_PROFILE_STATE_CONNECTED) {
- int event = BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED;
- char connected_address[BT_ADDRESS_STRING_SIZE + 1];
- bluetooth_device_address_t device_address;
- gboolean connected;
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
- param);
- connected = _bt_is_headset_type_connected(
- BT_AVRCP,
- connected_address);
- if (connected) {
- if (g_strcmp0(connected_address,
- address) != 0) {
- _bt_convert_addr_string_to_type(
- device_address.addr,
- connected_address);
- _bt_audio_disconnect(0,
- BT_AVRCP,
- &device_address, NULL);
- }
- }
- BT_DBG("device Path: %s", path);
- _bt_add_headset_to_list(BT_AVRCP,
- BT_STATE_CONNECTED, address);
- } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
- int event = BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED;
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_AVRCP_CONTROL_EVENT, event,
- param);
- /* Remove data from the connected list */
- _bt_remove_headset_from_list(BT_AVRCP, address);
- }
- } else if (strcasecmp(profile_uuid, A2DP_SOURCE_UUID) == 0) {
- if (state == BT_PROFILE_STATE_CONNECTED) {
- int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
- BT_INFO("A2DP Source is connected");
-#ifdef TIZEN_BT_A2DP_SINK_ENABLE
- __bt_set_device_values(TRUE,
- VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
-#endif
-
-#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
- _bt_audio_set_auto_connect_device_addr(address);
- _bt_audio_stop_auto_connect();
-#endif
- _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
- BT_STATE_CONNECTED, address);
- _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
- g_variant_new("(is)", result, address));
- } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
- int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
- BT_INFO("A2DP Source Disconnected");
-#ifdef TIZEN_BT_A2DP_SINK_ENABLE
- __bt_set_device_values(FALSE,
- VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
-#endif
- _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
- _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
- g_variant_new("(is)", result, address));
-
- wait_list = _bt_get_audio_wait_data();
- if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
- bluetooth_device_address_t device_address;
- _bt_convert_addr_string_to_type(
- device_address.addr,
- wait_list->address);
-
- _bt_audio_connect(wait_list->req_id,
- wait_list->type,
- &device_address,
- NULL);
- /* Now free the wait list */
- _bt_rel_wait_data();
- }
- }
- } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
- ((state == BT_PROFILE_STATE_CONNECTED) ||
- (state == BT_PROFILE_STATE_DISCONNECTED))) {
- int event;
- if (state == BT_PROFILE_STATE_CONNECTED)
- event = BLUETOOTH_HID_CONNECTED;
- else
- event = BLUETOOTH_HID_DISCONNECTED;
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_HID_EVENT, event,
- param);
- } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
- if (state == BT_PROFILE_STATE_CONNECTED) {
- int event;
- event = BLUETOOTH_HID_DEVICE_CONNECTED;
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_HID_DEVICE_EVENT, event,
- param);
- } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
- event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_HID_DEVICE_EVENT, event,
- param);
- }
- }
- g_free(address);
- g_free(profile_uuid);
- } else if (strcasecmp(member, "AdvReport") == 0) {
-
- bt_remote_le_dev_info_t *le_dev_info = NULL;
- char *buffer = NULL;
- int buffer_len = 0;
- bt_le_adv_info_t *adv_info = NULL;
- GVariant *value = NULL;
- ret_if(_bt_is_le_scanning() == FALSE);
-
- le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
-
- g_variant_get(msg, "(&syyii@ay)", &le_dev_info->address,
- &le_dev_info->addr_type,
- &le_dev_info->adv_type,
- &le_dev_info->rssi,
- &le_dev_info->adv_data_len,
- &value);
- if (value == NULL) {
- _bt_free_le_device_info(le_dev_info);
- return;
- }
-
- _bt_convert_device_path_to_address(path, le_dev_info->address);
-
- buffer_len = g_variant_get_size(value);
- if (buffer_len > 0)
- buffer = (char *)g_variant_get_data(value);
-
- le_dev_info->adv_data = g_memdup(buffer, buffer_len);
- if (le_dev_info->adv_data == NULL &&
- le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {
- _bt_free_le_device_info(le_dev_info);
- g_variant_unref(value);
- return;
- }
-
- if (_bt_get_le_scan_type() == BT_LE_PASSIVE_SCAN) {
- _bt_send_scan_result_event(le_dev_info, NULL);
- _bt_free_le_device_info(le_dev_info);
- g_variant_unref(value);
- return;
- }
-
- if (le_dev_info->adv_type == BT_LE_ADV_DIRECT_IND ||
- le_dev_info->adv_type == BT_LE_ADV_NONCONN_IND) {
- _bt_send_scan_result_event(le_dev_info, NULL);
- } else if (le_dev_info->adv_type == BT_LE_ADV_IND ||
- le_dev_info->adv_type == BT_LE_ADV_SCAN_IND) {
- adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
- adv_info->addr = g_strdup(le_dev_info->address);
- adv_info->addr_type = le_dev_info->addr_type;
- adv_info->rssi = le_dev_info->rssi;
- adv_info->data_len = le_dev_info->adv_data_len;
- adv_info->data = g_malloc0(le_dev_info->adv_data_len);
- memcpy(adv_info->data, le_dev_info->adv_data,
- le_dev_info->adv_data_len);
-
- if (__bt_add_adv_ind_info(adv_info) == 0) {
- adv_info->timer_id = g_timeout_add(1000,
- (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
- }
- } else { /* SCAN_RSP */
- adv_info = __bt_get_adv_ind_info(le_dev_info->address);
- if (adv_info) {
- _bt_send_scan_result_event(le_dev_info, adv_info);
- __bt_del_adv_ind_info(le_dev_info->address);
- }
- }
- _bt_free_le_device_info(le_dev_info);
- g_variant_unref(value);
- } else if (strcasecmp(member, "LEDataLengthChanged") == 0) {
- guint16 tx_octets = 0;
- guint16 tx_time = 0;
- guint16 rx_octets = 0;
- guint16 rx_time = 0;
-
- g_variant_get(msg, "(qqqq)",
- &tx_octets, &tx_time, &rx_octets, &rx_time);
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- _bt_convert_device_path_to_address(path, address);
-
- param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
- rx_octets, rx_time);
- /* Send event to application */
- _bt_send_event(BT_DEVICE_EVENT,
- BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
- g_free(address);
- } else if (strcasecmp(member, "IpspStateChanged") == 0) {
- gboolean connected = FALSE;
- char *ifname = NULL;
-
- g_variant_get(msg, "(bs)", &connected, &ifname);
-
- event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
- BLUETOOTH_EVENT_IPSP_DISCONNECTED;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
- _bt_convert_device_path_to_address(path, address);
-
- BT_DBG("Ipsp BT Interface Name: %s", ifname);
- BT_DBG("address: %s", address);
- param = g_variant_new("(iss)", result, address, ifname);
-
- /* Send event to application */
- _bt_send_event(BT_DEVICE_EVENT, event, param);
- g_free(address);
- } else if (strcasecmp(member, "AttMtuChanged") == 0) {
- int result = BLUETOOTH_ERROR_NONE;
- guint16 mtu = 0;
- guint8 status = 0;
-
- g_variant_get(msg, "(q)", &mtu);
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
- BT_DBG("Address : %s Server MTU changed : %d", address, mtu);
-
- param = g_variant_new("(isqy)",
- result,
- address,
- mtu,
- status);
-
- /* Send the event to application */
- _bt_send_event(BT_DEVICE_EVENT,
- BLUETOOTH_EVENT_GATT_SERVER_ATT_MTU_CHANGED,
- param);
-
- g_free(address);
- } else if (strcasecmp(member, "iBeaconReport") == 0) {
- bt_remote_ibeacon_dev_info_t *ibeacon_dev_info = NULL;
-
- ret_if(_bt_is_le_scanning() == FALSE);
-
- ibeacon_dev_info = g_malloc0(sizeof(bt_remote_ibeacon_dev_info_t));
-
- g_variant_get(msg, "(syuusuuy)", &ibeacon_dev_info->address,
- &ibeacon_dev_info->addr_type,
- &ibeacon_dev_info->company_id,
- &ibeacon_dev_info->ibeacon_type,
- &ibeacon_dev_info->uuid,
- &ibeacon_dev_info->major_id,
- &ibeacon_dev_info->minor_id,
- &ibeacon_dev_info->measured_power);
- _bt_send_ibeacon_scan_result_event(ibeacon_dev_info);
- g_free(ibeacon_dev_info);
- }
-}
-
-void __bt_set_audio_values(gboolean connected, char *address)
-{
- char *name = NULL;
- int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
-
- /* Set the headset name */
- if (connected == TRUE)
- name = _bt_get_device_name(address);
- else
- name = g_strdup("");
-
- if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0)
- BT_ERR("vconf_set_str failed");
-
- g_free(name);
-
- /* Set the headset state */
- if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
- BT_ERR("vconf_get_int failed");
-
-#ifdef TIZEN_SUPPORT_DUAL_HF
- if ((connected == TRUE) &&
- (FALSE == __bt_is_companion_device(address))) {
- bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
- } else if ((bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) &&
- (FALSE == __bt_is_companion_device(address))) {
- bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
- }
-#else
- if (connected == TRUE)
- bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
- else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED)
- bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
-#endif
-
- if (vconf_set_int(VCONFKEY_BT_DEVICE,
- bt_device_state) != 0) {
- BT_ERR("vconf_set_int failed");
- }
-}
-
-void _bt_handle_headset_event(GVariant *msg, const char *path)
-{
- int result = BLUETOOTH_ERROR_NONE;
- gboolean property_flag = FALSE;
- char *property = NULL;
- GVariant *value = NULL;
- GVariant *param = NULL;
- g_variant_get(msg, "(sv)", &property, &value);
- bluetooth_device_address_t bd_addr;
-
- ret_if(property == NULL);
-
- BT_DBG("Property = %s \n", property);
- /* We allow only 1 headset connection (HSP or HFP)*/
- if (strcasecmp(property, "Connected") == 0) {
- int event = BLUETOOTH_EVENT_NONE;
- bt_headset_wait_t *wait_list;
- char *address;
- guint restricted = 0x0;
- g_variant_get(value, "b", &property_flag);
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
- _bt_convert_addr_string_to_type(bd_addr.addr, address);
-
- if (property_flag == TRUE) {
- event = BLUETOOTH_EVENT_AG_CONNECTED;
- _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
-
- if (_bt_headset_get_local_connection() == FALSE) {
- if (restricted == 0x0) /* not restricted*/
- _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
- } else
- _bt_headset_set_local_connection(FALSE);
- } else {
- int previous_state;
-
- event = BLUETOOTH_EVENT_AG_DISCONNECTED;
-
- previous_state = _bt_get_device_state_from_list(BT_AUDIO_HSP, address);
- if (previous_state == BT_STATE_DISCONNECTING)
- _bt_send_hf_local_term_event(address);
- }
- /* Set the State machine here */
- __bt_connection_manager_set_state(address, event);
- __bt_set_audio_values(property_flag, address);
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_HEADSET_EVENT, event,
- param);
-
- if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
- /* Remove data from the connected list */
- _bt_remove_headset_from_list(BT_AUDIO_HSP, address);
-
- wait_list = _bt_get_audio_wait_data();
- if (wait_list == NULL) {
- g_free(address);
- return;
- }
-
- bluetooth_device_address_t device_address;
-
- _bt_set_audio_wait_data_flag(TRUE);
-
- _bt_convert_addr_string_to_type(device_address.addr,
- wait_list->address);
- _bt_audio_connect(wait_list->req_id, wait_list->type,
- &device_address, NULL);
- _bt_rel_wait_data();
- } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
- /* Add data to the connected list */
- _bt_add_headset_to_list(BT_AUDIO_HSP,
- BT_STATE_CONNECTED, address);
-
- wait_list = _bt_get_audio_wait_data();
- if (wait_list != NULL &&
- (g_strcmp0(wait_list->address, address) == 0))
- _bt_rel_wait_data();
-
- BT_INFO("Check A2DP pending connect");
- _bt_audio_check_pending_connect();
- }
- g_free(address);
- } else if (strcasecmp(property, "State") == 0) {
- char *state = NULL;
-
- g_variant_get(value, "s", &state);
-
- /* This code assumes we support only 1 headset connection */
- /* Need to use the headset list, if we support multi-headsets */
- if (strcasecmp(state, "Playing") == 0) {
- BT_DBG("Playing: Sco Connected");
- } else if (strcasecmp(state, "connected") == 0 ||
- strcasecmp(state, "disconnected") == 0) {
- BT_DBG("connected/disconnected: Sco Disconnected");
- } else {
- BT_ERR("Not handled state - %s", state);
- g_free(state);
- return;
- }
- g_free(state);
- } else if (strcasecmp(property, "SpeakerGain") == 0) {
- guint16 spkr_gain;
- char *address;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- spkr_gain = g_variant_get_uint16(value);
-
- BT_DBG("spkr_gain: %d", spkr_gain);
-
- param = g_variant_new("(i&sq)", result, address, spkr_gain);
- _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
- param);
-
- g_free(address);
- } else if (strcasecmp(property, "MicrophoneGain") == 0) {
- guint16 mic_gain;
- char *address;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- mic_gain = g_variant_get_uint16(value);
-
- param = g_variant_new("(i&sq)", result, address, mic_gain);
- _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
- param);
- g_free(address);
- }
-
- if (property)
- g_free(property);
- g_variant_unref(value);
-}
-
-void _bt_handle_sink_event(GVariant *msg, const char *path)
-{
- GVariantIter value_iter;
- char *property = NULL;
-
- bt_headset_wait_t *wait_list;
-
- GVariant *child = NULL;
- GVariant *val = NULL;
- GVariant *param = NULL;
- g_variant_iter_init(&value_iter, msg);
- while ((child = g_variant_iter_next_value(&value_iter))) {
-
- g_variant_get(child, "{sv}", &property, &val);
-
- ret_if(property == NULL);
-
- BT_DBG("Property = %s \n", property);
-
-
- if (strcasecmp(property, "State") == 0) {
- int result = BLUETOOTH_ERROR_NONE;
- char *value;
-
- g_variant_get(val, "s", &value);
- BT_DBG("value: %s", value);
-
- if (g_strcmp0(value, "disconnected") == 0) {
- char *address;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- __bt_set_device_values(FALSE,
- VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_HEADSET_EVENT,
- BLUETOOTH_EVENT_AV_DISCONNECTED,
- param);
-
- /* Remove data from the connected list */
- _bt_remove_headset_from_list(BT_AUDIO_A2DP, address);
- wait_list = _bt_get_audio_wait_data();
- if (wait_list == NULL) {
- g_free(value);
- g_free(property);
- g_variant_unref(val);
- g_variant_unref(child);
- g_free(address);
- return;
- }
-
- if (((wait_list->type == BT_AUDIO_ALL) &&
- (wait_list->ag_flag == TRUE)) ||
- (wait_list->type == BT_AUDIO_A2DP) ||
- (wait_list->disconnection_type == BT_AUDIO_A2DP)) {
- bluetooth_device_address_t device_address;
- _bt_convert_addr_string_to_type(
- device_address.addr,
- wait_list->address);
-
- _bt_audio_connect(wait_list->req_id,
- wait_list->type,
- &device_address,
- NULL);
- }
- g_free(address);
- } else if (strcasecmp(value, "Connected") == 0) {
- char *address;
- char connected_address[BT_ADDRESS_STRING_SIZE + 1];
- bluetooth_device_address_t device_address;
- gboolean connected;
-
- address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-
- _bt_convert_device_path_to_address(path, address);
-
- __bt_set_device_values(TRUE,
- VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
- param = g_variant_new("(is)", result, address);
- _bt_send_event(BT_HEADSET_EVENT,
- BLUETOOTH_EVENT_AV_CONNECTED,
- param);
- /* Check for existing Media device to disconnect */
- connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
- connected_address);
- if (connected) {
- /* Match connected device address */
- if (g_strcmp0(connected_address, address) != 0) {
- /* Convert BD address from string type */
- _bt_convert_addr_string_to_type(
- device_address.addr,
- connected_address);
- _bt_audio_disconnect(0, BT_AUDIO_A2DP,
- &device_address, NULL);
- }
- }
-
- /* Add data to the connected list */
- _bt_add_headset_to_list(BT_AUDIO_A2DP,
- BT_STATE_CONNECTED, address);
-
- g_free(address);
- }
- g_free(value);
- }
- g_free(property);
- g_variant_unref(val);
- g_variant_unref(child);
- }
-}
-
-void _bt_handle_agent_event(GVariant *msg, const char *member)
-{
- int result = BLUETOOTH_ERROR_NONE;
- char *address = NULL;
- char *name = NULL;
- char *uuid = NULL;
- GVariant *param = NULL;
- ret_if(member == NULL);
-
- if (strcasecmp(member, "ObexAuthorize") == 0) {
- __bt_get_agent_signal_info(msg, &address, &name, &uuid);
- param = g_variant_new("(i&s&s)", result, address, name);
- _bt_send_event(BT_OPP_SERVER_EVENT,
- BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
- param);
- } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
- bt_rfcomm_server_info_t *server_info;
-
- __bt_get_agent_signal_info(msg, &address, &name, &uuid);
-
- server_info = _bt_rfcomm_get_server_info_using_uuid(uuid);
- ret_if(server_info == NULL);
- ret_if(server_info->server_type != BT_CUSTOM_SERVER);
- param = g_variant_new("(i&s&s&sn)", result, address, uuid, name,
- server_info->control_fd);
- _bt_send_event(BT_RFCOMM_SERVER_EVENT,
- BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
- param);
- }
-}
-
-static int __bt_get_object_path(GVariant *msg, char **path)
-{
- g_variant_get(msg, "(o*)", path, NULL);
- if (*path == NULL)
- return BLUETOOTH_ERROR_INTERNAL;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-static void __bt_devices_list_free(void)
-{
- bt_cache_info_t *cache_info;
- GList *node;
-
- node = g_list_first(p_cache_list);
-
- while (node != NULL) {
- cache_info = (bt_cache_info_t *)node->data;
- p_cache_list = g_list_remove(p_cache_list, cache_info);
- __bt_free_cache_info(cache_info);
-
- node = g_list_next(node);
- }
-}
-
-static int __bt_parse_event(GVariant *msg)
-{
- GVariantIter iter;
- GVariant *child;
- char *interface_name = NULL;
- GVariant *inner_iter = NULL;
-
- g_variant_iter_init(&iter, msg);
-
- while ((child = g_variant_iter_next_value(&iter))) {
- g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
- if (g_strcmp0(interface_name,
- BT_DEVICE_INTERFACE) == 0) {
- g_variant_unref(inner_iter);
- g_variant_unref(child);
- return BT_DEVICE_EVENT;
- } else if (g_strcmp0(interface_name,
- BT_MEDIATRANSPORT_INTERFACE) == 0) {
- g_variant_unref(inner_iter);
- g_variant_unref(child);
- return BT_MEDIA_TRANSFER_EVENT;
- } else if (g_strcmp0(interface_name,
- BT_PLAYER_CONTROL_INTERFACE) == 0) {
- g_variant_unref(inner_iter);
- g_variant_unref(child);
- return BT_AVRCP_CONTROL_EVENT;
- }
- g_variant_unref(inner_iter);
- g_variant_unref(child);
- }
-
- return 0;
-}
-
-static void __bt_manager_event_filter(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- bt_event_type_t bt_event = 0x00;
- int result = BLUETOOTH_ERROR_NONE;
- GVariant *value;
- char *obj_path = NULL;
- GVariant *param = NULL;
- if (signal_name == NULL)
- return;
- if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
- g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
-
- if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
-#ifdef USB_BLUETOOTH
- BT_DBG("Enable Adapter");
- _bt_enable_adapter();
-#else
- _bt_handle_adapter_added();
-#endif
- } else {
- bt_event = __bt_parse_event(value);
- if (bt_event == BT_DEVICE_EVENT) {
- bt_cache_info_t *cache_info;
- bt_remote_dev_info_t *dev_info;
-
- if (_bt_is_discovering() == FALSE &&
- _bt_is_le_scanning() == FALSE) {
- g_variant_unref(value);
- return;
- }
-
- cache_info = g_malloc0(sizeof(bt_cache_info_t));
-
- dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
-
- cache_info->dev_info = dev_info;
-
- if (__bt_parse_interface(parameters, dev_info) == FALSE) {
- BT_ERR("Fail to parse the properies");
- __bt_free_cache_info(cache_info);
- g_variant_unref(value);
- return;
- }
-
- if (dev_info->addr_type != BDADDR_BREDR) {
- /* Whenever emit the property changed from bluez,
- some property doesn't reach to bt-service.
- So LE device is handled as AdvReport signal */
- __bt_free_cache_info(cache_info);
- g_variant_unref(value);
- return;
- }
-
- if (dev_info->name == NULL)
- /* If Remote device name is NULL or still RNR is not done
- * then display address as name.
- */
- dev_info->name = g_strdup(dev_info->address);
-
-#ifdef TIZEN_DPM_ENABLE
- if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
- DPM_RESTRICTED) {
- bluetooth_device_class_t device_class;
- _bt_divide_device_class(&device_class, dev_info->class);
- BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
-
- if (device_class.major_class ==
- BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
- __bt_free_cache_info(cache_info);
- g_variant_unref(value);
- return;
- }
- }
-#endif
-
- GVariant *uuids = NULL;
- GVariantBuilder *builder = NULL;
- int i = 0;
- builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
- for (i = 0; i < dev_info->uuid_count; i++) {
- g_variant_builder_add(builder, "s",
- dev_info->uuids[i]);
- }
- uuids = g_variant_new("as", builder);
- g_variant_builder_unref(builder);
- GVariant *manufacturer_data = NULL;
- manufacturer_data = g_variant_new_from_data(
- G_VARIANT_TYPE_BYTESTRING,
- dev_info->manufacturer_data,
- dev_info->manufacturer_data_len,
- TRUE, NULL, NULL);
- param = g_variant_new("(isunsbub@asn@ay)", result,
- dev_info->address,
- dev_info->class,
- dev_info->rssi,
- dev_info->name,
- dev_info->paired,
- dev_info->connected,
- dev_info->trust,
- uuids,
- dev_info->manufacturer_data_len,
- manufacturer_data);
- _bt_send_event(BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
- param);
- p_cache_list = g_list_append(p_cache_list, cache_info);
- } else if (bt_event == BT_AVRCP_CONTROL_EVENT) {
- BT_DBG("Device path : %s ", obj_path);
- _bt_set_control_device_path(obj_path);
- }
- }
- g_variant_unref(value);
- } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
-#ifdef USB_BLUETOOTH
- BT_DBG("InterfacesRemoved");
- _bt_handle_adapter_removed();
-#endif
- if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0)
- bt_event = BT_MEDIA_TRANSFER_EVENT;
- else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0)
- bt_event = BT_DEVICE_EVENT;
- else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0)
- bt_event = BT_AVRCP_CONTROL_EVENT;
-
- if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
- _bt_handle_adapter_event(parameters, signal_name);
- if (bt_event == BT_AVRCP_CONTROL_EVENT) {
- BT_INFO("Object Path %s", obj_path);
- _bt_remove_control_device_path(obj_path);
- }
- }
- } else if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
- gboolean value;
- char *name = NULL;
- char *previous = NULL;
- char *current = NULL;
-
- if (g_strcmp0(g_variant_get_type_string(parameters), "(sss)") != 0) {
- BT_ERR("Invalid variant format");
- return;
- }
-
- if (__bt_get_owner_info(parameters, &name, &previous, ¤t)) {
- BT_ERR("Fail to get the owner info");
- return;
- }
-
- if (*current != '\0')
- return;
-
- if (name == NULL)
- return;
-
- if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
- BT_INFO_C("### Bluetoothd is terminated");
- if (_bt_adapter_get_status() == BT_ACTIVATED)
- _bt_disable_cb();
-
- _bt_handle_adapter_removed();
- __bt_devices_list_free();
- _bt_service_adapter_le_deinit();
- }
-
- _bt_obex_server_check_allocation(&value);
-
- if (value == TRUE) {
- /* Check if the obex server was terminated abnormally */
- _bt_obex_server_check_termination(name);
- }
-
- _bt_rfcomm_server_check_existence(&value);
-
- if (value == TRUE) {
- /* The obex server was terminated abnormally */
- _bt_rfcomm_server_check_termination(name);
- }
-
- /* Reset connection interval */
- _bt_remove_all_le_conn_param_info(name);
-
- /* Stop advertising started by terminated process */
- _bt_stop_advertising_by_terminated_process(name);
-
- /* Stop LE Scan */
- _bt_stop_le_scan(name);
- } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
- const char *path = object_path;
-
- if (strncmp(path, BT_MEDIA_OBJECT_PATH,
- strlen(BT_MEDIA_OBJECT_PATH)) == 0)
- return;
-
- _bt_handle_property_changed_event(parameters, object_path);
- } else if (g_strcmp0(interface_name, BT_ADAPTER_INTERFACE) == 0) {
- _bt_handle_adapter_event(parameters, signal_name);
- } else if (g_strcmp0(interface_name, BT_INPUT_INTERFACE) == 0) {
- _bt_handle_input_event(parameters, object_path);
- } else if (g_strcmp0(interface_name, BT_NETWORK_SERVER_INTERFACE) == 0) {
- _bt_handle_network_server_event(parameters, signal_name);
- } else if (g_strcmp0(interface_name, BT_HEADSET_INTERFACE) == 0) {
- if (g_strcmp0(signal_name, "PropertyChanged") == 0) {
- _bt_handle_headset_event(parameters, object_path);
- }
- } else if (g_strcmp0(interface_name, BT_SINK_INTERFACE) == 0) {
- _bt_handle_sink_event(parameters, object_path);
- } else if (g_strcmp0(interface_name, BT_AGENT_INTERFACE) == 0) {
- _bt_handle_agent_event(parameters, signal_name);
- } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
- _bt_handle_device_event(parameters, signal_name, object_path);
- } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
- _bt_handle_gatt_event(parameters, signal_name, object_path);
- }
-
- return;
-}
-
-static gboolean __bt_is_obexd_event(GVariant *msg, const char *interface)
-{
-
- if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
- char *interface_name = NULL;
-
- g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
- retv_if(interface_name == NULL, FALSE);
-
- if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
- BT_DBG("BT_OBEX_TRANSFER_INTERFACE");
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-static void __bt_obexd_event_filter(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- const char *member = signal_name;
- char *obj_path = NULL;
- ret_if(member == NULL);
-
- if (strcasecmp(member, "InterfacesAdded") == 0) {
- if (__bt_get_object_path(parameters, &obj_path)) {
- BT_ERR("Fail to get the path");
- return;
- }
- BT_DBG("object_path = [%s]", obj_path);
-
- /*Handle OPP_SERVER_CONNECTED_EVENT here */
- if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
- strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
- g_free(obj_path);
- return;
- }
-
- if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
- BT_DBG("Obex_Server_Session_Transfer connected");
- _bt_obex_transfer_connected(obj_path);
- }
- g_free(obj_path);
- } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
- /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
- if (__bt_get_object_path(parameters, &obj_path)) {
- BT_ERR("Fail to get the path");
- return;
- }
- BT_DBG("object_path = [%s]", obj_path);
-
- if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
- strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
- BT_DBG("Call PBAP Disconnected");
- _bt_obex_pbap_client_disconnect(obj_path);
- }
-
- if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
- strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
- g_free(obj_path);
- return;
- }
-
- if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
- BT_DBG("Obex_Server_Session_Transfer disconnected %s",
- obj_path);
-
- _bt_obex_transfer_disconnected(obj_path);
- }
- g_free(obj_path);
- } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
- const char *path = object_path;
-
- if (strncmp(path, BT_SESSION_BASEPATH_SERVER,
- strlen(BT_SESSION_BASEPATH_SERVER)) != 0 &&
- strncmp(path, BT_SESSION_BASEPATH_CLIENT,
- strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
- BT_DBG("DBUS_HANDLER_RESULT_NOT_YET_HANDLED");
- return;
- }
-
- _bt_handle_property_changed_event(parameters, path);
- }
- BT_DBG("-");
- return;
-}
-
-static gboolean __bt_is_obexd_client_event(GVariant *msg, const char *interface)
-{
- BT_DBG("+");
-
- if (g_strcmp0(interface, BT_PROPERTIES_INTERFACE) == 0) {
- char *interface_name = NULL;
-
- g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, NULL, NULL);
-
- retv_if(interface_name == NULL, FALSE);
-
- if (strcasecmp(interface_name,
- BT_OBEX_TRANSFER_INTERFACE) == 0) {
- BT_DBG("-");
- return TRUE;
- }
- }
-
- BT_DBG("-");
-
- return FALSE;
-}
-
-static void __bt_opc_event_filter(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- const char *member = signal_name;
- char *obj_path = NULL;
- if (strcasecmp(member, "InterfacesAdded") == 0) {
- BT_DBG("InterfacesAdded");
- } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
-
- if (__bt_get_object_path(parameters, &obj_path)) {
- BT_ERR("Fail to get the path");
- return;
- }
-
- BT_DBG("object_path = %s", obj_path);
-
- if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
- strlen(BT_SESSION_BASEPATH_CLIENT)) != 0
- || strstr(obj_path, "transfer") == NULL) {
- g_free(obj_path);
- return;
- } else if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
- strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
- BT_DBG("Going to call opc disconnected");
- _bt_opc_disconnected(obj_path);
- }
-
- _bt_sending_files();
- g_free(obj_path);
- } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
- char *path = (char *)object_path;
- BT_INFO("object_path %s", path);
- if (strncmp(path, BT_SESSION_BASEPATH_CLIENT,
- strlen(BT_SESSION_BASEPATH_CLIENT)) != 0) {
- BT_DBG("NOT BT_SESSION_BASEPATH_CLIENT");
- return;
- }
-
- _bt_opc_property_changed_event(parameters, path);
- }
-
- return;
-}
-
-int _bt_opp_client_event_init(void)
-{
- GError *error = NULL;
-
- if (opc_obexd_conn == NULL) {
- opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
-
- if (!opc_obexd_conn) {
- if (error) {
- BT_ERR("Unable to connect to dbus: %s", error->message);
- g_clear_error(&error);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
- }
-
- if (_bt_register_service_event(opc_obexd_conn,
- BT_OPP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
- g_object_unref(opc_obexd_conn);
- opc_obexd_conn = NULL;
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_opp_client_event_deinit(void)
-{
- if (opc_obexd_conn) {
- _bt_unregister_service_event(opc_obexd_conn,
- BT_OPP_CLIENT_EVENT);
- g_object_unref(opc_obexd_conn);
- opc_obexd_conn = NULL;
- }
-}
-
-int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
- int subscribe)
-{
- if (conn == NULL)
- return -1;
-
- static int subs_interface_added_id = -1;
- static int subs_interface_removed_id = -1;
- static int subs_name_owner_id = -1;
- static int subs_property_id = -1;
- static int subs_adapter_id = -1;
- static int subs_gatt_id = -1;
-
- if (subscribe) {
- if (subs_interface_added_id == -1) {
- subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_MANAGER_INTERFACE,
- BT_INTERFACES_ADDED, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- if (subs_interface_removed_id == -1) {
- subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_MANAGER_INTERFACE,
- BT_INTERFACES_REMOVED, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- if (subs_name_owner_id == -1) {
- subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_FREEDESKTOP_INTERFACE,
- BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- if (subs_property_id == -1) {
- subs_property_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_PROPERTIES_INTERFACE,
- BT_PROPERTIES_CHANGED, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- if (subs_adapter_id == -1) {
- subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_ADAPTER_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- if (subs_gatt_id == -1) {
- subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_GATT_CHAR_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- } else {
- if (subs_interface_added_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_interface_added_id);
- subs_interface_added_id = -1;
- }
- if (subs_interface_removed_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_interface_removed_id);
- subs_interface_removed_id = -1;
- }
- if (subs_name_owner_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_name_owner_id);
- subs_name_owner_id = -1;
- }
- if (subs_property_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_property_id);
- subs_property_id = -1;
- }
- if (subs_adapter_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
- subs_adapter_id = -1;
- }
- if (subs_gatt_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
- subs_gatt_id = -1;
- }
- }
- return 0;
-}
-
-int _bt_register_device_subscribe_signal(GDBusConnection *conn,
- int subscribe)
-{
- if (conn == NULL)
- return -1;
-
- static int subs_device_id = -1;
-
- if (subscribe) {
- if (subs_device_id == -1) {
- subs_device_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_DEVICE_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- } else {
- if (subs_device_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_device_id);
- subs_device_id = -1;
- }
- }
- return 0;
-}
-
-int _bt_register_input_subscribe_signal(GDBusConnection *conn,
- int subscribe)
-{
- if (conn == NULL)
- return -1;
-
- static int subs_input_id = -1;
-
- if (subscribe) {
- if (subs_input_id == -1) {
- subs_input_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_INPUT_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- } else {
- if (subs_input_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_input_id);
- subs_input_id = -1;
- }
- }
- return 0;
-}
-
-int _bt_register_network_subscribe_signal(GDBusConnection *conn,
- int subscribe)
-{
- if (conn == NULL)
- return -1;
-
- static int subs_serv_id = -1;
- static int subs_client_id = -1;
-
- if (subscribe) {
- if (subs_serv_id == -1) {
- subs_serv_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_NETWORK_SERVER_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- if (subs_client_id == -1) {
- subs_client_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_NETWORK_CLIENT_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- } else {
- if (subs_serv_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_serv_id);
- subs_serv_id = -1;
- }
- if (subs_client_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_client_id);
- subs_client_id = -1;
- }
- }
- return 0;
-}
-
-int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
- int subscribe)
-{
- if (conn == NULL)
- return -1;
-
- static int subs_headset_id = -1;
- static int subs_sink_id = -1;
-
- if (subscribe) {
- if (subs_headset_id == -1) {
- subs_headset_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_HEADSET_INTERFACE,
- "PropertyChanged", NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- if (subs_sink_id == -1) {
- subs_sink_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_SINK_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_manager_event_filter,
- NULL, NULL);
- }
- } else {
- if (subs_headset_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_headset_id);
- subs_headset_id = -1;
- }
- if (subs_sink_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_sink_id);
- subs_sink_id = -1;
- }
- }
- return 0;
-}
-
-int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
- int subscribe)
-{
- if (conn == NULL)
- return -1;
-
- static int subs_opp_server_interface_added_id = -1;
- static int subs_opp_server_interface_removed_id = -1;
- static int subs_opp_server_property_id = -1;
-
-
- if (subscribe) {
- if (subs_opp_server_interface_added_id == -1) {
- subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_MANAGER_INTERFACE,
- BT_INTERFACES_ADDED, NULL, NULL, 0,
- __bt_obexd_event_filter,
- NULL, NULL);
- }
- if (subs_opp_server_interface_removed_id == -1) {
- subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_MANAGER_INTERFACE,
- BT_INTERFACES_REMOVED, NULL, NULL, 0,
- __bt_obexd_event_filter,
- NULL, NULL);
- }
- if (subs_opp_server_property_id == -1) {
- subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_PROPERTIES_INTERFACE,
- BT_PROPERTIES_CHANGED, NULL, NULL, 0,
- __bt_obexd_event_filter,
- NULL, NULL);
- }
- } else {
- if (subs_opp_server_interface_added_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_opp_server_interface_added_id);
- subs_opp_server_interface_added_id = -1;
- }
- if (subs_opp_server_interface_removed_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_opp_server_interface_removed_id);
- subs_opp_server_interface_removed_id = -1;
- }
- if (subs_opp_server_property_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_opp_server_property_id);
- subs_opp_server_property_id = -1;
- }
- }
- return 0;
-}
-
-int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
- int subscribe)
-{
- if (conn == NULL)
- return -1;
-
- static int subs_opp_client_interface_added_id = -1;
- static int subs_opp_client_interface_removed_id = -1;
- static int subs_opp_client_property_id = -1;
-
-
- if (subscribe) {
- if (subs_opp_client_interface_added_id == -1) {
- subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_MANAGER_INTERFACE,
- BT_INTERFACES_ADDED, NULL, NULL, 0,
- __bt_opc_event_filter,
- NULL, NULL);
- }
- if (subs_opp_client_interface_removed_id == -1) {
- subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_MANAGER_INTERFACE,
- BT_INTERFACES_REMOVED, NULL, NULL, 0,
- __bt_opc_event_filter,
- NULL, NULL);
- }
- if (subs_opp_client_property_id == -1) {
- subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_PROPERTIES_INTERFACE,
- BT_PROPERTIES_CHANGED, NULL, NULL, 0,
- __bt_opc_event_filter,
- NULL, NULL);
- }
- } else {
- if (subs_opp_client_interface_added_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_opp_client_interface_added_id);
- subs_opp_client_interface_added_id = -1;
- }
- if (subs_opp_client_interface_removed_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_opp_client_interface_removed_id);
- subs_opp_client_interface_removed_id = -1;
- }
- if (subs_opp_client_property_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_opp_client_property_id);
- subs_opp_client_property_id = -1;
- }
- }
- return 0;
-}
-
-int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
- int subscribe)
-{
- if (conn == NULL)
- return -1;
-
- static int subs_a2dp_source_id = -1;
- static int subs_a2dp_sink_id = -1;
-
- if (subscribe) {
- if (subs_a2dp_source_id == -1) {
- subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_A2DP_SOURCE_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_opc_event_filter,
- NULL, NULL);
- }
- if (subs_a2dp_sink_id == -1) {
- subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_SINK_INTERFACE,
- NULL, NULL, NULL, 0,
- __bt_opc_event_filter,
- NULL, NULL);
- }
- } else {
- if (subs_a2dp_source_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_a2dp_source_id);
- subs_a2dp_source_id = -1;
- }
- if (subs_a2dp_sink_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_a2dp_sink_id);
- subs_a2dp_sink_id = -1;
- }
- }
- return 0;
-}
-
-static void __bt_dump_event_filter(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- return;
-}
-
-int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
- gboolean subscribe)
-{
- if (conn == NULL)
- return -1;
-
- static int subs_source_id = -1;
-
- if (subscribe) {
- if (subs_source_id == -1) {
- subs_source_id = g_dbus_connection_signal_subscribe(conn,
- NULL, BT_DUMP_SERVICE_INTERFACE,
- BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
- __bt_dump_event_filter,
- NULL, NULL);
- }
- } else {
- if (subs_source_id != -1) {
- g_dbus_connection_signal_unsubscribe(conn,
- subs_source_id);
- subs_source_id = -1;
- }
- }
- return 0;
-}
-
-int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
-{
- BT_DBG("+");
-
- retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- switch (event_type) {
- case BT_MANAGER_EVENT:
- _bt_register_manager_subscribe_signal(g_conn, TRUE);
- break;
- case BT_DEVICE_EVENT:
- _bt_register_device_subscribe_signal(g_conn, TRUE);
- break;
- case BT_HID_EVENT:
- _bt_register_input_subscribe_signal(g_conn, TRUE);
- break;
- case BT_NETWORK_EVENT:
- _bt_register_network_subscribe_signal(g_conn, TRUE);
- break;
- case BT_HEADSET_EVENT:
- _bt_register_audio_subscribe_signal(g_conn, TRUE);
- break;
-
- case BT_OPP_SERVER_EVENT:
- BT_ERR("BT_OPP_SERVER_EVENT: register service event");
- _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
- break;
- case BT_OPP_CLIENT_EVENT:
- BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
- _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
- break;
- case BT_A2DP_SOURCE_EVENT:
- BT_INFO("A2dp Source event");
- _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
- break;
- default:
- BT_ERR("Unknown event");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
-{
- BT_DBG("+");
-
- ret_if(g_conn == NULL);
-
- switch (event_type) {
- case BT_MANAGER_EVENT:
- _bt_register_manager_subscribe_signal(g_conn, FALSE);
- _bt_register_device_subscribe_signal(g_conn, FALSE);
- _bt_register_input_subscribe_signal(g_conn, FALSE);
- _bt_register_network_subscribe_signal(g_conn, FALSE);
- _bt_register_audio_subscribe_signal(g_conn, FALSE);
- break;
- case BT_OPP_SERVER_EVENT:
- _bt_register_opp_server_subscribe_signal(g_conn, FALSE);
- break;
- case BT_OPP_CLIENT_EVENT:
- _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
- break;
- default:
- BT_ERR("Unknown event");
- return;
- }
-
- BT_DBG("-");
-}
-
-static int __bt_init_manager_receiver(void)
-{
- BT_DBG("+");
-
- GError *error = NULL;
-
- if (manager_conn == NULL) {
- manager_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (error != NULL) {
- BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
- g_clear_error(&error);
- }
- retv_if(manager_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
- }
-
- if (_bt_register_service_event(manager_conn,
- BT_MANAGER_EVENT) != BLUETOOTH_ERROR_NONE)
- goto fail;
- if (_bt_register_service_event(manager_conn,
- BT_DEVICE_EVENT) != BLUETOOTH_ERROR_NONE)
- goto fail;
-
- if (_bt_register_service_event(manager_conn,
- BT_HID_EVENT) != BLUETOOTH_ERROR_NONE)
- goto fail;
-
- if (_bt_register_service_event(manager_conn,
- BT_HEADSET_EVENT) != BLUETOOTH_ERROR_NONE)
- goto fail;
-
- if (_bt_register_service_event(manager_conn,
- BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
- goto fail;
-
- __bt_register_dump_subscribe_signal(manager_conn, TRUE);
- return BLUETOOTH_ERROR_NONE;
-fail:
- if (manager_conn) {
- g_object_unref(manager_conn);
- manager_conn = NULL;
- }
-
- BT_DBG("-");
-
- return BLUETOOTH_ERROR_INTERNAL;
-}
-
-static int __bt_init_obexd_receiver(void)
-{
- BT_DBG("+");
-#ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
- GError *error = NULL;
-
- if (obexd_conn == NULL) {
- obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
- if (error != NULL) {
- BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
- g_clear_error(&error);
- }
- retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
- }
-
- if (_bt_register_service_event(obexd_conn,
- BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Error while registering service event");
- g_object_unref(obexd_conn);
- obexd_conn = NULL;
- return BLUETOOTH_ERROR_INTERNAL;
- }
-#endif
- BT_DBG("-");
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-gboolean __bt_reinit_obexd_receiver(gpointer user_data)
-{
- static int retry_cnt = 0;
- int result = BLUETOOTH_ERROR_NONE;
-
- BT_DBG("+");
-
- result = __bt_init_obexd_receiver();
- if (result != BLUETOOTH_ERROR_NONE) {
- /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
- then it is not the timing issue. Just can't use the session bus connection */
- if (retry_cnt > 100) {
- BT_ERR("Fail to init obexd receiver by 50 times.");
- retry_cnt = 0;
- session_reinit_timer = 0;
- return FALSE;
- }
- retry_cnt++;
- BT_DBG("Retry to initialize the obexd receiver");
- return TRUE;
- }
-
- retry_cnt = 0;
- session_reinit_timer = 0;
-
- BT_DBG("-");
-
- return FALSE;
-}
-
-/* To receive the event from bluez */
-int _bt_init_service_event_receiver(void)
-{
- BT_DBG("+");
-
- int result;
-
- result = __bt_init_manager_receiver();
- retv_if(result != BLUETOOTH_ERROR_NONE, result);
-
- result = __bt_init_obexd_receiver();
- if (result != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Fail to init obexd receiver");
-
- /* Try to re-initialize obexd receiver in the timer */
- if (session_reinit_timer > 0)
- g_source_remove(session_reinit_timer);
-
- session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
- (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
- }
-
- BT_DBG("-");
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_deinit_service_event_receiver(void)
-{
- BT_DBG("+");
-
- _bt_unregister_service_event(manager_conn, BT_MANAGER_EVENT);
-
- _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
-
- __bt_register_dump_subscribe_signal(manager_conn, FALSE);
-
- if (manager_conn) {
- g_object_unref(manager_conn);
- manager_conn = NULL;
- }
-
- if (obexd_conn) {
- g_object_unref(obexd_conn);
- obexd_conn = NULL;
- }
-
- if (event_id > 0)
- g_source_remove(event_id);
- event_id = 0;
-
- BT_DBG("-");
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <dlog.h>
-#include <gio/gio.h>
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-
-static GDBusConnection *event_conn;
-static GDBusConnection *hf_local_term_event_conn;
-
-#ifdef HPS_FEATURE
-int _bt_send_to_hps(void)
-{
- gboolean ret = FALSE;
- GError *error = NULL;
-
- BT_DBG(" ");
-
- retv_if(event_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- ret = g_dbus_connection_emit_signal(event_conn, NULL,
- "/org/projectx/httpproxy",
- "org.projectx.httpproxy_service",
- BT_LE_ENABLED,
- NULL, &error);
- if (!ret) {
- if (error != NULL) {
- BT_ERR("D-Bus API failure: errCode[%x], \
- message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-#endif
-
-int _bt_send_event(int event_type, int event, GVariant *param)
-{
- char *path;
- char *signal;
- GDBusMessage *msg1 = NULL;
-
- retv_if(event_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- BT_DBG("event_type [%d], event [%d]", event_type, event);
-
- switch (event_type) {
- case BT_ADAPTER_EVENT:
- path = BT_ADAPTER_PATH;
- break;
- case BT_LE_ADAPTER_EVENT:
- path = BT_LE_ADAPTER_PATH;
- break;
- case BT_DEVICE_EVENT:
- path = BT_DEVICE_PATH;
- break;
- case BT_HID_EVENT:
- path = BT_HID_PATH;
- break;
- case BT_HID_DEVICE_EVENT:
- path = BT_HID_DEVICE_PATH;
- break;
- case BT_HEADSET_EVENT:
- path = BT_HEADSET_PATH;
- break;
- case BT_AVRCP_EVENT:
- path = BT_AVRCP_PATH;
- break;
- case BT_AVRCP_CONTROL_EVENT:
- path = BT_AVRCP_CONTROL_PATH;
- break;
- case BT_NETWORK_EVENT:
- path = BT_NETWORK_PATH;
- break;
- case BT_OPP_CLIENT_EVENT:
- path = BT_OPP_CLIENT_PATH;
- break;
- case BT_OPP_SERVER_EVENT:
- path = BT_OPP_SERVER_PATH;
- break;
- case BT_PBAP_CLIENT_EVENT:
- path = BT_PBAP_CLIENT_PATH;
- break;
- case BT_RFCOMM_CLIENT_EVENT:
- path = BT_RFCOMM_CLIENT_PATH;
- break;
- case BT_RFCOMM_SERVER_EVENT:
- path = BT_RFCOMM_SERVER_PATH;
- break;
- case BT_A2DP_SOURCE_EVENT:
- path = BT_A2DP_SOURCE_PATH;
- break;
- default:
- BT_ERR("Unknown event");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- switch (event) {
- case BLUETOOTH_EVENT_ENABLED:
- signal = BT_ENABLED;
- BT_INFO_C("### BT Enabled");
- break;
- case BLUETOOTH_EVENT_DISABLED:
- signal = BT_DISABLED;
- BT_INFO_C("### BT Disabled");
- break;
- case BLUETOOTH_EVENT_LE_ENABLED:
- signal = BT_LE_ENABLED;
- break;
- case BLUETOOTH_EVENT_LE_DISABLED:
- signal = BT_LE_DISABLED;
- break;
- case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:
- signal = BT_ADAPTER_NAME_CHANGED;
- break;
- case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED:
- signal = BT_DISCOVERABLE_MODE_CHANGED;
- break;
- case BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED:
- signal = BT_DISCOVERABLE_TIMEOUT_CHANGED;
- break;
- case BLUETOOTH_EVENT_CONNECTABLE_CHANGED:
- signal = BT_CONNECTABLE_CHANGED;
- break;
- case BLUETOOTH_EVENT_DISCOVERY_STARTED:
- signal = BT_DISCOVERY_STARTED;
- break;
- case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:
- signal = BT_DEVICE_FOUND;
- break;
- case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
- signal = BT_DISCOVERY_FINISHED;
- break;
- case BLUETOOTH_EVENT_LE_DISCOVERY_STARTED:
- signal = BT_LE_DISCOVERY_STARTED;
- break;
- case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND:
- signal = BT_LE_DEVICE_FOUND;
- break;
- case BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED:
- signal = BT_LE_DISCOVERY_FINISHED;
- break;
- case BLUETOOTH_EVENT_ADVERTISING_STARTED:
- signal = BT_ADVERTISING_STARTED;
- break;
- case BLUETOOTH_EVENT_ADVERTISING_STOPPED:
- signal = BT_ADVERTISING_STOPPED;
- break;
- case BLUETOOTH_EVENT_ADVERTISING_MANUFACTURER_DATA_CHANGED:
- signal = BT_ADVERTISING_MANUFACTURER_DATA_CHANGED;
- break;
- case BLUETOOTH_EVENT_SCAN_RESPONSE_MANUFACTURER_DATA_CHANGED:
- signal = BT_SCAN_RESPONSE_MANUFACTURER_DATA_CHANGED;
- break;
- case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED:
- signal = BT_MANUFACTURER_DATA_CHANGED;
- break;
- case BLUETOOTH_EVENT_BONDING_FINISHED:
- signal = BT_BOND_CREATED;
- break;
- case BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED:
- signal = BT_BOND_DESTROYED;
- break;
- case BLUETOOTH_EVENT_DEVICE_AUTHORIZED:
- signal = BT_DEVICE_AUTHORIZED;
- break;
- case BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED:
- signal = BT_DEVICE_UNAUTHORIZED;
- break;
- case BLUETOOTH_EVENT_RSSI_ENABLED:
- signal = BT_RSSI_MONITORING_ENABLED;
- break;
- case BLUETOOTH_EVENT_RSSI_ALERT:
- signal = BT_RSSI_ALERT;
- break;
- case BLUETOOTH_EVENT_RAW_RSSI:
- signal = BT_RAW_RSSI_EVENT;
- break;
- case BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED:
- signal = BT_SUPPORTED_PROFILE_TRUSTED;
- break;
- case BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY:
- signal = BT_KBD_PASSKEY_DISPLAY_REQ_RECEIVED;
- break;
- case BLUETOOTH_EVENT_PIN_REQUEST:
- signal = BT_PIN_REQ_RECEIVED;
- break;
- case BLUETOOTH_EVENT_PASSKEY_REQUEST:
- signal = BT_PASSKEY_REQ_RECEIVED;
- break;
- case BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST:
- signal = BT_PASSKEY_CFM_REQ_RECEIVED;
- break;
- case BLUETOOTH_EVENT_SERVICE_SEARCHED:
- signal = BT_SERVICE_SEARCHED;
- break;
- case BLUETOOTH_HID_CONNECTED:
- signal = BT_INPUT_CONNECTED;
- BT_INFO_C("### Connected [HID]");
- break;
- case BLUETOOTH_HID_DISCONNECTED:
- signal = BT_INPUT_DISCONNECTED;
- BT_INFO_C("### Disconnected [HID]");
- break;
- case BLUETOOTH_HID_DEVICE_CONNECTED:
- signal = BT_INPUT_HID_DEVICE_CONNECTED;
- BT_INFO_C("### Connected [HID Device]");
- break;
- case BLUETOOTH_HID_DEVICE_DISCONNECTED:
- signal = BT_INPUT_HID_DEVICE_DISCONNECTED;
- BT_INFO_C("### Disconnected [HID Device]");
- break;
- case BLUETOOTH_PBAP_CONNECTED:
- signal = BT_PBAP_CONNECTED;
- BT_INFO_C("### Connected [PBAP Client]");
- break;
- case BLUETOOTH_PBAP_DISCONNECTED:
- signal = BT_PBAP_DISCONNECTED;
- BT_INFO_C("### Disconnected [PBAP Client]");
- break;
- case BLUETOOTH_PBAP_PHONEBOOK_SIZE:
- signal = BT_PBAP_PHONEBOOK_SIZE;
- break;
- case BLUETOOTH_PBAP_PHONEBOOK_PULL:
- signal = BT_PBAP_PHONEBOOK_PULL;
- break;
- case BLUETOOTH_PBAP_VCARD_LIST:
- signal = BT_PBAP_VCARD_LIST;
- break;
- case BLUETOOTH_PBAP_VCARD_PULL:
- signal = BT_PBAP_VCARD_PULL;
- break;
- case BLUETOOTH_PBAP_PHONEBOOK_SEARCH:
- signal = BT_PBAP_SEARCH_PHONEBOOK;
- break;
- case BLUETOOTH_EVENT_AG_CONNECTED:
- signal = BT_HEADSET_CONNECTED;
- BT_INFO_C("Connected [HSP/HFP]");
- break;
- case BLUETOOTH_EVENT_AG_DISCONNECTED:
- signal = BT_HEADSET_DISCONNECTED;
- BT_INFO_C("Disconnected [HSP/HFP]");
- break;
- case BLUETOOTH_EVENT_AV_CONNECTED:
- signal = BT_STEREO_HEADSET_CONNECTED;
- BT_INFO_C("### Connected [A2DP]");
- break;
- case BLUETOOTH_EVENT_AV_DISCONNECTED:
- signal = BT_STEREO_HEADSET_DISCONNECTED;
- BT_INFO_C("### Disconnected [A2DP]");
- break;
- case BLUETOOTH_EVENT_AV_SOURCE_CONNECTED:
- signal = BT_A2DP_SOURCE_CONNECTED;
- BT_INFO_C("### Connected [A2DP Source]");
- break;
- case BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED:
- signal = BT_A2DP_SOURCE_DISCONNECTED;
- BT_INFO_C("### Disconnected [A2DP Source]");
- break;
- case BLUETOOTH_EVENT_AG_AUDIO_CONNECTED:
- signal = BT_SCO_CONNECTED;
- BT_INFO_C("Connected [SCO]");
- break;
- case BLUETOOTH_EVENT_AG_AUDIO_DISCONNECTED:
- signal = BT_SCO_DISCONNECTED;
- BT_INFO_C("Disonnected [SCO]");
- break;
- case BLUETOOTH_EVENT_AG_SPEAKER_GAIN:
- signal = BT_SPEAKER_GAIN;
- break;
- case BLUETOOTH_EVENT_AG_MIC_GAIN:
- signal = BT_MICROPHONE_GAIN;
- break;
- case BLUETOOTH_EVENT_NETWORK_CONNECTED:
- signal = BT_NETWORK_CONNECTED;
- BT_INFO_C("Connected [Newwork]");
- break;
- case BLUETOOTH_EVENT_NETWORK_DISCONNECTED:
- signal = BT_NETWORK_DISCONNECTED;
- BT_INFO_C("Disconnected [Newwork]");
- break;
- case BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED:
- signal = BT_NETWORK_SERVER_CONNECTED;
- BT_INFO_C("Connected [Network Server]");
- break;
- case BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED:
- signal = BT_NETWORK_SERVER_DISCONNECTED;
- BT_INFO_C("Disconnected [Network Server]");
- break;
- case BLUETOOTH_EVENT_OPC_CONNECTED:
- signal = BT_OPP_CONNECTED;
- BT_INFO_C("Connected [OPP]");
- break;
- case BLUETOOTH_EVENT_OPC_DISCONNECTED:
- signal = BT_OPP_DISCONNECTED;
- BT_INFO_C("Disconnected [OPP]");
- break;
- case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED:
- signal = BT_TRANSFER_CONNECTED;
- break;
- case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_DISCONNECTED:
- signal = BT_TRANSFER_DISCONNECTED;
- break;
- case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED:
- case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED:
- signal = BT_TRANSFER_STARTED;
- break;
- case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS:
- case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS:
- signal = BT_TRANSFER_PROGRESS;
- break;
- case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE:
- case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED:
- signal = BT_TRANSFER_COMPLETED;
- break;
- case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE:
- signal = BT_TRANSFER_AUTHORIZED;
- break;
- case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE:
- case BLUETOOTH_EVENT_RFCOMM_AUTHORIZE:
- signal = BT_CONNECTION_AUTHORIZED;
- break;
- case BLUETOOTH_EVENT_RFCOMM_CONNECTED:
- signal = BT_RFCOMM_CONNECTED;
- break;
- case BLUETOOTH_EVENT_RFCOMM_DISCONNECTED:
- signal = BT_RFCOMM_DISCONNECTED;
- break;
- case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED:
- signal = BT_RFCOMM_DATA_RECEIVED;
- break;
- case BLUETOOTH_EVENT_RFCOMM_SERVER_REMOVED:
- signal = BT_RFCOMM_SERVER_REMOVED;
- break;
- case BLUETOOTH_EVENT_DEVICE_CONNECTED:
- signal = BT_DEVICE_CONNECTED;
- break;
- case BLUETOOTH_EVENT_DEVICE_DISCONNECTED:
- signal = BT_DEVICE_DISCONNECTED;
- break;
- case BLUETOOTH_EVENT_AVRCP_CONNECTED:
- case BLUETOOTH_EVENT_AVRCP_CONTROL_CONNECTED:
- signal = BT_AVRCP_CONNECTED;
- BT_INFO_C("Connected [AVRCP]");
- break;
- case BLUETOOTH_EVENT_AVRCP_DISCONNECTED:
- case BLUETOOTH_EVENT_AVRCP_CONTROL_DISCONNECTED:
- signal = BT_AVRCP_DISCONNECTED;
- BT_INFO_C("Disconnected [AVRCP]");
- break;
- case BLUETOOTH_EVENT_AVRCP_SETTING_SHUFFLE_STATUS:
- case BLUETOOTH_EVENT_AVRCP_CONTROL_SHUFFLE_STATUS:
- signal = BT_MEDIA_SHUFFLE_STATUS;
- break;
- case BLUETOOTH_EVENT_AVRCP_SETTING_EQUALIZER_STATUS:
- case BLUETOOTH_EVENT_AVRCP_CONTROL_EQUALIZER_STATUS:
- signal = BT_MEDIA_EQUALIZER_STATUS;
- break;
- case BLUETOOTH_EVENT_AVRCP_SETTING_REPEAT_STATUS:
- case BLUETOOTH_EVENT_AVRCP_CONTROL_REPEAT_STATUS:
- signal = BT_MEDIA_REPEAT_STATUS;
- break;
- case BLUETOOTH_EVENT_AVRCP_SETTING_SCAN_STATUS:
- case BLUETOOTH_EVENT_AVRCP_CONTROL_SCAN_STATUS:
- signal = BT_MEDIA_SCAN_STATUS;
- break;
- case BLUETOOTH_EVENT_AVRCP_SONG_POSITION_STATUS:
- signal = BT_MEDIA_POSITION_STATUS;
- break;
- case BLUETOOTH_EVENT_AVRCP_PLAY_STATUS_CHANGED:
- signal = BT_MEDIA_PLAY_STATUS;
- break;
- case BLUETOOTH_EVENT_AVRCP_TRACK_CHANGED:
- signal = BT_MEDIA_TRACK_CHANGE;
- break;
- case BLUETOOTH_EVENT_GATT_CONNECTED:
- signal = BT_GATT_CONNECTED;
- BT_INFO_C("### Connected [GATT]");
- break;
- case BLUETOOTH_EVENT_GATT_DISCONNECTED:
- signal = BT_GATT_DISCONNECTED;
- BT_INFO_C("### Disconnected [GATT]");
- break;
- case BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED:
- signal = BT_GATT_REQ_ATT_MTU_CHANGED;
- break;
- case BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED:
- signal = BT_IPSP_INITIALIZED;
- break;
- case BLUETOOTH_EVENT_IPSP_CONNECTED:
- signal = BT_IPSP_CONNECTED;
- break;
- case BLUETOOTH_EVENT_IPSP_DISCONNECTED:
- signal = BT_IPSP_DISCONNECTED;
- break;
- case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED:
- signal = BT_GATT_CHAR_VAL_CHANGED;
- break;
- case BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED:
- signal = BT_LE_DATA_LENGTH_CHANGED;
- break;
- case BLUETOOTH_EVENT_REMOTE_IBEACON_DEVICE_FOUND:
- signal = BT_IBEACON_DEVICE_FOUND;
- break;
- case BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED:
- signal = BT_PXP_PROPERTY_CHANGED;
- break;
- default:
- BT_ERR("Unknown event");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- BT_DBG("Path : %s", path);
- BT_INFO_C("Signal : %s", signal);
-
- msg1 = g_dbus_message_new_signal(path, BT_EVENT_SERVICE, signal);
- g_dbus_message_set_body(msg1, param);
- if (!g_dbus_connection_send_message(event_conn, msg1, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 0, NULL))
- BT_ERR("Error while sending");
-
- g_object_unref(msg1);
-
-#ifdef HPS_FEATURE
- if (g_strcmp0(signal, BT_LE_ENABLED) == 0)
- _bt_send_to_hps();
-#endif
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_send_event_to_dest(const char* dest, int event_type,
- int event, GVariant *param)
-{
- char *path;
- char *signal;
- GError *error = NULL;
-
- retv_if(event_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- BT_DBG("event_type [%d], event [%d]", event_type, event);
-
- switch (event_type) {
- case BT_ADAPTER_EVENT:
- path = BT_ADAPTER_PATH;
- break;
- case BT_LE_ADAPTER_EVENT:
- path = BT_LE_ADAPTER_PATH;
- break;
- case BT_DEVICE_EVENT:
- path = BT_DEVICE_PATH;
- break;
- default:
- BT_ERR("Unknown event");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- switch (event) {
- case BLUETOOTH_EVENT_ADVERTISING_STARTED:
- signal = BT_ADVERTISING_STARTED;
- break;
- case BLUETOOTH_EVENT_ADVERTISING_STOPPED:
- signal = BT_ADVERTISING_STOPPED;
- break;
- case BLUETOOTH_EVENT_PASSKEY_NOTIFICATION:
- signal = BT_PASSKEY_NOTIFICATION;
- break;
- case BLUETOOTH_EVENT_LE_DISCOVERY_STARTED:
- signal = BT_LE_DISCOVERY_STARTED;
- break;
- case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND:
- signal = BT_LE_DEVICE_FOUND;
- break;
- case BLUETOOTH_EVENT_LE_DISCOVERY_FINISHED:
- signal = BT_LE_DISCOVERY_FINISHED;
- break;
- case BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED:
- signal = BT_GATT_CHAR_VAL_CHANGED;
- break;
- default:
- BT_ERR("Unknown event");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- BT_INFO_C("Signal : %s", signal);
-
- if (!g_dbus_connection_emit_signal(event_conn, dest, path, BT_EVENT_SERVICE,
- signal, param, &error)) {
- BT_ERR("Error while sending Signal: %s", signal);
- if (error) {
- BT_ERR("Error Code [%d], Error Message [%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_send_hf_local_term_event(char *address)
-{
- GError *error = NULL;
-
- retv_if(hf_local_term_event_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- if (!g_dbus_connection_emit_signal(hf_local_term_event_conn, NULL,
- BT_HF_LOCAL_TERM_EVENT_PATH,
- BT_HF_LOCAL_TERM_EVENT_INTERFACE,
- BT_HF_LOCAL_TERM, g_variant_new("s", address),
- &error)) {
- BT_ERR("Error while sending Signal: %s", signal);
- if (error) {
- BT_ERR("Error Code [%d], Error Message [%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-/* To send the event from service daemon to application*/
-int _bt_init_service_event_sender(void)
-{
- GDBusConnection *conn;
- GError *err = NULL;
-
- if (event_conn) {
- BT_ERR("Event handler is already exist");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (conn == NULL) {
- BT_ERR("conn == NULL");
- if (err) {
- BT_ERR("Code[%d], Message[%s]",
- err->code, err->message);
- g_clear_error(&err);
- }
-
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- event_conn = conn;
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_deinit_service_event_sender(void)
-{
- if (event_conn) {
- g_object_unref(event_conn);
- event_conn = NULL;
- }
-}
-
-int _bt_init_hf_local_term_event_sender(void)
-{
- GDBusConnection *conn;
- GError *err = NULL;
-
- if (hf_local_term_event_conn) {
- BT_ERR("Event handler is already exist");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (conn == NULL) {
- BT_ERR("conn == NULL");
- if (err) {
- BT_ERR("Code[%d], Message[%s]",
- err->code, err->message);
- g_clear_error(&err);
- }
-
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- hf_local_term_event_conn = conn;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_deinit_hf_local_term_event_sender(void)
-{
- if (hf_local_term_event_conn) {
- g_object_unref(hf_local_term_event_conn);
- hf_local_term_event_conn = NULL;
- }
-}
-
-int _bt_send_dump_signal(char *signal)
-{
- GError *error = NULL;
- int32_t pid = getpid();
-
- retv_if(event_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- if (!g_dbus_connection_emit_signal(event_conn, NULL,
- BT_DUMP_SERVICE_PATH,
- BT_DUMP_SERVICE_INTERFACE,
- signal, g_variant_new("(i)", pid),
- &error)) {
- BT_ERR("Error while sending Signal: %s", signal);
- if (error) {
- BT_ERR("Error Code [%d], Error Message [%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <vconf.h>
-#include <vconf-keys.h>
-
-#include "bt-internal-types.h"
-#include "bt-service-common.h"
-#include "bt-service-agent.h"
-#include "bt-service-gap-agent.h"
-#include "bt-service-adapter.h"
-#include "bt-service-device.h"
-
-static GDBusConnection *connection = NULL;
-
-typedef enum {
- GAP_AGENT_ERROR_REJECT,
- GAP_AGENT_ERROR_CANCEL,
- GAP_AGENT_ERROR_TIMEOUT,
-} GapAgentError;
-
-#define GAP_AGENT_ERROR (gap_agent_error_quark())
-
-static GQuark gap_agent_error_quark(void)
-{
- static GQuark quark = 0;
- if (!quark)
- quark = g_quark_from_static_string("agent");
-
- return quark;
-}
-
-#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
-
-static gint gap_agent_id = -1;
-
-static bt_agent_osp_server_t *__gap_agent_find_server(GSList *servers,
- int type,
- const char *uuid)
-{
- GSList *l;
- bt_agent_osp_server_t *transfer;
-
- for (l = servers; l != NULL; l = l->next) {
- transfer = l->data;
-
- if (transfer == NULL)
- continue;
-
- /* No uuid in obex server */
- if (type == BT_OBEX_SERVER &&
- transfer->type == BT_OBEX_SERVER)
- return transfer;
-
- if (g_strcmp0(transfer->uuid, uuid) == 0)
- return transfer;
- }
-
- return NULL;
-}
-
-static void __gap_agent_remove_osp_servers(GSList *osp_servers)
-{
- GSList *l;
- bt_agent_osp_server_t *server;
-
- for (l = osp_servers; l != NULL; l = g_slist_next(l)) {
- server = l->data;
-
- if (server == NULL)
- continue;
-
- g_free(server->uuid);
- g_free(server);
- }
-}
-
-gboolean _gap_agent_register_osp_server(GapAgentPrivate *agent,
- const gint type,
- const char *uuid,
- const char *path,
- int fd)
-{
- bt_agent_osp_server_t *server;
-
- BT_DBG("+");
-
- GapAgentPrivate *priv = agent;
-
- if (priv == NULL)
- return FALSE;
-
- /* type: BT_OBEX_SERVER / BT_RFCOMM_SERVER*/
- if (type > BT_RFCOMM_SERVER)
- return FALSE;
-
- server = g_malloc0(sizeof(bt_agent_osp_server_t));
- server->type = type;
- if (type == BT_RFCOMM_SERVER) {
- server->uuid = g_strdup(uuid);
- server->path = g_strdup(path);
- server->fd = fd;
- }
-
- priv->osp_servers = g_slist_append(priv->osp_servers, server);
-
- BT_DBG("-");
-
- return TRUE;
-}
-
-gboolean _gap_agent_unregister_osp_server(GapAgentPrivate *agent,
- const gint type,
- const char *uuid)
-{
- bt_agent_osp_server_t *server;
-
- BT_DBG("+");
-
- GapAgentPrivate *priv = agent;
-
- if (priv == NULL)
- return FALSE;
-
- /* type: BT_OBEX_SERVER / BT_RFCOMM_SERVER*/
- if (type > BT_RFCOMM_SERVER)
- return FALSE;
-
- server = __gap_agent_find_server(priv->osp_servers, type, uuid);
-
- if (server == NULL)
- return FALSE;
-
- priv->osp_servers = g_slist_remove(priv->osp_servers, server);
-
- g_free(server->uuid);
- g_free(server);
-
- BT_DBG("-");
-
- return TRUE;
-}
-
-gboolean gap_agent_reply_pin_code(GapAgentPrivate *agent, const guint accept,
- const char *pin_code,
- GDBusMethodInvocation *context)
-{
- BT_DBG("+");
-
- GapAgentPrivate *priv = agent;
- retv_if(priv == NULL, FALSE);
-
- if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
- priv->reply_context != NULL) {
- if (accept == GAP_AGENT_ACCEPT) {
- g_dbus_method_invocation_return_value(priv->reply_context,
- g_variant_new("(s)", pin_code));
- priv->canceled = FALSE;
- } else {
- switch (accept) {
- case GAP_AGENT_CANCEL:
- g_dbus_method_invocation_return_error(priv->reply_context,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
- "CanceledbyUser");
- priv->canceled = TRUE;
- break;
- case GAP_AGENT_TIMEOUT:
- case GAP_AGENT_REJECT:
- default:
- g_dbus_method_invocation_return_error(priv->reply_context,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
- "Pairing request rejected");
- priv->canceled = FALSE;
- break;
- }
- }
- }
-
- priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
- priv->reply_context = NULL;
- memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
-
- BT_DBG("-");
-
- return TRUE;
-}
-
-gboolean gap_agent_reply_passkey(GapAgentPrivate *agent, const guint accept,
- const char *passkey,
- GDBusMethodInvocation *context)
-{
- BT_DBG("+");
-
- GapAgentPrivate *priv = agent;
- retv_if(priv == NULL, FALSE);
-
- if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
- priv->reply_context != NULL) {
- if (accept == GAP_AGENT_ACCEPT) {
- guint pass_key = atoi(passkey);
- g_dbus_method_invocation_return_value(priv->reply_context,
- g_variant_new("(u)", pass_key));
- priv->canceled = FALSE;
- } else {
- switch (accept) {
- case GAP_AGENT_CANCEL:
- g_dbus_method_invocation_return_error(priv->reply_context,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
- "CanceledbyUser");
- priv->canceled = TRUE;
- break;
- case GAP_AGENT_TIMEOUT:
- case GAP_AGENT_REJECT:
- default:
- g_dbus_method_invocation_return_error(priv->reply_context,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
- "Passkey request rejected");
- priv->canceled = FALSE;
- break;
- }
- }
- }
-
- priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
- priv->reply_context = NULL;
- memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
-
- BT_DBG("-");
-
- return TRUE;
-}
-
-gboolean gap_agent_reply_confirmation(GapAgentPrivate *agent, const guint accept,
- GDBusMethodInvocation *context)
-{
- BT_DBG("+");
-
- GapAgentPrivate *priv = agent;
- retv_if(priv == NULL, FALSE);
-
- if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
- priv->reply_context != NULL) {
- if (accept == GAP_AGENT_ACCEPT) {
- g_dbus_method_invocation_return_value(priv->reply_context, NULL);
- priv->canceled = FALSE;
- } else {
- switch (accept) {
- case GAP_AGENT_CANCEL:
- g_dbus_method_invocation_return_error(priv->reply_context,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
- "CanceledbyUser");
- priv->canceled = TRUE;
- break;
- case GAP_AGENT_TIMEOUT:
- case GAP_AGENT_REJECT:
- default:
- g_dbus_method_invocation_return_error(priv->reply_context,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
- "Confirmation request rejected");
- priv->canceled = FALSE;
- break;
- }
- }
- }
-
- priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
- priv->reply_context = NULL;
- memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
-
- BT_DBG("-");
-
- return TRUE;
-}
-
-gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
- GDBusMethodInvocation *context)
-{
- gboolean ret = TRUE;
-
- BT_DBG("+");
-
- GapAgentPrivate *priv = agent;
- retv_if(priv == NULL, FALSE);
-
- if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
- priv->reply_context != NULL) {
- if (accept == GAP_AGENT_ACCEPT) {
- g_dbus_method_invocation_return_value(priv->reply_context, NULL);
- } else if (accept == GAP_AGENT_ACCEPT_ALWAYS) {
- bluetooth_device_address_t addr = { { 0, } };
- int result;
-
- _bt_convert_addr_string_to_type(addr.addr,
- priv->authorize_addr);
-
- /* Do not set device as Trusted*/
- /* result = _bt_set_authorization(&addr, TRUE); */
- result = _bt_set_trust_profile(&addr,
- _bt_get_trusted_profile_enum(priv->uuid),
- TRUE);
- if (result == BLUETOOTH_ERROR_NONE) {
- BT_INFO("[%s] Profile added as trusted for Device[%s]",
- priv->uuid, priv->authorize_addr);
- }
-
- g_dbus_method_invocation_return_value(priv->reply_context, NULL);
- } else {
- switch (accept) {
- case GAP_AGENT_CANCEL:
- g_dbus_method_invocation_return_error(priv->reply_context,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
- "CanceledbyUser");
- break;
- case GAP_AGENT_REJECT: {
- bluetooth_device_address_t addr = { { 0, } };
- int result;
-
- _bt_convert_addr_string_to_type(addr.addr,
- priv->authorize_addr);
-
- /* Set Profile as blocked */
- result = _bt_set_trust_profile(&addr,
- _bt_get_trusted_profile_enum(priv->uuid),
- FALSE);
- if (result == BLUETOOTH_ERROR_NONE) {
- BT_INFO("[%s] Profile added as blocked for Device[%s]",
- priv->uuid, priv->authorize_addr);
- }
-
- g_dbus_method_invocation_return_error(priv->reply_context,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
- "Authorization request rejected");
- break;
- }
- case GAP_AGENT_TIMEOUT:
- default:
- g_dbus_method_invocation_return_error(priv->reply_context,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
- "Authorization request rejected");
- break;
- }
- }
-
- if (context)
- g_dbus_method_invocation_return_value(context, NULL);
- } else {
- BT_ERR("No context");
-
- if (context)
- g_dbus_method_invocation_return_error(context,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
- "No context");
- ret = FALSE;
- }
-
- if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION) {
- priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
- priv->reply_context = NULL;
- memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
- g_free(priv->uuid);
- priv->uuid = NULL;
- }
-
- BT_DBG("-");
-
- return ret;
-}
-
-gboolean _gap_agent_register(GapAgentPrivate *agent)
-{
- GapAgentPrivate *priv = agent;
- GDBusProxy *agent_manager;
- GError *error = NULL;
- GVariant *reply;
-
- retv_if(priv == NULL, FALSE);
- retv_if(connection == NULL, FALSE);
-
- if (priv->agent_manager == NULL) {
- agent_manager = g_dbus_proxy_new_sync(connection,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, BT_BLUEZ_PATH,
- BT_AGENT_MANAGER_INTERFACE, NULL, &error);
- if (!agent_manager) {
- if (error) {
- ERR("Unable to create proxy: %s", error->message);
- g_clear_error(&error);
- }
- return FALSE;
- }
- } else {
- agent_manager = priv->agent_manager;
- }
-
- reply = g_dbus_proxy_call_sync(agent_manager, "RegisterAgent",
-#ifdef TIZEN_BT_IO_CAPA_NO_INPUT_OUTPUT
- g_variant_new("(os)", priv->path, "NoInputNoOutput"),
-#elif defined(TIZEN_BT_IO_CAPA_DISPLAY_ONLY)
- g_variant_new("(os)", priv->path, "DisplayOnly"),
-#else
- g_variant_new("(os)", priv->path, "KeyboardDisplay"),
-#endif
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
- if (reply == NULL) {
- BT_ERR("Agent registration failed");
- if (error) {
- BT_ERR("Agent registration failed: errCode[%x], message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- g_object_unref(agent_manager);
- priv->agent_manager = NULL;
- return FALSE;
- }
- g_variant_unref(reply);
- reply = NULL;
-
- /* Set the defalut agent */
- BT_DBG("agent_manager[%p] priv->path[%s]", agent_manager, priv->path);
- reply = g_dbus_proxy_call_sync(agent_manager, "RequestDefaultAgent",
- g_variant_new("(o)", priv->path),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
- if (reply == NULL) {
- ERR("Request Default Agent failed");
- if (error) {
- ERR("Request Default Agent failed: errCode[%x], message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- g_object_unref(agent_manager);
- priv->agent_manager = NULL;
- return FALSE;
- }
- g_variant_unref(reply);
-
- priv->agent_manager = agent_manager;
-
- return TRUE;
-}
-
-static gboolean __gap_agent_unregister(GapAgentPrivate *agent)
-{
- GapAgentPrivate *priv = agent;
- GDBusProxy *agent_manager;
- GError *error = NULL;
- GVariant *reply;
-
- retv_if(priv == NULL, FALSE);
- retv_if(priv->path == NULL, FALSE);
- retv_if(connection == NULL, FALSE);
-
- if (priv->agent_manager == NULL) {
- agent_manager = g_dbus_proxy_new_sync(connection,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, BT_BLUEZ_PATH,
- BT_AGENT_MANAGER_INTERFACE, NULL, &error);
- if (!agent_manager) {
- if (error) {
- ERR("Unable to create proxy: %s", error->message);
- g_clear_error(&error);
- }
- return FALSE;
- }
- } else {
- agent_manager = priv->agent_manager;
- }
-
- reply = g_dbus_proxy_call_sync(agent_manager, "UnregisterAgent",
- g_variant_new("(o)", priv->path),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
- g_object_unref(agent_manager);
- priv->agent_manager = NULL;
-
- if (reply == NULL) {
- ERR("Agent unregistration failed");
- if (error) {
- ERR("Agent unregistration failed: errCode[%x], message[%s]",
- error->code, error->message);
- g_clear_error(&error);
- }
- return FALSE;
- }
- g_variant_unref(reply);
-
- return TRUE;
-}
-
-static const gchar gap_agent_bluez_introspection_xml[] =
-"<node name='/'>"
-" <interface name='org.bluez.Agent1'>"
-" <method name='RequestConfirmation'>"
-" <arg type='o' name='target' direction='in'/>"
-" <arg type='u' name='passkey' direction='in'/>"
-" </method>"
-" <method name='RequestPinCode'>"
-" <arg type='o' name='target' direction='in'/>"
-" <arg type='s' name='pincode' direction='out'/>"
-" </method>"
-" <method name='RequestAuthorization'>"
-" <arg type='o' name='target' direction='in'/>"
-" </method>"
-" <method name='RequestPasskey'>"
-" <arg type='o' name='target' direction='in'/>"
-" <arg type='u' name='passkey' direction='out'/>"
-" </method>"
-" <method name='AuthorizeService'>"
-" <arg type='o' name='target' direction='in'/>"
-" <arg type='s' name='uuid' direction='in'/>"
-" </method>"
-" <method name='DisplayPasskey'>"
-" <arg type='o' name='target' direction='in'/>"
-" <arg type='u' name='passkey' direction='in'/>"
-" <arg type='q' name='entered' direction='in'/>"
-" </method>"
-" <method name='ReplyConfirmation'>"
-" <arg type='u' name='accept' direction='in'/>"
-" </method>"
-" <method name='ReplyPinCode'>"
-" <arg type='u' name='accept' direction='in'/>"
-" <arg type='s' name='pincode' direction='in'/>"
-" </method>"
-" <method name='ReplyAuthorize'>"
-" <arg type='u' name='accept' direction='in'/>"
-" </method>"
-" <method name='ReplyPasskey'>"
-" <arg type='u' name='accept' direction='in'/>"
-" <arg type='s' name='passkey' direction='in'/>"
-" </method>"
-" <method name='GetDiscoverableTimeout'>"
-" <arg type='u' name='timeout' direction='out'/>"
-" </method>"
-" <method name='ConfirmModeChange'>"
-" <arg type='s' name='mode' direction='in'/>"
-" </method>"
-" <method name='Cancel'>"
-" </method>"
-" <method name='Release'>"
-" </method>"
-" </interface>"
-"</node>";
-
-static GDBusNodeInfo *__bt_service_create_method_node_info
- (const gchar *introspection_data)
-{
- GError *err = NULL;
- GDBusNodeInfo *node_info = NULL;
-
- if (introspection_data == NULL)
- return NULL;
-
- node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
-
- if (err) {
- ERR("Unable to create node: %s", err->message);
- g_clear_error(&err);
- }
- return node_info;
-}
-
-static void __bt_gap_agent_method(GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *method_name,
- GVariant *parameters,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
-{
- FN_START;
-
- BT_DBG("Method[%s] Object Path[%s] Interface Name[%s]",
- method_name, object_path, interface_name);
-
- GError *err = NULL;
-
- if (g_strcmp0(method_name, "RequestPinCode") == 0) {
- GapAgentPrivate *agent = user_data;
- char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
- GDBusProxy *device;
- char *addr;
- char *path;
- GDBusConnection *conn;
-
- if (sender == NULL)
- return;
-
- g_variant_get(parameters, "(&o)", &path);
- BT_INFO("Request pin code, Device Path :%s", path);
-
- /* Need to check
- if (g_strcmp0(sender, agent->busname) != 0)
- return;
- */
-
- if (!agent->cb.passkey_func)
- return;
-
- conn = _bt_gdbus_get_system_gconn();
- if (conn == NULL)
- return;
-
- device = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, path,
- BT_PROPERTIES_INTERFACE, NULL, &err);
-
- if (!device) {
- BT_ERR("Fail to make device proxy");
-
- g_dbus_method_invocation_return_error(invocation,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
- "No proxy for device");
-
- if (err) {
- ERR("Unable to create proxy: %s", err->message);
- g_clear_error(&err);
- }
-
- return;
- }
-
- agent->exec_type = GAP_AGENT_EXEC_PAIRING;
- agent->reply_context = invocation;
-
- addr = strstr(path, "dev_");
- if (addr != NULL) {
- char *pos = NULL;
- addr += 4;
- g_strlcpy(agent->pairing_addr, addr, sizeof(agent->pairing_addr));
-
- while ((pos = strchr(agent->pairing_addr, '_')) != NULL)
- *pos = ':';
- }
-
- agent->cb.pincode_func(agent, device);
-
- g_object_unref(device);
- return;
-
- } else if (g_strcmp0(method_name, "RequestPasskey") == 0) {
- GapAgentPrivate *priv = user_data;
- char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
- GDBusProxy *device;
- char *addr;
- char *path;
- GDBusConnection *conn;
-
- if (sender == NULL)
- return;
-
- g_variant_get(parameters, "(&o)", &path);
- BT_INFO("Request passkey : sender %s priv->busname %s Device Path :%s",
- sender, priv->busname, path);
-
- /* Need to check
- if (g_strcmp0(sender, agent->busname) != 0)
- return;
- */
-
- if (!priv->cb.passkey_func)
- return;
-
- conn = _bt_gdbus_get_system_gconn();
- if (conn == NULL)
- return;
-
- device = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, path,
- BT_PROPERTIES_INTERFACE, NULL, &err);
-
- if (!device) {
- BT_ERR("Fail to make device proxy");
-
- g_dbus_method_invocation_return_error(invocation,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
- "No proxy for device");
-
- if (err) {
- ERR("Unable to create proxy: %s", err->message);
- g_clear_error(&err);
- }
-
- return;
- }
-
- priv->exec_type = GAP_AGENT_EXEC_PAIRING;
- priv->reply_context = invocation;
-
- addr = strstr(path, "dev_");
- if (addr != NULL) {
- char *pos = NULL;
- addr += 4;
- g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr));
-
- while ((pos = strchr(priv->pairing_addr, '_')) != NULL)
- *pos = ':';
- }
-
- priv->cb.passkey_func(priv, device);
-
- g_object_unref(device);
- return;
-
- } else if (g_strcmp0(method_name, "DisplayPasskey") == 0) {
- GapAgentPrivate *priv = user_data;
- char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
- GDBusProxy *device;
- guint passkey;
- guint16 entered;
- char *path;
- GDBusConnection *conn;
-
- if (sender == NULL)
- return;
-
- g_variant_get(parameters, "(&ouq)", &path, &passkey, &entered);
- BT_INFO("Request passkey display :sender %s priv->busname %s"
- " Device Path :%s, Passkey: %06d, Entered: %d",
- sender, priv->busname, path, passkey, entered);
-
- /* Do not show popup for Key event while typing*/
- if (entered)
- return;
-
- /* Need to check
- if (g_strcmp0(sender, agent->busname) != 0)
- return;
- */
-
- if (!priv->cb.display_func)
- return;
-
- conn = _bt_gdbus_get_system_gconn();
- if (conn == NULL)
- return;
-
- device = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, path,
- BT_PROPERTIES_INTERFACE, NULL, &err);
-
- if (!device) {
- BT_ERR("Fail to make device proxy");
-
- g_dbus_method_invocation_return_error(invocation,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
- "No proxy for device");
-
- if (err) {
- ERR("Unable to create proxy: %s", err->message);
- g_clear_error(&err);
- }
-
- return;
- }
-
- g_dbus_method_invocation_return_value(invocation, NULL);
-
- priv->cb.display_func(priv, device, passkey);
-
- g_object_unref(device);
- return;
-
- } else if (g_strcmp0(method_name, "RequestConfirmation") == 0) {
- GapAgentPrivate *priv = user_data;
- char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
- GDBusProxy *device;
- guint passkey;
- char *path;
- char *addr;
- GDBusConnection *conn;
-
- if (sender == NULL)
- return;
-
- g_variant_get(parameters, "(&ou)", &path, &passkey);
- BT_INFO_C("### Request passkey confirmation");
- INFO_SECURE("Device Path :%s, Passkey: %d", path, passkey);
-
- BT_DBG("Sender: [%s] priv->busname: [%s]", sender, priv->busname);
- /* Need to check
- if (g_strcmp0(sender, agent->busname) != 0)
- return;
- */
-
- BT_DBG("priv->cb.confirm_func [%p]", priv->cb.confirm_func);
- if (!priv->cb.confirm_func)
- return;
-
- conn = _bt_gdbus_get_system_gconn();
- if (conn == NULL)
- return;
-
- device = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, path,
- BT_PROPERTIES_INTERFACE, NULL, &err);
-
- if (!device) {
- BT_ERR("Fail to make device proxy");
-
- g_dbus_method_invocation_return_error(invocation,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
- "No proxy for device");
-
- if (err) {
- ERR("Unable to create proxy: %s", err->message);
- g_clear_error(&err);
- }
-
- return;
- }
-
- priv->exec_type = GAP_AGENT_EXEC_PAIRING;
- priv->reply_context = invocation;
-
- addr = strstr(path, "dev_");
- if (addr != NULL) {
- char *pos = NULL;
- addr += 4;
- g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr));
-
- while ((pos = strchr(priv->pairing_addr, '_')) != NULL)
- *pos = ':';
- }
-
- priv->cb.confirm_func(priv, device, passkey);
-
- g_object_unref(device);
- return;
-
- } else if (g_strcmp0(method_name, "AuthorizeService") == 0) {
- GapAgentPrivate *priv = user_data;
- char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
- GDBusProxy *device;
- GDBusConnection *conn;
- char *addr;
- char *path;
- char *uuid;
-
- if (sender == NULL)
- return;
-
- g_variant_get(parameters, "(&o&s)", &path, &uuid);
- BT_DBG("Request authorization :sender %s priv->busname %s "
- "Device Path :%s UUID: %s",
- sender, priv->busname, path, uuid);
-
- /* Need to check
- if (g_strcmp0(sender, agent->busname) != 0)
- return;
- */
-
- if (!priv->cb.authorize_func)
- return;
-
- conn = _bt_gdbus_get_system_gconn();
- if (conn == NULL)
- return;
-
- device = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, path,
- BT_PROPERTIES_INTERFACE, NULL, &err);
-
- if (!device) {
- BT_ERR("Fail to make device proxy");
-
- g_dbus_method_invocation_return_error(invocation,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
- "No proxy for device");
-
- if (err) {
- ERR("Unable to create proxy: %s", err->message);
- g_clear_error(&err);
- }
-
- return;
- }
-
- priv->exec_type = GAP_AGENT_EXEC_AUTHORZATION;
- priv->reply_context = invocation;
- priv->uuid = g_strdup(uuid);
-
- addr = strstr(path, "dev_");
- if (addr != NULL) {
- char *pos = NULL;
- addr += 4;
- g_strlcpy(priv->authorize_addr, addr,
- sizeof(priv->authorize_addr));
-
- while ((pos = strchr(priv->authorize_addr, '_')) != NULL)
- *pos = ':';
- }
-
- priv->cb.authorize_func(priv, device, uuid);
-
- g_object_unref(device);
- return;
-
- } else if (g_strcmp0(method_name, "RequestAuthorization") == 0) {
- g_dbus_method_invocation_return_value(invocation, NULL);
- } else if (g_strcmp0(method_name, "ConfirmModeChange") == 0) {
- g_dbus_method_invocation_return_value(invocation, NULL);
- } else if (g_strcmp0(method_name, "Cancel") == 0) {
- GapAgentPrivate *priv = user_data;
- char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
-
- if (sender == NULL)
- return;
-
- BT_DBG("Cancelled : agent %p sender %s", sender);
-
- /* Need to check
- if (g_strcmp0(sender, agent->busname) != 0)
- return;
- */
-
- if (priv->cb.authorization_cancel_func &&
- priv->exec_type == GAP_AGENT_EXEC_AUTHORZATION) {
- priv->cb.authorization_cancel_func(priv,
- priv->authorize_addr);
- memset(priv->authorize_addr, 0x00,
- sizeof(priv->authorize_addr));
- } else if (priv->cb.pairing_cancel_func &&
- priv->exec_type == GAP_AGENT_EXEC_PAIRING) {
- priv->cb.pairing_cancel_func(priv,
- priv->pairing_addr);
- memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
- }
-
- if (priv->exec_type != GAP_AGENT_EXEC_CONFIRM_MODE &&
- priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
- priv->reply_context != NULL) {
-
- g_dbus_method_invocation_return_error(priv->reply_context,
- GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
- "Rejected by remote cancel");
- }
-
- /* Canceled flag is set when user cancels pairing request
- * Since here bluez has cancelled pairing request, we set the flag to false
- */
- priv->canceled = FALSE;
- priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
- priv->reply_context = NULL;
-
- return;
- } else if (g_strcmp0(method_name, "Release") == 0) {
- GapAgentPrivate *priv = user_data;
- char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
-
- if (sender == NULL)
- return;
-
- BT_DBG("Released : sender %s\n", sender);
-
- /* Need to check
- if (g_strcmp0(sender, agent->busname) != 0)
- return;
- */
-
- g_dbus_method_invocation_return_value(invocation, NULL);
-
- priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
- priv->reply_context = NULL;
-
- memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
- memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
-
- return;
- } else if (g_strcmp0(method_name, "GetDiscoverableTimeout") == 0) {
- BT_DBG("+");
-
- int timeout;
-
- _bt_get_timeout_value(&timeout);
-
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", timeout));
-
- BT_DBG("-");
-
- return;
- } else if (g_strcmp0(method_name, "ReplyPinCode") == 0) {
- GapAgentPrivate *priv = user_data;
- const char *pin_code;
- const guint accept;
-
- g_variant_get(parameters, "(u&s)", &accept, &pin_code);
- BT_DBG("Accept: %d PinCode: %s", accept, pin_code);
- gap_agent_reply_pin_code(priv, accept, pin_code, invocation);
- } else if (g_strcmp0(method_name, "ReplyPasskey") == 0) {
- GapAgentPrivate *priv = user_data;
- const char *passkey;
- const guint accept;
-
- g_variant_get(parameters, "(u&s)", &accept, &passkey);
- BT_DBG("Accept: %d PinCode: %s", accept, passkey);
- gap_agent_reply_passkey(priv, accept, passkey, invocation);
- } else if (g_strcmp0(method_name, "ReplyConfirmation") == 0) {
- GapAgentPrivate *priv = user_data;
- const guint accept;
-
- g_variant_get(parameters, "(u)", &accept);
- BT_DBG("Accept: %d", accept);
- gap_agent_reply_confirmation(priv, accept, invocation);
- } else if (g_strcmp0(method_name, "ReplyAuthorize") == 0) {
- GapAgentPrivate *priv = user_data;
- const guint accept;
-
- g_variant_get(parameters, "(u)", &accept);
- BT_DBG("Accept: %d", accept);
- gap_agent_reply_authorize(priv, accept, invocation);
- }
-}
-
-static const GDBusInterfaceVTable method_table = {
- __bt_gap_agent_method,
- NULL,
- NULL,
-};
-
-void _gap_agent_setup_dbus(GapAgentPrivate *agent, GAP_AGENT_FUNC_CB *func_cb,
- const char *path,
- GDBusProxy *adapter)
-{
- GapAgentPrivate *priv = agent;
- GDBusProxy *proxy;
- GDBusNodeInfo *node_info;
- GError *error = NULL;
-
- priv->path = g_strdup(path);
-
-
- node_info = __bt_service_create_method_node_info(
- gap_agent_bluez_introspection_xml);
- if (node_info == NULL)
- return;
-
- BT_DBG("path is [%s]", path);
-
- if (connection == NULL) {
- connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (!connection) {
- if (error) {
- ERR("Unable to connect to gdbus: %s", error->message);
- g_clear_error(&error);
- }
- g_dbus_node_info_unref(node_info);
- return;
- }
- }
-
- if (gap_agent_id == -1) {
- gap_agent_id = g_dbus_connection_register_object(connection, path,
- node_info->interfaces[0],
- &method_table, priv,
- NULL, &error);
- }
-
- g_dbus_node_info_unref(node_info);
-
- if (gap_agent_id == 0) {
- BT_ERR("Failed to register for Path: %s", path);
- if (error) {
- BT_ERR("Failed to register: %s", error->message);
- g_clear_error(&error);
- }
- return;
- }
-
- memcpy(&priv->cb, func_cb, sizeof(GAP_AGENT_FUNC_CB));
-
- priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
- memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
- memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
- priv->reply_context = NULL;
-
- BT_DBG("path: %s", path);
-
- proxy = g_dbus_proxy_new_sync(connection,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, path,
- BT_AGENT_INTERFACE, NULL, &error);
-
- if (!proxy) {
- ERR("Unable to create proxy");
- if (error) {
- ERR("Error: %s", error->message);
- g_clear_error(&error);
- }
- priv->busname = NULL;
- } else {
- priv->busname = g_strdup(g_dbus_proxy_get_name(proxy));
- BT_DBG("Busname: %s", priv->busname);
- g_object_unref(proxy);
- }
-
-}
-
-void _gap_agent_reset_dbus(GapAgentPrivate *agent)
-{
- GapAgentPrivate *priv = agent;
- if (priv == NULL)
- return;
-
- __gap_agent_unregister(agent);
-
- if (gap_agent_id > 0) {
- g_dbus_connection_unregister_object(connection,
- gap_agent_id);
- gap_agent_id = -1;
- }
-
- if (connection) {
- g_object_unref(connection);
- connection = NULL;
- }
-
- if (priv->osp_servers) {
- __gap_agent_remove_osp_servers(priv->osp_servers);
- g_slist_free(priv->osp_servers);
- priv->osp_servers = NULL;
- }
-
- g_free(priv->path);
- priv->path = NULL;
-
- g_free(priv->busname);
- priv->busname = NULL;
-}
-
-gboolean _gap_agent_exist_osp_server(GapAgentPrivate *agent, int type, char *uuid)
-{
- GapAgentPrivate *priv = agent;
-
- if (priv == NULL)
- return FALSE;
-
- if (__gap_agent_find_server(priv->osp_servers,
- type, uuid) != NULL) {
- return TRUE;
- }
-
- return FALSE;
-}
-
-bt_agent_osp_server_t *_gap_agent_get_osp_server(GapAgentPrivate *agent, int type,
- char *uuid)
-{
- GapAgentPrivate *priv = agent;
- bt_agent_osp_server_t *osp_serv = NULL;
- if (priv == NULL)
- return NULL;
-
- osp_serv = __gap_agent_find_server(priv->osp_servers,
- type, uuid);
- if (!osp_serv)
- return NULL;
-
- return osp_serv;
-}
-
-gchar* _gap_agent_get_path(GapAgentPrivate *agent)
-{
- GapAgentPrivate *priv = agent;
- if (priv == NULL)
- return NULL;
-
- return priv->path;
-}
-
-gboolean _gap_agent_is_canceled(GapAgentPrivate *agent)
-{
- GapAgentPrivate *priv = agent;
-
- return priv->canceled;
-}
-
-void _gap_agent_set_canceled(GapAgentPrivate *agent, gboolean value)
-{
- GapAgentPrivate *priv = agent;
- if (priv == NULL)
- return;
-
- priv->canceled = value;
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<node name="/">
- <interface name="org.bluez.Agent">
- <method name="RequestPinCode">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="target"/>
- <arg type="s" name="pincode" direction="out"/>
- </method>
-
- <method name="RequestPasskey">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="target"/>
- <arg type="u" name="passkey" direction="out"/>
- </method>
-
- <method name="DisplayPasskey">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="target"/>
- <arg type="u" name="passkey"/>
- </method>
-
- <method name="RequestConfirmation">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="target"/>
- <arg type="u" name="passkey"/>
- </method>
-
- <method name="Authorize">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="target"/>
- <arg type="s" name="uuid"/>
- </method>
-
- <method name="Cancel">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- </method>
-
- <method name="Release">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- </method>
-
- <method name="ReplyPinCode">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="u" name="accept"/>
- <arg type="s" name="pincode"/>
- </method>
-
- <method name="ReplyPasskey">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="u" name="accept"/>
- <arg type="s" name="passkey"/>
- </method>
-
- <method name="ReplyConfirmation">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="u" name="accept"/>
- </method>
-
- <method name="ReplyAuthorize">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="u" name="accept"/>
- </method>
-
- <method name="ConfirmModeChange">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="s" name="mode"/>
- </method>
-
- <method name="GetDiscoverableTimeout">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="u" name="timeout" direction="out"/>
- </method>
- </interface>
-</node>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<node name="/">
- <interface name="org.bluez.Agent1">
- <method name="RequestPinCode">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="device"/>
- <arg type="s" name="pincode" direction="out"/>
- </method>
-
- <method name="RequestPasskey">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="device"/>
- <arg type="u" name="passkey" direction="out"/>
- </method>
-
- <method name="DisplayPasskey">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="device"/>
- <arg type="u" name="passkey"/>
- <arg type="q" name="entered"/>
- </method>
-
- <method name="RequestConfirmation">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="device"/>
- <arg type="u" name="passkey"/>
- </method>
-
- <method name="RequestAuthorization">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="device"/>
- </method>
-
- <method name="AuthorizeService">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="device"/>
- <arg type="s" name="uuid"/>
- </method>
-
- <method name="Cancel">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- </method>
-
- <method name="Release">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- </method>
-
- <method name="ReplyPinCode">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="u" name="accept"/>
- <arg type="s" name="pincode"/>
- </method>
-
- <method name="ReplyPasskey">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="u" name="accept"/>
- <arg type="s" name="passkey"/>
- </method>
-
- <method name="ReplyConfirmation">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="u" name="accept"/>
- </method>
-
- <method name="ReplyAuthorize">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="u" name="accept"/>
- </method>
-
- <method name="ConfirmModeChange">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="s" name="mode"/>
- </method>
-
- <method name="GetDiscoverableTimeout">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="u" name="timeout" direction="out"/>
- </method>
- </interface>
-</node>
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <string.h>
-#include <dlog.h>
-#include <vconf.h>
-#include <vconf-internal-bt-keys.h>
-
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-#include "bt-service-main.h"
-#include "bt-service-adapter.h"
-#include "bt-service-device.h"
-#include "bt-service-audio.h"
-#include "bt-service-headset-connection.h"
-
-#include "bt-service-opp-client.h"
-
-
-
-static GList *p_connection_list = NULL;
-typedef enum {
- BLUETOOTH_NONE_CONNECTED = 0x00,
- BLUETOOTH_HFP_CONNECTED ,
- BLUETOOTH_A2DP_CONNECTED,
- BLUETOOTH_ALL_CONNECTED,
-} bluetooth_state_type_t;
-
-typedef struct {
- bluetooth_state_type_t state;
- bluetooth_device_info_t dev_info;
- int connection_type;
-} bt_connection_node_info_t;
-
-gboolean connection_local = FALSE;
-
-
-void _bt_headset_set_local_connection(gboolean value)
-{
- BT_INFO("setting connection_local to %d", value);
- connection_local = value;
-}
-
-gboolean _bt_headset_get_local_connection()
-{
- return connection_local;
-}
-
-//gint compare_state(GList *data, bluetooth_state_type_t state)
-gint compare_state(gconstpointer list_data, gconstpointer conn_state)
-{
- GList *data = (GList *) list_data;
- bluetooth_state_type_t *state = (bluetooth_state_type_t *)conn_state;
- bt_connection_node_info_t *p_data = (bt_connection_node_info_t *) data;
- if (p_data->state == *state) {
- BT_INFO("State Already Added");
- return 0;
- }
- return 1;
-}
-
-gboolean connect_remote_media_audio(gpointer user_data)
-{
- bt_connection_node_info_t *conn_info =
- (bt_connection_node_info_t *) user_data;
- GList *list = NULL;
- bluetooth_state_type_t state;
-
- char remote_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- _bt_convert_addr_type_to_string(remote_address, conn_info->dev_info.device_address.addr);
- if (p_connection_list == NULL) {
- BT_INFO("None of device connected and this hasbeen triggered");
- g_free(conn_info);
- return FALSE;
- }
- if (conn_info->connection_type == BT_AUDIO_A2DP) {
- state = BLUETOOTH_A2DP_CONNECTED;
- list = g_list_find_custom(p_connection_list,
- &state, compare_state);
- if (list == NULL) {
- BT_INFO("Head Set didn't initiated a2dp connection");
- BT_INFO("local device initiating A2DP connection");
-
- _bt_audio_connect(0, BT_AUDIO_A2DP,
- &conn_info->dev_info.device_address, NULL);
- } else {
- BT_INFO("A2DP Connection Already exists");
- }
- g_free(conn_info);
- } else {
- state = BLUETOOTH_HFP_CONNECTED;
- list = g_list_find_custom(p_connection_list,
- &state, compare_state);
- if (list == NULL) {
- BT_INFO("Headset didn't initiated HFP connection");
- BT_INFO("local device intiating HFP Connection");
-
- _bt_audio_connect(0, BT_AUDIO_HSP,
- &conn_info->dev_info.device_address, NULL);
- } else {
- BT_INFO("HFP Connection Already exists");
- }
- g_free(conn_info);
- }
- return FALSE;
-}
-
-void _bt_get_bluetooth_device_info(char *remote_address, bluetooth_device_info_t *device)
-{
- GArray *dev_list = NULL;
- int size = 0;
- int i = 0;
- bluetooth_device_info_t *info;
- char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 };
-
- if (device == NULL)
- return;
-
- dev_list = g_array_new(FALSE, FALSE, sizeof(gchar));
-
- _bt_get_bonded_devices(&dev_list);
- size = (dev_list->len) / sizeof(bluetooth_device_info_t);
- for (i = 0; i < size; i++) {
- info = &g_array_index(dev_list, bluetooth_device_info_t, i);
- _bt_convert_addr_type_to_string(bond_address, info->device_address.addr);
- if (strcmp(bond_address, remote_address) == 0) {
- BT_INFO("Match found");
- memcpy(device, info, sizeof(bluetooth_device_info_t));
- g_array_free(dev_list, TRUE);
- return;
- }
- }
- g_array_free(dev_list, TRUE);
- return;
-}
-
-void _bt_headset_add_timer_function(int connection_type, bluetooth_device_info_t *info)
-{
- bt_connection_node_info_t *pass_conn_info = NULL;
-
- if (info == NULL)
- return;
-
- pass_conn_info = g_new0(bt_connection_node_info_t, 1);
- pass_conn_info->connection_type = connection_type;
- memcpy(&pass_conn_info->dev_info, info, sizeof(bluetooth_device_info_t));
- /* This need to be freed in timer function */
- g_timeout_add(CONNECT_TIMEOUT, connect_remote_media_audio,
- pass_conn_info);
- return;
-}
-
-void _bt_start_timer_for_connection(char *remote_address, int connection_type)
-{
- GArray *dev_list = NULL;
- int size;
- int i;
- int j;
- bluetooth_device_info_t *info;
- char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- dev_list = g_array_new(FALSE, FALSE, sizeof(gchar));
- _bt_get_bonded_devices(&dev_list);
- size = (dev_list->len) / sizeof(bluetooth_device_info_t);
-
- for (i = 0; i < size; i++) {
- info = &g_array_index(dev_list, bluetooth_device_info_t, i);
- j = 0;
- _bt_convert_addr_type_to_string(bond_address,
- info->device_address.addr);
- if (strcmp(bond_address, remote_address) != 0)
- continue;
- BT_INFO("Device address Matched");
-
- while (j != info->service_index) {
- BT_INFO("UUID %s", info->uuids[j]);
- if (connection_type == BT_AUDIO_A2DP) {
- if (strcmp(info->uuids[j], A2DP_SINK_UUID) == 0) {
- BT_INFO("Remote Device has A2DP Sink Support start timer");
- _bt_headset_add_timer_function(BT_AUDIO_A2DP, info);
- goto end;
- }
- } else {
- if (strcmp(info->uuids[j], HFP_HS_UUID) == 0) {
- BT_INFO("Remote Device has HFP Sink Support start timer");
- _bt_headset_add_timer_function(BT_AUDIO_HSP, info);
- goto end;
- }
- }
- j++;
- }
- }
-end:
- g_array_free(dev_list, TRUE);
-}
-
-void __bt_connection_manager_set_state(char *remote_address, int event)
-{
- bt_connection_node_info_t *info;
-
- char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 };
- if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
- info = g_new0(bt_connection_node_info_t, 1);
- info->state = BLUETOOTH_HFP_CONNECTED;
- _bt_get_bluetooth_device_info(remote_address, &info->dev_info);
- _bt_convert_addr_type_to_string(bond_address,
- info->dev_info.device_address.addr);
- BT_INFO("Adding HFP Connected device to list");
- p_connection_list = g_list_append(p_connection_list, info);
- } else if (event == BLUETOOTH_EVENT_AG_DISCONNECTED) {
- /* Delete coresponding node */
- BT_INFO("Deleting HFP Connected device from list");
- GList *list = NULL;
- bluetooth_state_type_t state;
- bt_connection_node_info_t *h_conn;
- state = BLUETOOTH_HFP_CONNECTED;
- list = g_list_find_custom(p_connection_list,
- &state, compare_state);
- if (list == NULL) {
- BT_INFO("Didn't found any device with HFP State");
- return;
- }
- h_conn = list->data;
- p_connection_list = g_list_remove(p_connection_list, h_conn);
- g_free(h_conn);
- } else if (event == BLUETOOTH_EVENT_AV_CONNECTED) {
- info = g_new0(bt_connection_node_info_t, 1);
- info->state = BLUETOOTH_A2DP_CONNECTED;
- _bt_get_bluetooth_device_info(remote_address, &info->dev_info);
- _bt_convert_addr_type_to_string(bond_address,
- info->dev_info.device_address.addr);
- BT_INFO("Adding A2DP Connected device to list");
- p_connection_list = g_list_append(p_connection_list, info);
- } else if (event == BLUETOOTH_EVENT_AV_DISCONNECTED) {
- BT_INFO("Deleting A2DP Connected device from list");
- bt_connection_node_info_t *a_conn;
- GList *list = NULL;
- bluetooth_state_type_t state;
- state = BLUETOOTH_A2DP_CONNECTED;
- list = g_list_find_custom(p_connection_list,
- &state, compare_state);
- if (list == NULL) {
- BT_INFO("Didn't found any device with A2DP State");
- return;
- }
- a_conn = list->data;
- p_connection_list = g_list_remove(p_connection_list, a_conn);
- g_free(a_conn);
- }
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <gio/gio.h>
-#include <dlog.h>
-#include <string.h>
-#include <syspopup_caller.h>
-#include <vconf.h>
-#include "bluetooth-api.h"
-
-#include "bt-service-common.h"
-#include "bt-service-device.h"
-#include "bt-service-hid.h"
-#include "bt-service-event.h"
-#include "bt-service-util.h"
-
-#define BT_HID_BARCODE_SUPPORT "file/bluetooth/hid/barcode_support"
-
-static void __bt_hid_connect_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data)
-{
- GError *g_error = NULL;
- GVariant *out_param1 = NULL;
- GVariant *reply = NULL;
- bluetooth_device_address_t device_addr = { {0} };
- int result = BLUETOOTH_ERROR_NONE;
- bt_function_data_t *func_data;
- request_info_t *req_info;
-
- BT_DBG("+");
- func_data = user_data;
-
- reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
- g_object_unref(proxy);
- if (reply == NULL) {
- BT_ERR("Hid Connect Dbus Call Error");
- if (g_error) {
- BT_ERR("Error: %s\n", g_error->message);
- g_clear_error(&g_error);
- }
- result = BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_unref(reply);
-
-
- if (func_data == NULL) {
- /* Send reply */
- BT_ERR("func_data == NULL");
- goto done;
- }
-
- req_info = _bt_get_request_info(func_data->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- goto done;
- }
-
- if (req_info->context == NULL)
- goto done;
- BT_DBG("Address: %s", func_data->address);
- _bt_convert_addr_string_to_type(device_addr.addr,
- func_data->address);
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("iv", result, out_param1));
-
- _bt_delete_request_list(req_info->req_id);
- BT_DBG("HID Connected..");
-
-done:
- if (func_data) {
- g_free(func_data->address);
- g_free(func_data);
- }
-}
-
-static void __bt_hid_disconnect_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data)
-{
- GError *g_error = NULL;
- GVariant *out_param1 = NULL;
- GVariant *reply;
- bluetooth_device_address_t device_addr = { {0} };
- int result = BLUETOOTH_ERROR_NONE;
- bt_function_data_t *func_data;
- request_info_t *req_info;
-
- reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
- g_object_unref(proxy);
-
- if (reply == NULL) {
- BT_ERR("Hid Disconnect Dbus Call Error");
- if (g_error) {
- BT_ERR("Error: %s\n", g_error->message);
- g_clear_error(&g_error);
- }
- result = BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_unref(reply);
-
- func_data = user_data;
- if (func_data == NULL) {
- /* Send reply */
- BT_ERR("func_data == NULL");
- goto done;
- }
-
- req_info = _bt_get_request_info(func_data->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- goto done;
- }
-
- if (req_info->context == NULL)
- goto done;
- BT_DBG("Address: %s", func_data->address);
- _bt_convert_addr_string_to_type(device_addr.addr,
- func_data->address);
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("iv", result, out_param1));
-
- _bt_delete_request_list(req_info->req_id);
- BT_DBG("HID Disconnected..");
-
-done:
- if (func_data) {
- g_free(func_data->address);
- g_free(func_data);
- }
-}
-
-
-/**********************************************************************
-* HID APIs *
-***********************************************************************/
-
-int _bt_hid_connect(int request_id,
- bluetooth_device_address_t *device_address)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- bt_function_data_t *func_data;
- /* GDBusProxy *adapter_proxy; */
- GDBusConnection *conn;
-
- int ret;
- char *uuid;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- /* Unused adapter proxy
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- */
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- func_data = g_malloc0(sizeof(bt_function_data_t));
- func_data->address = g_strdup(address);
- func_data->req_id = request_id;
- uuid = HID_UUID;
-
- ret = _bt_connect_profile(address, uuid,
- __bt_hid_connect_cb, func_data);
-
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("_bt_connect_profile Error");
- return ret;
- }
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_hid_disconnect(int request_id,
- bluetooth_device_address_t *device_address)
-{
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- bt_function_data_t *func_data;
- /* GDBusProxy *adapter_proxy; */
- GDBusConnection *conn;
-
- int ret;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- /* Unused adapter proxy
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- */
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- func_data = g_malloc0(sizeof(bt_function_data_t));
- func_data->address = g_strdup(address);
- func_data->req_id = request_id;
-
- ret = _bt_disconnect_profile(address, HID_UUID,
- __bt_hid_disconnect_cb, func_data);
-
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("_bt_disconnect_profile Error");
- return ret;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_hid_enable_barcode_feature(void)
-{
- if (vconf_set_int(BT_HID_BARCODE_SUPPORT, 1) != 0) {
- BT_ERR("Set vconf failed\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <dlog.h>
-#include <string.h>
-#include <vconf.h>
-
-#include <bundle.h>
-#include <eventsystem.h>
-
-#include "bt-internal-types.h"
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-#include "bt-service-main.h"
-#include "bt-service-util.h"
-#include "bt-request-handler.h"
-#include "bt-service-adapter.h"
-#include "bt-service-adapter-le.h"
-
-static GMainLoop *main_loop;
-static gboolean terminated = FALSE;
-static gboolean is_initialized = FALSE;
-
-static void __on_log_glib(const gchar *log_domain, GLogLevelFlags log_level,
- const gchar *msg, gpointer user_data)
-{
- BT_ERR_C("%s", msg);
-}
-
-static void __bt_release_service(void)
-{
- _bt_service_unregister_vconf_handler();
- _bt_service_unregister_poweroff_event();
-
- _bt_service_adapter_le_deinit();
- _bt_deinit_service_event_sender();
- _bt_deinit_hf_local_term_event_sender();
- _bt_deinit_service_event_receiver();
-
- _bt_service_unregister();
-
- _bt_deinit_proxys();
-
- _bt_clear_request_list();
-
-#ifndef GATT_NO_RELAY
- _bt_clear_gatt_client_senders();
-#endif
- is_initialized = FALSE;
- _bt_service_cynara_deinit();
-
- BT_DBG("Terminating the bt-service daemon");
-}
-
-static void __bt_sigterm_handler(int signo, siginfo_t *info, void *data)
-{
- BT_INFO("signal [%d] is sent by [%d]", signo, info->si_pid);
-
-#ifndef TIZEN_TV
- int ret;
- ret = _bt_recover_adapter();
- if (ret != BLUETOOTH_ERROR_NONE)
- BT_ERR("_bt_recover_adapter is failed : %d", ret);
-#endif
- return;
-}
-
-gboolean _bt_terminate_service(gpointer user_data)
-{
- __bt_release_service();
-
- terminated = TRUE;
-
- BT_INFO_C("Terminating the bt-service daemon");
-
- if (main_loop != NULL) {
- g_main_loop_quit(main_loop);
- } else {
- BT_ERR("main_loop == NULL");
- exit(0);
- }
-
- return FALSE;
-}
-
-gboolean _bt_reliable_terminate_service(gpointer user_data)
-{
- _bt_deinit_proxys();
-
- _bt_clear_request_list();
-
- _bt_set_disabled(BLUETOOTH_ERROR_NONE);
-
- _bt_deinit_service_event_sender();
-
- _bt_service_unregister();
-
- terminated = TRUE;
-
- BT_INFO_C("### Terminating the bt-service daemon");
-
- if (main_loop != NULL)
- g_main_loop_quit(main_loop);
- else
- exit(0);
-
- return FALSE;
-}
-
-static gboolean __bt_check_bt_service(void *data)
-{
- bt_status_t status = BT_DEACTIVATED;
- bt_le_status_t le_status = BT_LE_DEACTIVATED;
- int bt_status = VCONFKEY_BT_STATUS_OFF;
- int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF;
- int flight_mode_deactivation = 0;
- int bt_off_due_to_timeout = 0;
-#if 0
- int ps_mode_deactivation = 0;
-#endif
-
- if (_is_name_acquired() == FALSE) {
- BT_ERR("dbus name is NOT acquired yet");
- return TRUE;
- }
-
- status = _bt_adapter_get_status();
- le_status = _bt_adapter_get_le_status();
- BT_DBG("State: %d, LE State: %d", status, le_status);
-
- if (TIZEN_PROFILE_TV) {
- if (_bt_get_enable_timer_id() == 0)
- _bt_enable_adapter();
- } else {
- if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0)
- BT_DBG("no bluetooth device info, so BT was disabled at previous session");
-
- if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0)
- BT_ERR("no bluetooth le info, so BT LE was disabled at previous session");
-
- if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_deactivation) != 0)
- BT_ERR("Fail to get the flight_mode_deactivation value");
-
-#if 0
- if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &ps_mode_deactivation) != 0)
- BT_ERR("Fail to get the ps_mode_deactivation value");
- }
-#endif
-
- if (vconf_get_int(BT_OFF_DUE_TO_TIMEOUT, &bt_off_due_to_timeout) != 0)
- BT_ERR("Fail to get BT_OFF_DUE_TO_TIMEOUT");
-
- if (bt_off_due_to_timeout) {
- /* Set the vconf flag to 0 here, if BT need to be enabled
- bt_off_due_to_timeout variable already hold the old value */
-
- if (vconf_set_int(BT_OFF_DUE_TO_TIMEOUT, 0) != 0)
- BT_ERR("Set vconf failed");
- }
-
-
- if ((bt_status != VCONFKEY_BT_STATUS_OFF || bt_off_due_to_timeout) &&
- (status == BT_DEACTIVATED)) {
- BT_DBG("Previous session was enabled.");
-
- /* Enable the BT */
- _bt_enable_adapter();
- } else if (bt_status == VCONFKEY_BT_STATUS_OFF && flight_mode_deactivation == 1) {
- _bt_enable_core();
- }
-
- if ((bt_le_status == VCONFKEY_BT_LE_STATUS_ON) && (le_status == BT_LE_DEACTIVATED)) {
- BT_DBG("Previous session was le enabled. Turn BT LE on automatically.");
-
- /* Enable the BT LE */
- _bt_enable_adapter_le();
- } else {
- status = _bt_adapter_get_status();
- le_status = _bt_adapter_get_le_status();
- BT_DBG("State: %d, LE State: %d", status, le_status);
-
- if ((status != BT_ACTIVATING && status != BT_ACTIVATED) &&
- (le_status != BT_LE_ACTIVATING && le_status != BT_LE_ACTIVATED)) {
- _bt_terminate_service(NULL);
- }
- }
- }
- return FALSE;
-}
-
-int _bt_service_initialize(void)
-{
- int ret;
-
- if (is_initialized == TRUE)
- return BLUETOOTH_ERROR_NONE;
-
- /* Security Initialization */
- if (_bt_service_cynara_init() != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Fail to init cynara");
- return EXIT_FAILURE;
- }
-
- _bt_service_register_vconf_handler();
- _bt_service_register_poweroff_event();
-
- /* Event reciever Init */
- ret = _bt_init_service_event_receiver();
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Fail to init event reciever");
- return ret;
- }
-
- /* Event sender Init */
- ret = _bt_init_service_event_sender();
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Fail to init event sender");
- return ret;
- }
-
- ret = _bt_init_hf_local_term_event_sender();
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Fail to init core event sender");
- return ret;
- }
-
- ret = _bt_service_register();
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Fail to register service");
- return ret;
- }
-
- ret = _bt_service_adapter_le_init();
- if (ret != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Fail to init le");
- return ret;
- }
-
- _bt_init_request_id();
-
- _bt_init_request_list();
-
-#ifndef GATT_NO_RELAY
- _bt_init_gatt_client_senders();
-#endif
-
- is_initialized = TRUE;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int main(void)
-{
- struct sigaction sa;
- BT_INFO_C("### Starting the bt-service daemon");
-
- memset(&sa, 0, sizeof(sa));
- sa.sa_sigaction = __bt_sigterm_handler;
- sa.sa_flags = SA_SIGINFO;
- sigaction(SIGINT, &sa, NULL);
- sigaction(SIGTERM, &sa, NULL);
-
- if (_bt_service_initialize() != BLUETOOTH_ERROR_NONE)
- return 0;
-
- g_timeout_add(500, (GSourceFunc)__bt_check_bt_service, NULL);
-
- if (terminated == TRUE) {
- __bt_release_service();
- return 0;
- }
-
- g_log_set_default_handler(__on_log_glib, NULL);
-
- main_loop = g_main_loop_new(NULL, FALSE);
-
- g_main_loop_run(main_loop);
- BT_DBG("g_main_loop_quit called!");
-
- if (main_loop != NULL)
- g_main_loop_unref(main_loop);
-
- if (terminated == FALSE)
- __bt_release_service();
-
- return 0;
-}
-
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<node name="/">
- <interface name="org.bluez.MediaPlayer">
- <method name="SetProperty">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="s" name="property"/>
- <arg type="v" name="value"/>
- </method>
- </interface>
- <interface name="org.freedesktop.DBus.Properties">
- <method name="Set">
- <arg type="s" name="property"/>
- <arg type="v" name="value"/>
- </method>
- </interface>
-</node>
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <gio/gio.h>
-#include <dlog.h>
-#include <string.h>
-#include <stdio.h>
-#include <syspopup_caller.h>
-#include <net_connection.h>
-
-#include "bluetooth-api.h"
-#include "bt-service-network.h"
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-#include "bt-service-util.h"
-#include "bt-internal-types.h"
-
-void _bt_util_addr_type_to_addr_net_string(char *address,
- unsigned char *addr)
-{
- ret_if(address == NULL);
- ret_if(addr == NULL);
-
- snprintf(address, BT_ADDRESS_STR_LEN, "%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", addr[0],
- addr[1], addr[2], addr[3], addr[4], addr[5]);
-}
-
-static connection_profile_h __bt_get_net_profile(void *connection,
- connection_iterator_type_e type,
- unsigned char *address)
-{
- int result;
- gchar **split_string;
- char net_address[BT_ADDRESS_STR_LEN + 1] = { 0 };
- char *profile_name = NULL;
- connection_profile_iterator_h profile_iter;
- connection_profile_h profile_h;
- connection_profile_type_e profile_type;
-
- retv_if(connection == NULL, NULL);
- retv_if(address == NULL, NULL);
-
- BT_DBG("net_conn: %x", connection);
-
- _bt_util_addr_type_to_addr_net_string(net_address, address);
-
- result = connection_get_profile_iterator(connection,
- type,
- &profile_iter);
- if (result != CONNECTION_ERROR_NONE) {
- BT_ERR("Fail to get profile iterator [%d]", result);
- return NULL;
- }
-
- while (connection_profile_iterator_has_next(profile_iter)) {
- profile_name = NULL;
- profile_h = NULL;
- split_string = NULL;
-
- if (connection_profile_iterator_next(profile_iter,
- &profile_h) != CONNECTION_ERROR_NONE) {
- BT_ERR("Fail to get profile handle");
- return NULL;
- }
-
- if (connection_profile_get_type(profile_h,
- &profile_type) != CONNECTION_ERROR_NONE) {
- BT_ERR("Fail to get profile type");
- continue;
- }
-
- if (profile_type != CONNECTION_PROFILE_TYPE_BT)
- continue;
-
- if (connection_profile_get_name(profile_h,
- &profile_name) != CONNECTION_ERROR_NONE) {
- BT_ERR("Fail to get profile name");
- return NULL;
- }
-
- split_string = g_strsplit(profile_name, "_", 3);
-
- g_free(profile_name);
-
- if (g_strv_length(split_string) < 3)
- continue;
-
- if (g_ascii_strcasecmp(split_string[2], net_address) == 0) {
- BT_DBG("matched profile");
- g_strfreev(split_string);
- return profile_h;
- }
-
- g_strfreev(split_string);
- }
-
- return NULL;
-}
-
-int _bt_is_network_connected(void *connection, unsigned char *address,
- gboolean *is_connected)
-{
- void *handle = NULL;
- handle = __bt_get_net_profile(connection,
- CONNECTION_ITERATOR_TYPE_CONNECTED,
- address);
- if (handle)
- *is_connected = TRUE;
- else
- *is_connected = FALSE;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-static void __bt_network_connect_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data)
-{
- GError *g_error = NULL;
- GVariant *out_param1 = NULL;
- GVariant *reply = NULL;
- bluetooth_device_address_t device_addr = { {0} };
- int result = BLUETOOTH_ERROR_NONE;
- bt_function_data_t *func_data;
- request_info_t *req_info;
-
- reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
- g_object_unref(proxy);
-
- if (reply == NULL) {
- BT_ERR("Network Connect Dbus Call Error");
- if (g_error) {
- BT_ERR("Error: %s\n", g_error->message);
- g_clear_error(&g_error);
- }
- result = BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_unref(reply);
-
- func_data = user_data;
- if (func_data == NULL) {
- /* Send reply */
- BT_ERR("func_data == NULL");
- goto done;
- }
-
- BT_ERR("func_data->req_id: %d", func_data->req_id);
- req_info = _bt_get_request_info(func_data->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- goto done;
- }
-
- if (req_info->context == NULL)
- goto done;
-
- _bt_convert_addr_string_to_type(device_addr.addr,
- func_data->address);
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("iv", result, out_param1));
-
- _bt_delete_request_list(req_info->req_id);
-
-done:
- if (func_data) {
- g_free(func_data->address);
- g_free(func_data);
- }
-}
-
-static void __bt_network_disconnect_cb(GDBusProxy *proxy, GAsyncResult *res,
- gpointer user_data)
-{
- GError *g_error = NULL;
- GVariant *out_param1 = NULL;
- GVariant *reply = NULL;
- bluetooth_device_address_t device_addr = { {0} };
- int result = BLUETOOTH_ERROR_NONE;
- bt_function_data_t *func_data;
- request_info_t *req_info;
-
- reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
- g_object_unref(proxy);
-
- if (reply == NULL) {
- BT_ERR("Network Disconnect Dbus Call Error");
- if (g_error) {
- BT_ERR("Error: %s\n", g_error->message);
- g_clear_error(&g_error);
- }
- result = BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_unref(reply);
-
- func_data = user_data;
- if (func_data == NULL) {
- /* Send reply */
- BT_ERR("func_data == NULL");
- goto done;
- }
- BT_ERR("func_data->req_id: %d", func_data->req_id);
- req_info = _bt_get_request_info(func_data->req_id);
- if (req_info == NULL) {
- BT_ERR("req_info == NULL");
- goto done;
- }
-
- if (g_error != NULL) {
- BT_ERR("Network Connect Dbus Call Error: %s\n", g_error->message);
- result = BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (req_info->context == NULL)
- goto done;
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("iv", result, out_param1));
-
- _bt_delete_request_list(req_info->req_id);
-
-done:
- if (func_data) {
- g_free(func_data->address);
- g_free(func_data);
- }
-}
-
-int _bt_network_activate(void)
-{
- int ret = BLUETOOTH_ERROR_NONE;
- char *adapter_path;
- GVariant *result = NULL;
- GError *err = NULL;
- GDBusConnection *conn;
- GDBusProxy *server_proxy;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_path = _bt_get_adapter_path();
- retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- server_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- adapter_path, BT_NETWORK_SERVER_INTERFACE, NULL, NULL);
- g_free(adapter_path);
-
- if (server_proxy == NULL) {
- BT_ERR("Failed to get the network server proxy\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- result = g_dbus_proxy_call_sync(server_proxy, "Register",
- g_variant_new("(ss)", NAP_UUID_NAME, NET_BRIDGE_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &err);
- if (result == NULL) {
- if (err != NULL) {
- g_dbus_error_strip_remote_error(err);
- BT_ERR("Network server register Error: %s\n", err->message);
- if (g_strcmp0(err->message, "Already Exists") == 0)
- ret = BLUETOOTH_ERROR_ALREADY_INITIALIZED;
- else
- ret = BLUETOOTH_ERROR_INTERNAL;
-
- g_error_free(err);
- }
- } else {
- g_variant_unref(result);
- }
-
- g_object_unref(server_proxy);
-
- return ret;
-}
-
-int _bt_network_deactivate(void)
-{
- char *adapter_path;
- GVariant *result = NULL;
- GError *err = NULL;
- GDBusConnection *conn;
- GDBusProxy *server_proxy;
- int ret = BLUETOOTH_ERROR_NONE;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_path = _bt_get_adapter_path();
- retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- server_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- adapter_path, BT_NETWORK_SERVER_INTERFACE, NULL, NULL);
- g_free(adapter_path);
-
- if (server_proxy == NULL) {
- BT_ERR("Failed to get the network server proxy\n");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- result = g_dbus_proxy_call_sync(server_proxy, "Unregister",
- g_variant_new("(s)", NAP_UUID_NAME),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &err);
- if (result == NULL) {
- if (err != NULL) {
- g_dbus_error_strip_remote_error(err);
- BT_ERR("Network server unregister Error: %s\n", err->message);
- if (g_strcmp0(err->message,
- "Operation currently not available") == 0) {
- ret = BLUETOOTH_ERROR_ALREADY_DEACTIVATED;
- } else {
- ret = BLUETOOTH_ERROR_INTERNAL;
- }
- g_error_free(err);
- }
- } else {
- g_variant_unref(result);
- }
-
- g_object_unref(server_proxy);
-
- return ret;
-}
-
-int _bt_network_connect(int request_id, int role,
- bluetooth_device_address_t *device_address)
-{
- const gchar *device_path = NULL;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- char remote_role[BLUETOOTH_UUID_STRING_MAX] = { 0 };
- bt_function_data_t *func_data;
- GDBusProxy *adapter_proxy;
- GDBusProxy *profile_proxy;
- GDBusConnection *conn;
- GVariant *result = NULL;
- GError*err = NULL;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- switch (role) {
- case BLUETOOTH_NETWORK_PANU_ROLE:
- g_strlcpy(remote_role, PANU_UUID_NAME, BLUETOOTH_UUID_STRING_MAX);
- break;
-
- case BLUETOOTH_NETWORK_NAP_ROLE:
- g_strlcpy(remote_role, NAP_UUID_NAME, BLUETOOTH_UUID_STRING_MAX);
- break;
-
- case BLUETOOTH_NETWORK_GN_ROLE:
- g_strlcpy(remote_role, GN_UUID_NAME, BLUETOOTH_UUID_STRING_MAX);
- break;
- default:
- BT_ERR("Unknown role");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice",
- g_variant_new("(s)", address),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &err);
- if (result == NULL) {
- BT_ERR("Error occurred in call to FindDevice");
- if (err) {
- BT_ERR("Error: %s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- device_path = g_variant_get_string(result, NULL);
- if (device_path == NULL) {
- BT_ERR("No paired device");
- g_variant_unref(result);
- return BLUETOOTH_ERROR_NOT_PAIRED;
- }
-
- profile_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_NETWORK_CLIENT_INTERFACE, NULL, NULL);
-
- g_variant_unref(result);
- retv_if(profile_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- func_data = g_malloc0(sizeof(bt_function_data_t));
- retv_if(func_data == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION);
-
- func_data->address = g_strdup(address);
- func_data->req_id = request_id;
-
- g_dbus_proxy_call(profile_proxy, "Connect",
- g_variant_new("(s)", remote_role),
- G_DBUS_CALL_FLAGS_NONE,
- BT_MAX_DBUS_TIMEOUT,
- NULL,
- (GAsyncReadyCallback)__bt_network_connect_cb,
- func_data);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_network_disconnect(int request_id,
- bluetooth_device_address_t *device_address)
-{
- const gchar *device_path = NULL;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- bt_function_data_t *func_data;
- GDBusProxy *adapter_proxy;
- GDBusProxy *profile_proxy;
- GDBusConnection *conn;
- GVariant *result = NULL;
- GError*err = NULL;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- adapter_proxy = _bt_get_adapter_proxy();
- retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice",
- g_variant_new("(s)", address),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, &err);
- if (result == NULL) {
- BT_ERR("Error occurred in call to FindDevice");
- if (err) {
- BT_ERR("Error: %s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- device_path = g_variant_get_string(result, NULL);
- if (device_path == NULL) {
- BT_ERR("No paired device");
- g_variant_unref(result);
- return BLUETOOTH_ERROR_NOT_PAIRED;
- }
-
- profile_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_NETWORK_CLIENT_INTERFACE, NULL, NULL);
-
- g_variant_unref(result);
- retv_if(profile_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- func_data = g_malloc0(sizeof(bt_function_data_t));
- retv_if(func_data == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION);
-
- func_data->address = g_strdup(address);
- func_data->req_id = request_id;
-
- g_dbus_proxy_call(profile_proxy, "Disconnect",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- BT_MAX_DBUS_TIMEOUT,
- NULL,
- (GAsyncReadyCallback)__bt_network_disconnect_cb,
- func_data);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_network_server_disconnect(int request_id,
- bluetooth_device_address_t *device_address)
-{
- gchar *adapter_path = NULL;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- bt_function_data_t *func_data;
- GDBusProxy *profile_proxy;
- GDBusConnection *conn;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_path = _bt_get_adapter_path();
- if (adapter_path == NULL) {
- BT_ERR("No adapter found");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- profile_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- adapter_path, BT_NETWORK_SERVER_INTERFACE, NULL, NULL);
- g_free(adapter_path);
- retv_if(profile_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- func_data = g_malloc0(sizeof(bt_function_data_t));
-
- func_data->address = g_strdup(address);
- func_data->req_id = request_id;
-
- g_dbus_proxy_call(profile_proxy, "Disconnect",
- g_variant_new("(s)", address),
- G_DBUS_CALL_FLAGS_NONE,
- BT_MAX_DBUS_TIMEOUT,
- NULL,
- (GAsyncReadyCallback)__bt_network_disconnect_cb,
- func_data);
-
- return BLUETOOTH_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <dlog.h>
-#include <string.h>
-#include <gio/gio.h>
-
-#include "bluetooth-api.h"
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-#include "bt-service-util.h"
-#include "bt-service-obex-agent.h"
-#include "bt-service-obex-server.h"
-
-static GDBusConnection *conn = NULL;
-static GDBusConnection *auth_reply_conn = NULL;
-static GSList *obex_agent_list = NULL;
-
-typedef struct {
- gchar *name;
- gchar *path;
-
- int openobex_id;
- int obex_agent_id;
- int obex_reply_id;
-
- /* callback data */
- gpointer authorize_data;
- gpointer release_data;
- gpointer request_data;
- gpointer progress_data;
- gpointer complete_data;
- gpointer error_data;
-
- /* callback function */
- bt_obex_authorize_cb authorize_cb;
- bt_obex_release_cb release_cb;
- bt_obex_request_cb request_cb;
- bt_obex_progress_cb progress_cb;
- bt_obex_complete_cb complete_cb;
- bt_obex_error_cb error_cb;
-} bt_obex_agent_info;
-
-static void __new_connection_method(GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *method_name,
- GVariant *parameters,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
-static const GDBusInterfaceVTable method_table = {
- __new_connection_method,
- NULL,
- NULL,
-};
-
-static const gchar obex_service_agent_xml1[] =
-"<node name='/'>"
-" <interface name='org.openobex.Agent'>"
-" <method name='Request'>"
-" <annotation name='org.freedesktop.DBus.GLib.Async' value=''/>"
-" <arg type='o' name='transfer'/>"
-" <arg type='s' name='name' direction='out'/>"
-" </method>"
-" <method name='Progress'>"
-" <annotation name='org.freedesktop.DBus.GLib.Async' value=''/>"
-" <arg type='o' name='transfer'/>"
-" <arg type='t' name='transferred'/>"
-" </method>"
-" <method name='Complete'>"
-" <annotation name='org.freedesktop.DBus.GLib.Async' value=''/>"
-" <arg type='o' name='transfer'/>"
-" </method>"
-" <method name='Release'>"
-" <annotation name='org.freedesktop.DBus.GLib.Async' value=''/>"
-" </method>"
-" <method name='Error'>"
-" <annotation name='org.freedesktop.DBus.GLib.Async' value=''/>"
-" <arg type='o' name='transfer'/>"
-" <arg type='s' name='message'/>"
-" </method>"
-" <method name='Authorize'>"
-" <annotation name='org.freedesktop.DBus.GLib.Async' value=''/>"
-" <arg type='o' name='objpath'/>"
-" <arg type='s' name='bdaddress'/>"
-" <arg type='s' name='name'/>"
-" <arg type='s' name='type'/>"
-" <arg type='i' name='length'/>"
-" <arg type='i' name='time'/>"
-" <arg type='s' name='filepath' direction='out'/>"
-" </method>"
-" </interface>"
-"</node>";
-
-static const gchar obex_service_agent_xml2[] =
-"<node name='/'>"
-" <interface name='org.bluez.obex.Agent1'>"
-" <method name='AuthorizePush'>"
-" <annotation name='org.freedesktop.DBus.GLib.Async' value=''/>"
-" <arg type='o' name='objpath'/>"
-" <arg type='s' name='filepath' direction='out'/>"
-" </method>"
-" </interface>"
-"</node>";
-
-static const gchar obex_service_reply_xml3[] =
-"<node name='/'>"
-" <interface name='org.bluez.obex.reply'>"
-" <method name='ReplyAuthorize'>"
-" <arg type='u' name='accept' direction='in'/>"
-" </method>"
-" </interface>"
-"</node>";
-
-static bt_obex_agent_info *__find_obex_agent_info(char *path)
-{
- GSList *l;
-
- for (l = obex_agent_list; l != NULL; l = l->next) {
- bt_obex_agent_info *info = l->data;
-
- if (g_strcmp0(info->path, path) == 0)
- return info;
- }
-
- return NULL;
-}
-
-
-static void __new_connection_method(GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *method_name,
- GVariant *parameters,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
-{
- BT_DBG("method_name %s", method_name);
- if (g_strcmp0(method_name, "AuthorizePush") == 0) {
- bt_obex_agent_info *info;
- char *path = NULL;
- info = __find_obex_agent_info((char *)object_path);
-
- if (info == NULL)
- goto fail;
-
- if (info->authorize_cb == NULL)
- goto fail;
-
- g_variant_get(parameters, "(&o)", &path);
-
- info->authorize_cb(invocation, path,
- info->authorize_data);
-
- return;
- } else if (g_strcmp0(method_name, "Authorize") == 0) {
- g_dbus_method_invocation_return_value(invocation, NULL);
- } else if (g_strcmp0(method_name, "Request") == 0) {
- char *sender;
- bt_obex_agent_info *info;
- GDBusProxy *proxy;
- char *path = NULL;
- char *name = NULL;
- GError *err = NULL;
-
- info = __find_obex_agent_info((char *)object_path);
-
- if (info == NULL)
- goto fail;
-
- if (conn == NULL)
- goto fail;
-
- sender = (char *)g_dbus_method_invocation_get_sender(invocation);
-
- if (info->name == NULL) {
- info->name = sender;
- } else {
- if (g_strcmp0(sender, info->name) != 0)
- goto fail;
- }
-
- if (info->request_cb == NULL)
- goto fail;
-
- g_variant_get(parameters, "(&o&s)", &path, &name);
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_CALL_FLAGS_NONE,
- NULL,
- BT_OBEX_SERVICE_NAME,
- path,
- BT_OBEX_TRANSFER_INTERFACE,
- NULL, &err);
-
- if (err) {
- BT_ERR("Dbus Err: %s", err->message);
- g_clear_error(&err);
- goto fail;
- }
-
- info->request_cb(invocation, proxy, info->request_data);
- g_object_unref(proxy);
- return;
-
- } else if (g_strcmp0(method_name, "Progress") == 0) {
- BT_DBG("+");
-
- bt_obex_agent_info *info;
- char *sender;
- char *path = NULL;
- gint64 transferred;
- GDBusProxy *proxy;
- GError *err = NULL;
-
- info = __find_obex_agent_info((char *)object_path);
-
- if (info == NULL)
- goto fail;
-
- if (conn == NULL)
- goto fail;
-
- sender = (char *)g_dbus_method_invocation_get_sender(invocation);
-
- if (g_strcmp0(sender, info->name) != 0)
- goto fail;
-
- if (info->progress_cb == NULL)
- goto fail;
-
- g_variant_get(parameters, "(&ot)", &path, &transferred);
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_CALL_FLAGS_NONE,
- NULL,
- BT_OBEX_SERVICE_NAME,
- path,
- BT_OBEX_TRANSFER_INTERFACE,
- NULL, &err);
-
- if (err) {
- BT_ERR("Dbus Err: %s", err->message);
- g_clear_error(&err);
- goto fail;
- }
-
- info->progress_cb(invocation, proxy, transferred, info->progress_data);
-
- g_object_unref(proxy);
-
- BT_DBG("-");
-
- return;
- } else if (g_strcmp0(method_name, "Error") == 0) {
- bt_obex_agent_info *info;
- char *sender;
- GDBusProxy *proxy;
- char *path, *message;
- GError *err = NULL;
-
- info = __find_obex_agent_info((char *)object_path);
-
- if (info == NULL)
- goto fail;
-
- if (conn == NULL)
- goto fail;
-
- sender = (char *)g_dbus_method_invocation_get_sender(invocation);
-
- if (g_strcmp0(sender, info->name) != 0)
- goto fail;
-
- if (info->error_cb == NULL)
- goto fail;
- g_variant_get(parameters, "(&o&s)", &path, &message);
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_CALL_FLAGS_NONE,
- NULL,
- BT_OBEX_SERVICE_NAME,
- path,
- BT_OBEX_TRANSFER_INTERFACE,
- NULL, &err);
- if (err) {
- BT_ERR("Dbus Err: %s", err->message);
- g_clear_error(&err);
- goto fail;
- }
- info->error_cb(invocation, proxy, message, info->progress_data);
-
- g_object_unref(proxy);
-
- return;
- } else if (g_strcmp0(method_name, "Complete") == 0) {
- bt_obex_agent_info *info;
- char *sender;
- GDBusProxy *proxy;
- char *path = NULL;
- GError *err = NULL;
-
- info = __find_obex_agent_info((char *)object_path);
-
- if (info == NULL)
- goto fail;
-
- if (conn == NULL)
- goto fail;
-
- sender = (char *)g_dbus_method_invocation_get_sender(invocation);
-
- if (g_strcmp0(sender, info->name) != 0)
- goto fail;
-
- if (info->complete_cb == NULL)
- goto fail;
-
- g_variant_get(parameters, "(&o)", &path);
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_CALL_FLAGS_NONE,
- NULL,
- BT_OBEX_SERVICE_NAME,
- path,
- BT_OBEX_TRANSFER_INTERFACE,
- NULL, &err);
- if (err) {
- BT_ERR("Dbus Err: %s", err->message);
- g_clear_error(&err);
- goto fail;
- }
-
- info->complete_cb(invocation, proxy, info->complete_data);
-
- g_object_unref(proxy);
-
- return;
- } else if (g_strcmp0(method_name, "Release") == 0) {
- bt_obex_agent_info *info;
- char *sender;
-
- info = __find_obex_agent_info((char *)object_path);
-
- if (info == NULL)
- goto fail;
-
- sender = (char *)g_dbus_method_invocation_get_sender(invocation);
-
- if (info->name) {
- /*In H2 if user denies auth,release will come without request and hence
- info->name will be NULL */
- if (g_strcmp0(sender, info->name) != 0)
- goto fail;
- }
-
- if (info->release_cb == NULL)
- goto fail;
-
- info->release_cb(invocation, info->release_data);
-
- return;
- } else if (g_strcmp0(method_name, "ReplyAuthorize") == 0) {
- const guint accept;
-
- g_variant_get(parameters, "(u)", &accept);
- BT_DBG("Accept: %d", accept);
-
- if (accept == 0) {
- BT_DBG("Transfer accepted");
- _bt_obex_server_reply_accept();
- } else {
- BT_ERR("Transfer denied");
- _bt_obex_server_reject_authorize();
- }
- }
-fail:
- BT_ERR("Fail case");
- g_dbus_method_invocation_return_value(invocation, NULL);
-}
-
-void _bt_obex_agent_new(char *path)
-{
- bt_obex_agent_info *info = NULL;
- GError *error = NULL;
-
- if (conn == NULL) {
- conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
- if (error != NULL) {
- BT_ERR("Fail to get dbus: %s", error->message);
- g_error_free(error);
- return;
- }
- auth_reply_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (error != NULL) {
- BT_ERR("Fail to get dbus: %s", error->message);
- g_error_free(error);
- return;
- }
- }
- info = (bt_obex_agent_info *)malloc(sizeof(bt_obex_agent_info));
- if (info) {
- memset(info, 0, sizeof(bt_obex_agent_info));
- info->path = g_strdup(path);
- obex_agent_list = g_slist_append(obex_agent_list, info);
- }
-}
-
-void _bt_obex_agent_destroy(char *path)
-{
- bt_obex_agent_info *info = NULL;
- info = __find_obex_agent_info(path);
- if (info == NULL) {
- BT_ERR("obex agent info not found on path %s", path);
- return;
- }
- obex_agent_list = g_slist_remove(obex_agent_list, info);
- if (info->path)
- g_free(info->path);
- if (info->name)
- g_free(info->name);
- if (info->openobex_id)
- g_dbus_connection_unregister_object(conn,
- info->openobex_id);
- if (info->obex_agent_id)
- g_dbus_connection_unregister_object(conn,
- info->obex_agent_id);
- if (info->obex_reply_id)
- g_dbus_connection_unregister_object(auth_reply_conn,
- info->obex_reply_id);
-
- g_free(info);
-}
-gboolean _bt_obex_setup(const char *path)
-{
- bt_obex_agent_info *info;
- GDBusProxy *proxy;
- GDBusNodeInfo *new_conn_node = NULL;
- GDBusNodeInfo *auth_reply_node = NULL;
- GError *err = NULL;
-
- info = __find_obex_agent_info((char *)path);
-
- retv_if(info == NULL, FALSE);
-
- proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- BT_OBEX_SERVICE_NAME,
- BT_OBEX_CLIENT_PATH,
- BT_OBEX_AGENT_INTERFACE,
- NULL,
- &err);
-
- g_free(info->name);
-
- if (proxy != NULL) {
- info->name = g_strdup(g_dbus_proxy_get_name(proxy));
- g_object_unref(proxy);
- } else {
- info->name = NULL;
- }
-
- new_conn_node = g_dbus_node_info_new_for_xml(obex_service_agent_xml1, NULL);
- if (new_conn_node == NULL)
- return FALSE;
-
- info->openobex_id = g_dbus_connection_register_object(conn, info->path,
- new_conn_node->interfaces[0],
- &method_table,
- NULL, NULL, &err);
- g_dbus_node_info_unref(new_conn_node);
- if (err) {
- BT_ERR("Dbus Err: %s", err->message);
- g_clear_error(&err);
- return FALSE;
- }
- if (info->openobex_id == 0)
- BT_ERR("Error while registering object");
-
- new_conn_node = g_dbus_node_info_new_for_xml(obex_service_agent_xml2, NULL);
- if (new_conn_node == NULL)
- return FALSE;
-
- info->obex_agent_id = g_dbus_connection_register_object(conn, info->path,
- new_conn_node->interfaces[0],
- &method_table,
- NULL, NULL, &err);
- g_dbus_node_info_unref(new_conn_node);
- if (info->obex_agent_id == 0)
- BT_ERR("Error while registering object");
- if (err) {
- BT_ERR("Dbus Err: %s", err->message);
- g_clear_error(&err);
- return FALSE;
- }
-
- auth_reply_node = g_dbus_node_info_new_for_xml(obex_service_reply_xml3, NULL);
-
- if (auth_reply_node == NULL) {
- BT_ERR("Fail to create the node info for xml");
- return FALSE;
- }
-
- info->obex_reply_id = g_dbus_connection_register_object(auth_reply_conn, info->path,
- auth_reply_node->interfaces[0], &method_table, NULL, NULL, &err);
- g_dbus_node_info_unref(auth_reply_node);
- if (info->obex_reply_id == 0)
- BT_ERR("Error while registering object");
- if (err) {
- BT_ERR("Dbus Err: %s", err->message);
- g_clear_error(&err);
- return FALSE;
- }
- return TRUE;
-}
-
-void _bt_obex_set_authorize_cb(char *object_path,
- bt_obex_authorize_cb func, gpointer data)
-{
- bt_obex_agent_info *info = __find_obex_agent_info(object_path);;
- if (info == NULL)
- return;
-
- info->authorize_cb = func;
- info->authorize_data = data;
-}
-
-void _bt_obex_set_release_cb(char *object_path,
- bt_obex_release_cb func, gpointer data)
-{
- bt_obex_agent_info *info = __find_obex_agent_info(object_path);;
- if (info == NULL)
- return;
-
- info->release_cb = func;
- info->release_data = data;
-}
-
-void _bt_obex_set_request_cb(char *object_path,
- bt_obex_request_cb func, gpointer data)
-{
- bt_obex_agent_info *info = __find_obex_agent_info(object_path);;
- if (info == NULL)
- return;
-
- info->request_cb = func;
- info->request_data = data;
-}
-
-void _bt_obex_set_progress_cb(char *object_path,
- bt_obex_progress_cb func, gpointer data)
-{
- bt_obex_agent_info *info = __find_obex_agent_info(object_path);;
- if (info == NULL)
- return;
-
- info->progress_cb = func;
- info->progress_data = data;
-}
-
-void _bt_obex_set_complete_cb(char *object_path,
- bt_obex_complete_cb func, gpointer data)
-{
- bt_obex_agent_info *info = __find_obex_agent_info(object_path);;
- if (info == NULL)
- return;
-
- info->complete_cb = func;
- info->complete_data = data;
-}
-
-void _bt_obex_set_error_cb(char *object_path,
- bt_obex_error_cb func, gpointer data)
-{
- bt_obex_agent_info *info = __find_obex_agent_info(object_path);;
- if (info == NULL)
- return;
-
- info->error_cb = func;
- info->error_data = data;
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<node name="/">
- <interface name="org.openobex.Agent">
- <method name="Request">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="transfer"/>
- <arg type="s" name="name" direction="out"/>
- </method>
-
- <method name="Progress">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="transfer"/>
- <arg type="t" name="transferred"/>
- </method>
-
- <method name="Complete">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="transfer"/>
- </method>
-
- <method name="Release">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- </method>
-
- <method name="Error">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="transfer"/>
- <arg type="s" name="message"/>
- </method>
- <method name="Authorize">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="objpath"/>
- <arg type="s" name="bdaddress"/>
- <arg type="s" name="name"/>
- <arg type="s" name="type"/>
- <arg type="i" name="length"/>
- <arg type="i" name="time"/>
- <arg type="s" name="filepath" direction="out"/>
- </method>
- </interface>
- <interface name="org.bluez.obex.Agent1">
- <method name="AuthorizePush">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="o" name="objpath"/>
- <arg type="s" name="filepath" direction="out"/>
- </method>
- </interface>
-</node>
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <glib.h>
-#include <dlog.h>
-#include <string.h>
-#include <dirent.h>
-#ifdef TIZEN_DPM_ENABLE
-#include "bt-service-dpm.h"
-#endif
-
-#include <vconf.h>
-
-#include <gio/gio.h>
-
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-#include "bt-service-util.h"
-#include "bt-service-obex-agent.h"
-#include "bt-service-obex-server.h"
-#include "bt-service-agent.h"
-
-#define DBUS_TIMEOUT 20 * 1000 /* 20 Seconds */
-#define BT_OBEX_SERVER_AGENT_PATH "/org/obex/server_agent"
-
-#define BT_OBEX_SERVICE "org.bluez.obex"
-#define BT_OBEX_MANAGER "org.bluez.obex.AgentManager1"
-#define BT_OBEX_PATH "/org/bluez/obex"
-
-#define BT_OBEX_PATH_PREFIX "/opt/usr/media"
-#define BT_OBEX_DEFAULT_PATH "/opt/usr/home/owner/media"
-#define BT_OBEX_PATH_MAX_LENGTH 255
-
-
-typedef struct {
- char *filename;
- char *file_path;
- char *path;
- char *type;
- char *device_name;
- int transfer_id;
- gint64 file_size;
- gint64 progress;
- char *address;
-} bt_transfer_info_t;
-
-typedef struct {
- GDBusMethodInvocation *reply_context;
- guint64 file_size;
- char *filename;
- char *file_path;
- char *device_name;
- char *transfer_path;
- char *address;
- unsigned char contact_auth_info[5];
-} bt_auth_info_t;
-
-typedef struct {
- char *dest_path;
- char *sender;
- int app_pid;
-} bt_server_info_t;
-
-typedef struct {
- GDBusProxy *proxy;
- int server_type;
- int accept_id;
- bt_auth_info_t *auth_info;
- bt_server_info_t *native_server;
- bt_server_info_t *custom_server;
-} bt_obex_agent_info_t;
-
-typedef struct {
- char *path;
- char *address;
- gboolean authorized;
-} bt_session_info_t;
-
-static GSList *transfers;
-static bt_obex_agent_info_t agent_info;
-static GSList *session_list = NULL;
-
-static bt_session_info_t *__bt_find_session_by_path(char *transfer_path)
-{
- GSList *l;
- bt_session_info_t *session;
-
- retv_if(transfer_path == NULL, NULL);
-
- for (l = session_list; l != NULL; l = l->next) {
- session = l->data;
-
- if (session == NULL)
- continue;
-
- if (g_strcmp0(session->path, transfer_path) == 0)
- return session;
- }
-
- return NULL;
-}
-
-static GQuark __bt_obex_error_quark(void)
-{
- static GQuark quark = 0;
- if (!quark)
- quark = g_quark_from_static_string("agent");
-
- return quark;
-}
-
-static bt_transfer_info_t *__bt_find_transfer_by_id(int transfer_id)
-{
- GSList *l;
- bt_transfer_info_t *transfer;
-
- for (l = transfers; l != NULL; l = l->next) {
- transfer = l->data;
-
- if (transfer == NULL)
- continue;
-
- if (transfer->transfer_id == transfer_id)
- return transfer;
- }
-
- return NULL;
-}
-
-bt_transfer_info_t *__bt_find_transfer_by_address(const char *address)
-{
- BT_DBG("+");
- GSList *l;
- bt_transfer_info_t *transfer;
-
- retv_if(address == NULL, NULL);
-
- for (l = transfers; l != NULL; l = l->next) {
- transfer = l->data;
-
- if (transfer == NULL)
- continue;
-
- if (g_strcmp0(transfer->address, address) == 0)
- return transfer;
- }
- BT_DBG("-");
- return NULL;
-}
-
-static bt_transfer_info_t *__bt_find_transfer_by_path(const char *transfer_path)
-{
- GSList *l;
- bt_transfer_info_t *transfer;
-
- retv_if(transfer_path == NULL, NULL);
-
- for (l = transfers; l != NULL; l = l->next) {
- transfer = l->data;
-
- if (transfer == NULL)
- continue;
-
- if (g_strcmp0(transfer->path, transfer_path) == 0)
- return transfer;
- }
-
- return NULL;
-}
-
-static void __bt_free_server_info(bt_server_info_t *server_info)
-{
- ret_if(server_info == NULL);
-
- g_free(server_info->sender);
- g_free(server_info->dest_path);
- g_free(server_info);
-}
-
-static void __bt_free_auth_info(bt_auth_info_t *auto_info)
-{
- ret_if(auto_info == NULL);
-
- g_free(auto_info->filename);
- g_free(auto_info->transfer_path);
- g_free(auto_info->device_name);
- g_free(auto_info->address);
- g_free(auto_info);
-}
-
-static void __bt_free_transfer_info(bt_transfer_info_t *transfer_info)
-{
- ret_if(transfer_info == NULL);
-
- g_free(transfer_info->path);
- g_free(transfer_info->filename);
- g_free(transfer_info->file_path);
- g_free(transfer_info->type);
- g_free(transfer_info->device_name);
- g_free(transfer_info->address);
- g_free(transfer_info);
-}
-
-void _bt_obex_check_pending_transfer(const char *address)
-{
- BT_DBG("+");
- GVariant *param = NULL;
- bt_transfer_info_t *transfer_info = __bt_find_transfer_by_address(address);
- if (transfer_info != NULL) {
- int result = BLUETOOTH_ERROR_CANCEL;
- param = g_variant_new("(issssstii)", result,
- transfer_info->filename,
- transfer_info->type,
- transfer_info->device_name,
- transfer_info->file_path,
- transfer_info->address,
- transfer_info->file_size,
- transfer_info->transfer_id,
- agent_info.server_type);
- _bt_send_event(BT_OPP_SERVER_EVENT,
- BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED,
- param);
- transfers = g_slist_remove(transfers, transfer_info);
- __bt_free_transfer_info(transfer_info);
- }
- BT_DBG("-");
-}
-
-static char *__bt_get_remote_device_name(const char *bdaddress)
-{
- char *device_path = NULL;
- char *name = NULL;
- GVariant *value;
- GVariant *result = NULL;
- GError *err = NULL;
- GDBusProxy *device_proxy;
- GDBusConnection *conn;
-
- retv_if(bdaddress == NULL, NULL);
-
- device_path = _bt_get_device_object_path((char *)bdaddress);
- retv_if(device_path == NULL, NULL);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, NULL);
- BT_INFO("Device_path %s", device_path);
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path,
- BT_PROPERTIES_INTERFACE,
- NULL, &err);
-
- g_free(device_path);
- retv_if(device_proxy == NULL, NULL);
-
- result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
- g_variant_new("(s)", BT_DEVICE_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL,
- &err);
- if (err) {
- BT_ERR("DBus Error : %s", err->message);
- g_clear_error(&err);
- return NULL;
- }
- if (result == NULL) {
- BT_ERR("g_dbus_proxy_call_sync function return NULL");
- return NULL;
- }
- g_variant_get(result, "(@a{sv})", &value);
-
- if (value) {
- GVariant *temp_value = g_variant_lookup_value(value, "Alias",
- G_VARIANT_TYPE_STRING);
- g_variant_get(temp_value, "s", &name);
- if (temp_value)
- g_variant_unref(temp_value);
-
- if (name != NULL)
- DBG_SECURE("Alias Name [%s]", name);
- else {
- temp_value = g_variant_lookup_value(value, "Name", G_VARIANT_TYPE_STRING);
- g_variant_get(temp_value, "s", &name);
- if (temp_value)
- g_variant_unref(temp_value);
- DBG_SECURE("Name = %s", name);
- }
- }
- g_variant_unref(result);
- g_object_unref(device_proxy);
- return name;
-}
-
-static void __bt_get_remote_device_name_authinfo(const char *bdaddress,
- char **device_name, unsigned char *auth_info)
-{
- char *device_path = NULL;
- char *name = NULL;
- gboolean is_alias_set;
- GVariant *value;
- GVariant *result = NULL;
- GError *err = NULL;
- GDBusProxy *device_proxy;
- GDBusConnection *conn;
-
- ret_if(bdaddress == NULL);
-
- device_path = _bt_get_device_object_path((char *)bdaddress);
- ret_if(device_path == NULL);
-
- conn = _bt_gdbus_get_system_gconn();
- ret_if(conn == NULL);
- BT_INFO("Device_path %s", device_path);
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path,
- BT_PROPERTIES_INTERFACE,
- NULL, &err);
-
- g_free(device_path);
- ret_if(device_proxy == NULL);
-
- result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
- g_variant_new("(s)", BT_DEVICE_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL,
- &err);
- if (err) {
- BT_ERR("DBus Error : %s", err->message);
- g_clear_error(&err);
- return;
- }
- if (result == NULL) {
- BT_ERR("g_dbus_proxy_call_sync function return NULL");
- return;
- }
- g_variant_get(result, "(@a{sv})", &value);
-
- if (value) {
- GVariant *temp_value = g_variant_lookup_value(value, "Alias",
- G_VARIANT_TYPE_STRING);
- g_variant_get(temp_value, "s", &name);
- if (temp_value)
- g_variant_unref(temp_value);
-
- if (name != NULL)
- DBG_SECURE("Alias Name [%s]", name);
- else {
- temp_value = g_variant_lookup_value(value, "Name", G_VARIANT_TYPE_STRING);
- g_variant_get(temp_value, "s", &name);
- if (temp_value)
- g_variant_unref(temp_value);
- DBG_SECURE("Name = %s", name);
- }
- temp_value = g_variant_lookup_value(value, "IsAliasSet", G_VARIANT_TYPE_BOOLEAN);
- if (temp_value) {
- is_alias_set = g_variant_get_boolean(temp_value);
- g_variant_unref(temp_value);
- } else {
- is_alias_set = FALSE;
- }
-
- if (is_alias_set == FALSE)
- __bt_get_auth_info(value, (char *)auth_info);
- }
- g_variant_unref(result);
- g_object_unref(device_proxy);
-
- *device_name = g_strdup(name);
- g_free(name);
- return;
-}
-
-static int __bt_get_transfer_id(const char *path)
-{
- char *tmp = NULL;
- if (path == NULL)
- return -1;
-
- tmp = strrchr(path, 'r') + 1;
- retv_if(tmp == NULL, -1);
-
- return atoi(tmp);
-}
-
-static GDBusProxy *__bt_get_transfer_proxy(const char *transfer_path)
-{
- GDBusConnection *conn;
- GDBusProxy *proxy;
- GError *err = NULL;
-
- conn = _bt_gdbus_get_session_gconn();
- retv_if(conn == NULL, NULL);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_OBEX_SERVICE_NAME,
- transfer_path,
- BT_OBEX_TRANSFER_INTERFACE,
- NULL, &err);
-
- if (err) {
- BT_ERR("Error : %s", err->message);
- g_clear_error(&err);
- return NULL;
- }
-
- return proxy;
-}
-
-static GDBusProxy *__bt_get_transfer_properties_proxy(const char *transfer_path)
-{
- GDBusConnection *conn;
- GDBusProxy *proxy;
- GError *err = NULL;
- conn = _bt_gdbus_get_session_gconn();
- retv_if(conn == NULL, NULL);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_OBEX_SERVICE_NAME,
- transfer_path,
- BT_PROPERTIES_INTERFACE,
- NULL, &err);
- if (err) {
- BT_ERR("Error : %s", err->message);
- g_clear_error(&err);
- return NULL;
- }
- return proxy;
-}
-
-static int __bt_get_transfer_properties(bt_transfer_info_t *transfer_info,
- const char *transfer_path)
-{
- GDBusProxy *transfer_proxy;
- GVariant *result = NULL;
- GError *err = NULL;
- GVariantIter *iter = NULL;
- BT_CHECK_PARAMETER(transfer_info, return);
- BT_CHECK_PARAMETER(transfer_path, return);
-
- transfer_proxy = __bt_get_transfer_properties_proxy(transfer_path);
-
- retv_if(transfer_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(transfer_proxy, "GetAll",
- g_variant_new("(s)", BT_OBEX_TRANSFER_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL,
- &err);
-
- if (err) {
- BT_ERR("DBus Error : %s", err->message);
- g_clear_error(&err);
- goto fail;
- }
- if (result == NULL) {
- BT_ERR("g_dbus_proxy_call_sync function return NULL");
- goto fail;
- }
-
- g_variant_get(result, "(a{sv})", &iter);
- g_variant_unref(result);
- if (iter) {
- const gchar *key;
- GVariant *val;
- gsize len = 0;
- while (g_variant_iter_loop(iter, "{sv}", &key, &val)) {
- if (g_strcmp0(key, "Operation") == 0) {
- transfer_info->type = g_variant_dup_string(val, &len);
- } else if (g_strcmp0(key, "Name") == 0) {
- transfer_info->filename = g_variant_dup_string(val, &len);
- } else if (g_strcmp0(key, "Size") == 0) {
- transfer_info->file_size = g_variant_get_uint64(val);
- } else if (g_strcmp0(key, "Address") == 0) {
- transfer_info->address = g_variant_dup_string(val, &len);
- BT_INFO("addressss %s", transfer_info->address);
- } else if (g_strcmp0(key, "Filename") == 0) {
- transfer_info->file_path = g_variant_dup_string(val, &len);
- if (!transfer_info->file_path)
- transfer_info->file_path = g_strdup(transfer_info->filename);
- }
- }
- g_variant_iter_free(iter);
-
- if (transfer_info->address == NULL)
- goto fail;
- transfer_info->device_name = __bt_get_remote_device_name(transfer_info->address);
- transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
- if (!transfer_info->device_name)
- transfer_info->device_name = g_strdup(transfer_info->address);
-
- if (transfer_info->type == NULL)
- goto fail;
-
- transfer_info->path = g_strdup(transfer_path);
- }
-
- g_object_unref(transfer_proxy);
- return BLUETOOTH_ERROR_NONE;
-
-fail:
- g_object_unref(transfer_proxy);
- return BLUETOOTH_ERROR_INTERNAL;
-}
-
-static gboolean __bt_authorize_cb(GDBusMethodInvocation *context,
- const char *path,
- gpointer user_data)
-{
- char *device_name = NULL;
- unsigned char auth_info[5] = {0, };
- int result = BLUETOOTH_ERROR_NONE;
- GDBusProxy *transfer_properties_proxy;
- char * bdaddress = NULL;
- GVariant *ret;
- GVariantIter *iter;
- GVariant *param = NULL;
- GError *err = NULL;
- bt_session_info_t *session_info = NULL;
-
- BT_DBG(" path [%s] \n", path);
-
- transfer_properties_proxy = __bt_get_transfer_properties_proxy(path);
-
- retv_if(transfer_properties_proxy == NULL, FALSE);
-
- ret = g_dbus_proxy_call_sync(transfer_properties_proxy, "GetAll",
- g_variant_new("(s)", BT_OBEX_TRANSFER_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL,
- &err);
- if (err) {
- BT_ERR("DBus Error : %s", err->message);
- g_clear_error(&err);
- return FALSE;
- }
- if (ret == NULL) {
- BT_ERR("g_dbus_proxy_call_sync function return NULL");
- return FALSE;
- }
- g_variant_get(ret, "(a{sv})", &iter);
- g_variant_unref(ret);
- if (iter == NULL) {
- g_object_unref(transfer_properties_proxy);
- return FALSE;
- }
-
- __bt_free_auth_info(agent_info.auth_info);
-
- agent_info.auth_info = g_malloc(sizeof(bt_auth_info_t));
-
- memset(agent_info.auth_info, 0, sizeof(bt_auth_info_t));
-
- agent_info.auth_info->reply_context = context;
-
- agent_info.auth_info->transfer_path = g_strdup(path);
-
-#ifdef TIZEN_DPM_ENABLE
- if (_bt_dpm_get_allow_bluetooth_mode() == DPM_BT_HANDSFREE_ONLY) {
- /* Free auth info in next function */
- _bt_obex_server_reject_authorize();
- return FALSE;
- }
-#endif
- if (iter) {
- const gchar *key;
- GVariant *val;
- gsize len = 0;
- while (g_variant_iter_loop(iter, "{sv}", &key, &val)) {
- if (g_strcmp0(key, "Name") == 0)
- agent_info.auth_info->filename = g_variant_dup_string(val, &len);
- else if (g_strcmp0(key, "Address") == 0)
- bdaddress = g_variant_dup_string(val, &len);
- else if (g_strcmp0(key, "Size") == 0)
- agent_info.auth_info->file_size = g_variant_get_uint64(val);
- }
- g_variant_iter_free(iter);
- }
-
- __bt_get_remote_device_name_authinfo(bdaddress, &device_name, auth_info);
-
- if (!device_name)
- device_name = g_strdup(bdaddress);
-
- agent_info.auth_info->address = g_strdup(bdaddress);
- agent_info.auth_info->device_name = device_name;
- memcpy(agent_info.auth_info->contact_auth_info, auth_info, 5);
-
- session_info = __bt_find_session_by_path((char *)path);
- if (NULL == session_info) {
- session_info = g_malloc0(sizeof(bt_session_info_t));
- session_info->path = g_strdup(path);
- session_info->address = g_strdup(bdaddress);
- session_info->authorized = FALSE;
- session_list = g_slist_append(session_list, session_info);
- }
-
- g_object_unref(transfer_properties_proxy);
- g_free(bdaddress);
-
- if (agent_info.server_type == BT_CUSTOM_SERVER) {
- /* No need to send the event */
- _bt_obex_server_accept_authorize(agent_info.auth_info->filename, FALSE);
- return TRUE;
- }
-
- if (session_info->authorized == FALSE) {
- _bt_launch_system_popup(BT_AGENT_EVENT_EXCHANGE_REQUEST, device_name,
- auth_info, NULL, NULL, BT_OBEX_SERVER_AGENT_PATH);
- } else {
- param = g_variant_new("(istss)", result,
- agent_info.auth_info->filename,
- agent_info.auth_info->file_size,
- agent_info.auth_info->address,
- agent_info.auth_info->device_name);
- _bt_send_event(BT_OPP_SERVER_EVENT,
- BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE, param);
- }
-
- return TRUE;
-}
-
-void _bt_obex_transfer_started(const char *transfer_path)
-{
- bt_transfer_info_t *transfer_info;
- request_info_t *req_info;
- GVariant *out_param1 = NULL;
- GVariant *param = NULL;
- GVariantBuilder *builder = NULL;
- int result = BLUETOOTH_ERROR_NONE;
- int i = 0;
-
- BT_DBG("%s", transfer_path);
-
- transfer_info = g_malloc0(sizeof(bt_transfer_info_t));
-
- if (agent_info.auth_info != NULL
- && g_strcmp0(transfer_path, agent_info.auth_info->transfer_path) == 0) {
- transfer_info->filename = g_strdup(agent_info.auth_info->filename);
- transfer_info->file_size = agent_info.auth_info->file_size;
- transfer_info->type = g_strdup(TRANSFER_PUT);
- transfer_info->path = g_strdup(agent_info.auth_info->transfer_path);
- transfer_info->device_name = g_strdup(agent_info.auth_info->device_name);
- transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
- transfer_info->file_path = agent_info.auth_info->file_path;
- transfer_info->address = g_strdup(agent_info.auth_info->address);
-
- } else {
- if (__bt_get_transfer_properties(transfer_info, transfer_path) < 0) {
- BT_ERR("Get Properties failed");
- __bt_free_transfer_info(transfer_info);
- return;
- }
- agent_info.server_type = BT_FTP_SERVER;
- }
-
- if (agent_info.server_type == BT_CUSTOM_SERVER) {
- if (agent_info.custom_server == NULL) {
- __bt_free_transfer_info(transfer_info);
- __bt_free_auth_info(agent_info.auth_info);
- agent_info.auth_info = NULL;
- return;
- }
-
- req_info = _bt_get_request_info(agent_info.accept_id);
- if (req_info == NULL || req_info->context == NULL) {
- BT_ERR("info is NULL");
- goto done;
- }
-
- agent_info.accept_id = 0;
- result = BLUETOOTH_ERROR_NONE;
- GArray *g_out_param1 = NULL;
- g_out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
- if (out_param1 == NULL) {
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- g_out_param1->data, g_out_param1->len,
- TRUE, NULL, NULL);
- }
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("(iv)", result, out_param1));
- g_array_free(g_out_param1, TRUE);
- _bt_delete_request_list(req_info->req_id);
- }
-done:
- transfers = g_slist_append(transfers, transfer_info);
-
- BT_DBG("Transfer id %d", transfer_info->transfer_id);
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
- for (i = 0; i < 5; i++) {
- if (agent_info.auth_info)
- g_variant_builder_add(builder, "y", agent_info.auth_info->contact_auth_info[i]);
- }
-
- param = g_variant_new("(isssstii(ay))", result,
- transfer_info->device_name,
- transfer_info->filename,
- transfer_info->type,
- transfer_info->address,
- transfer_info->file_size,
- transfer_info->transfer_id,
- agent_info.server_type,
- builder);
-
- __bt_free_auth_info(agent_info.auth_info);
- agent_info.auth_info = NULL;
-
- g_variant_builder_unref(builder);
-
- _bt_send_event(BT_OPP_SERVER_EVENT,
- BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
- param);
-}
-
-void _bt_obex_transfer_progress(const char *transfer_path,
- guint64 transferred)
-{
- BT_DBG("+");
- bt_transfer_info_t *transfer_info;
- int current_progress = 0;
- int previous_progress;
- GVariant *param = NULL;
- int result = BLUETOOTH_ERROR_NONE;
-
- transfer_info = __bt_find_transfer_by_path(transfer_path);
- ret_if(transfer_info == NULL);
-
- current_progress = (int)(((gdouble)transferred /
- (gdouble)transfer_info->file_size) * 100);
-
- previous_progress = (int)(((gdouble)transfer_info->progress /
- (gdouble)transfer_info->file_size) * 100);
-
- if (current_progress == previous_progress) {
- BT_DBG("Same Percentage Value: Do not emit Signal");
- return;
- }
-
- transfer_info->progress = transferred;
- param = g_variant_new("(isssstiii)", result,
- transfer_info->filename,
- transfer_info->type,
- transfer_info->device_name,
- transfer_info->address,
- transfer_info->file_size,
- transfer_info->transfer_id,
- current_progress,
- agent_info.server_type);
- _bt_send_event(BT_OPP_SERVER_EVENT,
- BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS,
- param);
- BT_DBG("-");
-}
-
-void _bt_obex_transfer_completed(const char *transfer_path, gboolean success)
-{
- bt_transfer_info_t *transfer_info;
- GVariantBuilder *builder = NULL;
- GVariant *param = NULL;
- int result;
- int i = 0;
- BT_DBG("Transfer [%s] Success [%d] \n", transfer_path, success);
-
- result = (success == TRUE) ? BLUETOOTH_ERROR_NONE
- : BLUETOOTH_ERROR_CANCEL;
-
- transfer_info = __bt_find_transfer_by_path(transfer_path);
-
- if (transfer_info == NULL) {
- BT_DBG("Very small files receiving case, did not get Active status from obexd");
- if (agent_info.auth_info == NULL ||
- g_strcmp0(transfer_path,
- agent_info.auth_info->transfer_path) != 0) {
- BT_ERR("auth_info is NULL, returning");
- return;
- }
-
- transfer_info = g_new0(bt_transfer_info_t, 1);
-
- transfer_info->filename = g_strdup(agent_info.auth_info->filename);
- transfer_info->file_size = agent_info.auth_info->file_size;
- transfer_info->type = g_strdup(TRANSFER_PUT);
- transfer_info->path = g_strdup(agent_info.auth_info->transfer_path);
- transfer_info->device_name = g_strdup(agent_info.auth_info->device_name);
- transfer_info->transfer_id = __bt_get_transfer_id(transfer_path);
- transfer_info->file_path = agent_info.auth_info->file_path;
- transfer_info->address = g_strdup(agent_info.auth_info->address);
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
- for (i = 0; i < 5; i++)
- g_variant_builder_add(builder, "y", agent_info.auth_info->contact_auth_info[i]);
-
- param = g_variant_new("(isssstii(ay))", result,
- transfer_info->filename,
- transfer_info->type,
- transfer_info->device_name,
- transfer_info->address,
- transfer_info->file_size,
- transfer_info->transfer_id,
- agent_info.server_type,
- builder);
- _bt_send_event(BT_OPP_SERVER_EVENT,
- BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED,
- param);
- g_variant_builder_unref(builder);
- }
- param = g_variant_new("(issssstii)", result,
- transfer_info->filename,
- transfer_info->type,
- transfer_info->device_name,
- transfer_info->file_path,
- transfer_info->address,
- transfer_info->file_size,
- transfer_info->transfer_id,
- agent_info.server_type);
- _bt_send_event(BT_OPP_SERVER_EVENT,
- BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED,
- param);
- transfers = g_slist_remove(transfers, transfer_info);
- __bt_free_transfer_info(transfer_info);
-}
-
-void _bt_obex_transfer_connected(const char *obj_path)
-{
- BT_DBG("+");
-
- int result = BLUETOOTH_ERROR_NONE;
- GVariant *param = NULL;
- bt_transfer_info_t *transfer_info = NULL;
-
- transfer_info = g_new0(bt_transfer_info_t, 1);
- __bt_get_transfer_properties(transfer_info, obj_path);
- INFO_SECURE("Address[%s] Name[%s] TransferID[%d] ", transfer_info->address,
- transfer_info->device_name, transfer_info->transfer_id);
-
- param = g_variant_new("(issi)", result, transfer_info->address,
- transfer_info->device_name, transfer_info->transfer_id);
-
- _bt_send_event(BT_OPP_SERVER_EVENT,
- BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_CONNECTED,
- param);
-
- __bt_free_transfer_info(transfer_info);
- BT_DBG("-");
-}
-
-void _bt_obex_transfer_disconnected(char * obj_path)
-{
- BT_DBG("+");
-
- int result = BLUETOOTH_ERROR_NONE;
- GVariant *param = NULL;
- bt_session_info_t *session = NULL;
- int transfer_id = -1;
-
- session = __bt_find_session_by_path(obj_path);
- ret_if(session == NULL);
-
- transfer_id = __bt_get_transfer_id(obj_path);
- DBG_SECURE("transfer_id: [%d]", transfer_id);
-
- DBG_SECURE("%s", session->address);
- param = g_variant_new("(isi)", result, session->address, transfer_id);
- _bt_send_event(BT_OPP_SERVER_EVENT,
- BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_DISCONNECTED,
- param);
- session_list = g_slist_remove(session_list, session);
- g_free(session->address);
- g_free(session->path);
- g_free(session);
- BT_DBG("-");
-}
-
-int _bt_register_obex_server(void)
-{
- GDBusConnection *g_conn;
- GDBusProxy *manager_proxy;
- GVariant *result = NULL;
- GError *g_error = NULL;
-
- /* Get the session bus. */
- g_conn = _bt_gdbus_get_session_gconn();
- retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_obex_agent_new(BT_OBEX_SERVER_AGENT_PATH);
-
- _bt_obex_setup(BT_OBEX_SERVER_AGENT_PATH);
-
- _bt_obex_set_authorize_cb(BT_OBEX_SERVER_AGENT_PATH,
- __bt_authorize_cb, NULL);
-
- manager_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_OBEX_SERVICE,
- BT_OBEX_PATH,
- BT_OBEX_MANAGER,
- NULL, &g_error);
-
- if (manager_proxy == NULL)
- return BLUETOOTH_ERROR_INTERNAL;
-
- result = g_dbus_proxy_call_sync(manager_proxy, "RegisterAgent",
- g_variant_new("(o)", BT_OBEX_SERVER_AGENT_PATH),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL,
- &g_error);
-
- if (g_error != NULL) {
- BT_ERR("Agent registration failed: %s\n", g_error->message);
- g_object_unref(manager_proxy);
- g_error_free(g_error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (result)
- g_variant_unref(result);
-
- agent_info.proxy = manager_proxy;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_unregister_obex_server(void)
-{
- GVariant *result = NULL;
- GError *g_error = NULL;
-
- retv_if(agent_info.proxy == NULL,
- BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(agent_info.proxy, "UnregisterAgent",
- g_variant_new("(o)", BT_OBEX_SERVER_AGENT_PATH),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL,
- &g_error);
- if (g_error != NULL) {
- BT_ERR("Agent unregistration failed: %s", g_error->message);
- g_error_free(g_error);
- }
-
- if (result)
- g_variant_unref(result);
-
- _bt_obex_agent_destroy(BT_OBEX_SERVER_AGENT_PATH);
- g_object_unref(agent_info.proxy);
- agent_info.proxy = NULL;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-gboolean __bt_check_folder_path(const char *dest_path)
-{
- DIR *dp;
-
- retv_if(dest_path == NULL, FALSE);
-
- dp = opendir(dest_path);
-
- if (dp == NULL) {
- BT_ERR("The directory does not exist");
- return FALSE;
- }
-
- closedir(dp);
-
- return TRUE;
-}
-
-char *__bt_transfer_folder_path(char *dest_path)
-{
- char *dst_path = (char *)g_malloc0(BT_OBEX_PATH_MAX_LENGTH);
- if (g_str_has_prefix(dest_path, BT_OBEX_PATH_PREFIX))
- snprintf(dst_path, BT_OBEX_PATH_MAX_LENGTH, BT_OBEX_DEFAULT_PATH"%s", dest_path + strlen(BT_OBEX_PATH_PREFIX));
- else
- snprintf(dst_path, BT_OBEX_PATH_MAX_LENGTH, "%s", dest_path);
-
- BT_INFO("obex transfed path : %s", dst_path);
- return dst_path;
-}
-
-int _bt_obex_server_allocate(char *sender, const char *dest_path, int app_pid, gboolean is_native)
-{
- BT_DBG("+");
-
- char *dst_path;
- dst_path = __bt_transfer_folder_path((char *)dest_path);
-
- if (__bt_check_folder_path(dst_path) == FALSE) {
- g_free(dst_path);
- return BLUETOOTH_ERROR_INVALID_PARAM;
- }
-
- if (is_native == TRUE) {
- if (agent_info.native_server) {
- BT_ERR("obex native server busy");
- g_free(dst_path);
- return BLUETOOTH_ERROR_DEVICE_BUSY;
- }
-
- /* Force to change the control to native */
- agent_info.native_server = g_malloc0(sizeof(bt_server_info_t));
- agent_info.native_server->dest_path = g_strdup(dst_path);
- agent_info.native_server->sender = g_strdup(sender);
- agent_info.native_server->app_pid = app_pid;
- agent_info.server_type = BT_NATIVE_SERVER;
- _bt_unregister_osp_server_in_agent(BT_OBEX_SERVER, NULL);
- } else {
- if (agent_info.custom_server) {
- BT_ERR("obex custom server busy");
- g_free(dst_path);
- return BLUETOOTH_ERROR_DEVICE_BUSY;
- }
-
- /* Force to change the control to custom */
- agent_info.custom_server = g_malloc0(sizeof(bt_server_info_t));
- agent_info.custom_server->dest_path = g_strdup(dst_path);
- agent_info.custom_server->sender = g_strdup(sender);
- agent_info.custom_server->app_pid = app_pid;
- agent_info.server_type = BT_CUSTOM_SERVER;
- _bt_register_osp_server_in_agent(BT_OBEX_SERVER, NULL, NULL, -1);
- }
-
- g_free(dst_path);
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_obex_server_deallocate(int app_pid, gboolean is_native)
-{
- if (is_native == TRUE) {
- retv_if(agent_info.native_server == NULL,
- BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
-
- retv_if(agent_info.native_server->app_pid != app_pid,
- BLUETOOTH_ERROR_ACCESS_DENIED);
-
- __bt_free_server_info(agent_info.native_server);
- agent_info.native_server = NULL;
-
- /* Change the control to custom */
- if (agent_info.custom_server) {
- agent_info.server_type = BT_CUSTOM_SERVER;
- _bt_register_osp_server_in_agent(BT_OBEX_SERVER,
- NULL, NULL, -1);
- }
- } else {
- retv_if(agent_info.custom_server == NULL,
- BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST);
-
- retv_if(agent_info.custom_server->app_pid != app_pid,
- BLUETOOTH_ERROR_ACCESS_DENIED);
-
- __bt_free_server_info(agent_info.custom_server);
- agent_info.custom_server = NULL;
-
- _bt_unregister_osp_server_in_agent(BT_OBEX_SERVER, NULL);
-
- /* Change the control to native */
- if (agent_info.native_server)
- agent_info.server_type = BT_NATIVE_SERVER;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_obex_server_accept_authorize(const char *filename, gboolean is_native)
-{
- char file_path[BT_FILE_PATH_MAX] = { 0 };
- bt_server_info_t *server_info;
-
- BT_CHECK_PARAMETER(filename, return);
-
- retv_if(agent_info.auth_info == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- retv_if(agent_info.auth_info->reply_context == NULL,
- BLUETOOTH_ERROR_INTERNAL);
-
- if (is_native == TRUE)
- server_info = agent_info.native_server;
- else
- server_info = agent_info.custom_server;
-
- retv_if(server_info == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- if (server_info->dest_path != NULL)
- snprintf(file_path, sizeof(file_path), "%s/%s",
- server_info->dest_path, filename);
- else
- snprintf(file_path, sizeof(file_path), "%s", filename);
-
- g_dbus_method_invocation_return_value(agent_info.auth_info->reply_context,
- g_variant_new("(s)", &file_path));
- agent_info.auth_info->reply_context = NULL;
- agent_info.auth_info->file_path = g_strdup(file_path);
- g_free(agent_info.auth_info->filename);
- agent_info.auth_info->filename = g_strdup(filename);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_obex_server_reply_accept(void)
-{
- GVariant *param = NULL;
- bt_session_info_t *session_info = NULL;
- int result = BLUETOOTH_ERROR_NONE;
- param = g_variant_new("(istss)", result,
- agent_info.auth_info->filename,
- agent_info.auth_info->file_size,
- agent_info.auth_info->address,
- agent_info.auth_info->device_name);
- BT_INFO("Send Obex Authorize");
- _bt_send_event(BT_OPP_SERVER_EVENT, BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE, param);
-
- session_info = __bt_find_session_by_path(agent_info.auth_info->transfer_path);
-
- if (NULL == session_info)
- BT_ERR("Couldn't get the session info from the list");
- else
- session_info->authorized = TRUE;
-}
-
-int _bt_obex_server_reject_authorize(void)
-{
- GError *g_error;
-
- retv_if(agent_info.auth_info->reply_context == NULL,
- BLUETOOTH_ERROR_INTERNAL);
-
- g_error = g_error_new(__bt_obex_error_quark(),
- BT_OBEX_AGENT_ERROR_CANCEL,
- "CancelledByUser");
-
- g_dbus_method_invocation_return_gerror(agent_info.auth_info->reply_context,
- g_error);
- g_error_free(g_error);
-
- __bt_free_auth_info(agent_info.auth_info);
- agent_info.auth_info = NULL;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_obex_server_set_destination_path(const char *dest_path,
- gboolean is_native)
-{
- bt_server_info_t *server_info;
- BT_CHECK_PARAMETER(dest_path, return);
-
- char *dst_path;
- dst_path = __bt_transfer_folder_path((char *)dest_path);
-
- DIR *dp = NULL;
-
- dp = opendir(dst_path);
-
- if (dp == NULL) {
- BT_ERR("The directory does not exist");
- g_free(dst_path);
- return BLUETOOTH_ERROR_INVALID_PARAM;
- }
-
- closedir(dp);
-
- if (is_native == TRUE)
- server_info = agent_info.native_server;
- else
- server_info = agent_info.custom_server;
-
- if (!server_info) {
- BT_ERR("obex server info is NULL");
- g_free(dst_path);
- return BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST;
- }
-
- g_free(server_info->dest_path);
- server_info->dest_path = g_strdup(dst_path);
-
- g_free(dst_path);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_obex_server_set_root(const char *root)
-{
- GVariant *result = NULL;
- GError *g_error = NULL;
- GVariant *folder = NULL;
- char *string = "Root";
- DIR *dp = NULL;
-
- BT_CHECK_PARAMETER(root, return);
-
- char *dst_root;
- dst_root = __bt_transfer_folder_path((char *)root);
-
- if (!agent_info.proxy) {
- BT_ERR("obex agent_info proxy error");
- g_free(dst_root);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- dp = opendir(dst_root);
-
- if (dp == NULL) {
- BT_ERR("The directory does not exist");
- g_free(dst_root);
- return BLUETOOTH_ERROR_INVALID_PARAM;
- }
-
- closedir(dp);
-
- folder = g_variant_new_string(dst_root);
- result = g_dbus_proxy_call_sync(agent_info.proxy, "SetProperty",
- g_variant_new("(sv)", string, folder),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL,
- &g_error);
-
- if (g_error) {
- BT_ERR("SetProperty Fail: %s", g_error->message);
- g_error_free(g_error);
- g_free(dst_root);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (result)
- g_variant_unref(result);
-
- g_free(dst_root);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_obex_server_cancel_transfer(int transfer_id)
-{
- bt_transfer_info_t *transfer = NULL;
- GDBusProxy *proxy;
- GVariant *result = NULL;
- GError *err = NULL;
- BT_DBG("+");
- transfer = __bt_find_transfer_by_id(transfer_id);
-
- retv_if(transfer == NULL, BLUETOOTH_ERROR_NOT_FOUND);
- proxy = __bt_get_transfer_proxy(transfer->path);
-
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy, "Cancel", NULL,
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIMEOUT, NULL, &err);
- if (err) {
- BT_ERR("Dbus Err: %s", err->message);
- g_clear_error(&err);
- }
-
- g_object_unref(proxy);
-
- if (result)
- g_variant_unref(result);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_obex_server_cancel_all_transfers(void)
-{
- GSList *l;
- bt_transfer_info_t *transfer;
-
- for (l = transfers; l != NULL; l = l->next) {
- transfer = l->data;
-
- if (transfer == NULL)
- continue;
-
- _bt_obex_server_cancel_transfer(transfer->transfer_id);
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_obex_server_is_activated(gboolean *activated)
-{
- BT_CHECK_PARAMETER(activated, return);
-
- if (agent_info.custom_server)
- *activated = TRUE;
- else
- *activated = FALSE;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_obex_server_check_allocation(gboolean *allocation)
-{
- BT_CHECK_PARAMETER(allocation, return);
-
- if (agent_info.native_server || agent_info.custom_server)
- *allocation = TRUE;
- else
- *allocation = FALSE;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_obex_server_check_termination(char *sender)
-{
- BT_CHECK_PARAMETER(sender, return);
-
- if (agent_info.native_server) {
- if (g_strcmp0(sender, agent_info.native_server->sender) == 0) {
- _bt_obex_server_deallocate(agent_info.native_server->app_pid,
- TRUE);
- }
- }
-
- if (agent_info.custom_server) {
- if (g_strcmp0(sender, agent_info.custom_server->sender) == 0) {
- _bt_obex_server_deallocate(agent_info.custom_server->app_pid,
- FALSE);
- }
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_obex_server_is_receiving(gboolean *receiving)
-{
- BT_CHECK_PARAMETER(receiving, return);
-
- if (transfers == NULL || g_slist_length(transfers) == 0)
- *receiving = FALSE;
- else
- *receiving = TRUE;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-gboolean __bt_obex_server_accept_timeout_cb(gpointer user_data)
-{
- request_info_t *req_info;
- GVariant *out_param1 = NULL;
- int result = BLUETOOTH_ERROR_TIMEOUT;
-
- /* Already reply in _bt_obex_transfer_started */
- retv_if(agent_info.accept_id == 0, FALSE);
-
- req_info = _bt_get_request_info(agent_info.accept_id);
- if (req_info == NULL || req_info->context == NULL) {
- BT_ERR("info is NULL");
- return FALSE;
- }
-
- agent_info.accept_id = 0;
- GArray *g_out_param1 = NULL;
- g_out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
- if (out_param1 == NULL) {
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- g_out_param1->data, g_out_param1->len,
- TRUE, NULL, NULL);
- }
-
- g_dbus_method_invocation_return_value(req_info->context,
- g_variant_new("(iv)", result, out_param1));
- g_array_free(g_out_param1, TRUE);
- _bt_delete_request_list(req_info->req_id);
-
- return FALSE;
-}
-
-/* To support the BOT */
-int _bt_obex_server_accept_connection(int request_id)
-{
- if (!_bt_agent_reply_authorize(TRUE))
- return BLUETOOTH_ERROR_INTERNAL;
-
- agent_info.accept_id = request_id;
-
- g_timeout_add(BT_SERVER_ACCEPT_TIMEOUT,
- (GSourceFunc)__bt_obex_server_accept_timeout_cb,
- NULL);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-/* To support the BOT */
-int _bt_obex_server_reject_connection(void)
-{
- if (!_bt_agent_reply_authorize(FALSE))
- return BLUETOOTH_ERROR_INTERNAL;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_opp_get_server_progress(int transfer_id, guint8 *progress)
-{
- bt_transfer_info_t *requested_transfer = NULL;
- requested_transfer = __bt_find_transfer_by_id(transfer_id);
- if (requested_transfer == NULL) {
- BT_ERR("No Matching Inbound transfer");
- return BLUETOOTH_ERROR_NOT_FOUND;
- }
-
- *progress = (int)(((double)requested_transfer->progress /
- requested_transfer->file_size) * 100);
-
- BT_DBG("Percentage: %d", *progress);
- return BLUETOOTH_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hocheol Seo <hocheol.seo@samsung.com>
- * Girishashok Joshi <girish.joshi@samsung.com>
- * Chanyeol Park <chanyeol.park@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <dlog.h>
-#include <string.h>
-#include <gio/gio.h>
-
-#include "bluetooth-api.h"
-#include "bt-service-common.h"
-#include "bt-service-oob.h"
-#include "bt-service-event.h"
-
-static int __get_oob_data_from_variant(GVariant *variant,
- unsigned char *buf, int size)
-{
- int i;
- unsigned char *v;
-
- i = g_variant_get_size(variant);
- v = (unsigned char *)g_variant_get_data(variant);
- if (i && v) {
- i = i > size ? size : i;
- memcpy(buf, v, i);
- }
-
- return i;
-}
-
-int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data)
-{
- GDBusProxy *proxy;
- GVariant *reply;
- GError *err = NULL;
- char *adapter_path;
- GDBusConnection *conn;
- GVariant *hash192 = NULL;
- GVariant *randomizer192 = NULL;
- GVariant *hash256 = NULL;
- GVariant *randomizer256 = NULL;
-
- BT_CHECK_PARAMETER(local_oob_data, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_path = _bt_get_adapter_path();
- retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- proxy = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, adapter_path,
- BT_OOB_INTERFACE, NULL, &err);
- g_free(adapter_path);
- if (!proxy) {
- BT_ERR("Unable to create proxy");
- if (err) {
- BT_ERR("Error: %s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- reply = g_dbus_proxy_call_sync(proxy, "ReadLocalData",
- NULL,
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &err);
- g_object_unref(proxy);
-
- if (reply == NULL) {
- BT_ERR("ReadLocalData dBUS-RPC is failed");
- if (err != NULL) {
- BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
- err->code, err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(reply, "(@ay@ay@ay@ay)", &hash192, &randomizer192,
- &hash256, &randomizer256);
- g_variant_unref(reply);
-
- if (hash192) {
- local_oob_data->hash_len = __get_oob_data_from_variant(hash192,
- local_oob_data->hash,
- sizeof(local_oob_data->hash));
- g_variant_unref(hash192);
- }
-
- if (randomizer192) {
- local_oob_data->randomizer_len = __get_oob_data_from_variant(randomizer192,
- local_oob_data->randomizer,
- sizeof(local_oob_data->randomizer));
- g_variant_unref(randomizer192);
- }
-
- if (hash256) {
- local_oob_data->hash256_len = __get_oob_data_from_variant(hash256,
- local_oob_data->hash256,
- sizeof(local_oob_data->hash256));
- g_variant_unref(hash256);
- }
-
- if (randomizer256) {
- local_oob_data->randomizer256_len = __get_oob_data_from_variant(randomizer256,
- local_oob_data->randomizer256,
- sizeof(local_oob_data->randomizer256));
- g_variant_unref(randomizer256);
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_oob_add_remote_data(
- bluetooth_device_address_t *remote_device_address,
- bt_oob_data_t *remote_oob_data)
-{
- int i;
- GDBusProxy *proxy;
- GVariant *reply;
- GError *err = NULL;
- char *dev_addr;
- char *adapter_path;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- unsigned char *remote_hash;
- unsigned char *remote_randomizer;
- GDBusConnection *conn;
- GVariantBuilder *builder;
- GVariantBuilder *builder2;
- GVariant *hash192;
- GVariant *randomizer192;
- GVariant *hash256;
- GVariant *randomizer256;
-
- BT_CHECK_PARAMETER(remote_device_address, return);
- BT_CHECK_PARAMETER(remote_oob_data, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_path = _bt_get_adapter_path();
- retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, remote_device_address->addr);
-
- proxy = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, adapter_path,
- BT_OOB_INTERFACE, NULL, &err);
- g_free(adapter_path);
- if (!proxy) {
- BT_ERR("Unable to create proxy");
- if (err) {
- BT_ERR("Error: %s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- /* Remote address */
- dev_addr = g_strdup(address);
-
- /* P-192 */
- remote_hash = remote_oob_data->hash;
- remote_randomizer = remote_oob_data->randomizer;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
- builder2 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
-
- for (i = 0; i < remote_oob_data->hash_len; i++)
- g_variant_builder_add(builder, "y", remote_hash[i]);
-
- for (i = 0; i < remote_oob_data->randomizer_len; i++)
- g_variant_builder_add(builder2, "y", remote_randomizer[i]);
-
- hash192 = g_variant_new("ay", builder);
- randomizer192 = g_variant_new("ay", builder2);
-
- g_variant_builder_unref(builder2);
- g_variant_builder_unref(builder);
-
- /* P-256 */
- remote_hash = remote_oob_data->hash256;
- remote_randomizer = remote_oob_data->randomizer256;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
- builder2 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
-
- for (i = 0; i < remote_oob_data->hash256_len; i++)
- g_variant_builder_add(builder, "y", remote_hash[i]);
-
- for (i = 0; i < remote_oob_data->randomizer256_len; i++)
- g_variant_builder_add(builder2, "y", remote_randomizer[i]);
-
- hash256 = g_variant_new("ay", builder);
- randomizer256 = g_variant_new("ay", builder2);
-
- g_variant_builder_unref(builder2);
- g_variant_builder_unref(builder);
-
- /* Call AddRemoteData Method */
- reply = g_dbus_proxy_call_sync(proxy, "AddRemoteData",
- g_variant_new("(s@ay@ay@ay@ay)", dev_addr,
- hash192, randomizer192, hash256, randomizer256),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &err);
- g_object_unref(proxy);
- g_free(dev_addr);
-
- /* Check the reply */
- if (reply == NULL) {
- BT_ERR("AddRemoteData dBUS-RPC is failed");
- if (err != NULL) {
- BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
- err->code, err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_unref(reply);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_oob_remove_remote_data(
- bluetooth_device_address_t *remote_device_address)
-{
- GDBusProxy *proxy;
- GVariant *reply;
- GError *err = NULL;
- char *dev_addr;
- char *adapter_path;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- GDBusConnection *conn;
-
- BT_CHECK_PARAMETER(remote_device_address, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_path = _bt_get_adapter_path();
- retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address,
- remote_device_address->addr);
-
- proxy = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, adapter_path,
- BT_OOB_INTERFACE, NULL, &err);
- g_free(adapter_path);
- if (!proxy) {
- BT_ERR("Unable to create proxy");
- if (err) {
- BT_ERR("Error: %s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- dev_addr = g_strdup(address);
-
- /* Call RemoveRemoteData Method*/
- reply = g_dbus_proxy_call_sync(proxy, "RemoveRemoteData",
- g_variant_new("(s)", dev_addr),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &err);
- g_object_unref(proxy);
- g_free(dev_addr);
-
- /* Check the reply*/
- if (reply == NULL) {
- BT_ERR("RemoveRemoteData dBUS-RPC is failed");
- if (err != NULL) {
- BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
- err->code, err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_unref(reply);
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_le_oob_read_local_data(bt_oob_data_t *local_oob_data)
-{
- GDBusProxy *proxy;
- GVariant *reply;
- GError *err = NULL;
- char *adapter_path;
- GDBusConnection *conn;
- GVariant *eir = NULL;
-
- BT_CHECK_PARAMETER(local_oob_data, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_path = _bt_get_adapter_path();
- retv_if(adapter_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- proxy = g_dbus_proxy_new_sync(conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- BT_BLUEZ_NAME, adapter_path,
- BT_OOB_INTERFACE, NULL, &err);
- g_free(adapter_path);
- if (!proxy) {
- BT_ERR("Unable to create proxy");
- if (err) {
- BT_ERR("Error: %s", err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- if (device_power_request_lock(POWER_LOCK_CPU, 2000) != DEVICE_ERROR_NONE)
- BT_ERR("device_power_request_lock() failed");
- else
- BT_ERR("device_power_request_lock() succeed");
-
- reply = g_dbus_proxy_call_sync(proxy, "LEReadLocalData",
- NULL,
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &err);
- g_object_unref(proxy);
-
- if (reply == NULL) {
- BT_ERR("LEReadLocalData dBUS-RPC is failed");
- if (err != NULL) {
- BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
- err->code, err->message);
- g_clear_error(&err);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- g_variant_get(reply, "(@ay)", &eir);
- g_variant_unref(reply);
-
- if (eir) {
- local_oob_data->eir_len = __get_oob_data_from_variant(eir,
- local_oob_data->eir,
- sizeof(local_oob_data->eir));
- g_variant_unref(eir);
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <dlog.h>
-#include <string.h>
-#include <mime_type.h>
-#include <aul.h>
-#include <glib.h>
-#include <gio/gio.h>
-
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-#include "bt-service-util.h"
-#include "bt-service-opp-client.h"
-#include "bt-service-obex-agent.h"
-#include "bt-service-adapter.h"
-
-#define BT_MIME_TYPE_MAX_LEN 20
-
-static GSList *transfer_list = NULL;
-bt_sending_info_t *sending_info;
-static int file_offset = 0;
-
-#define DBUS_TIEMOUT 20 * 1000 /* 20 Seconds */
-static gboolean __bt_sending_release();
-static int _bt_remove_session();
-
-static int __bt_opp_client_start_sending(int request_id, char *address,
- char **file_name_array, int file_count);
-
-static GQuark __bt_opc_error_quark(void)
-{
- static GQuark quark = 0;
- if (!quark)
- quark = g_quark_from_static_string("agent");
-
- return quark;
-}
-
-static void __bt_free_transfer_info(bt_transfer_info_t *info)
-{
- ret_if(info == NULL);
-
- if (info->proxy)
- g_object_unref(info->proxy);
-
- if (info->properties_proxy)
- g_object_unref(info->properties_proxy);
-
-
- g_free(info->transfer_name);
- g_free(info->file_name);
- g_free(info);
-}
-
-static void __bt_free_sending_info(bt_sending_info_t *info)
-{
- ret_if(info == NULL);
-
- /* Free the sending variable */
- __bt_free_transfer_info(info->transfer_info);
-
- g_free(info->file_name_array);
-
- g_free(info->address);
- g_free(info);
-}
-
-static gboolean __bt_cancel_push_cb(gpointer data)
-{
- BT_DBG("+");
-
- int result = BLUETOOTH_ERROR_CANCEL_BY_USER;
- GVariant *param = NULL;
- retv_if(sending_info == NULL, FALSE);
- sending_info->result = result;
-
- param = g_variant_new("(isi)", result,
- sending_info->address,
- sending_info->request_id);
- /* Send the event in only error none case */
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_CONNECTED,
- param);
- __bt_free_sending_info(sending_info);
- sending_info = NULL;
-
- _bt_opp_client_event_deinit();
-
- BT_DBG("Length of transfer list is %d", g_slist_length(transfer_list));
-
- /*Operate remain works*/
- if (g_slist_length(transfer_list) > 0) {
- bt_sending_data_t *node = NULL;
-
- node = transfer_list->data;
- if (node == NULL) {
- BT_ERR("data is NULL");
- return FALSE;
- }
-
- transfer_list = g_slist_remove(transfer_list, node);
-
- if (__bt_opp_client_start_sending(node->request_id,
- node->address, node->file_path,
- node->file_count) != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Fail to start sending");
- }
- }
- BT_DBG("-");
- return FALSE;
-}
-
-gboolean _bt_obex_client_progress(const char *transfer_path, guint64 transferred)
-{
- BT_DBG("+");
-
- int percentage_progress;
- int previous_progress;
- guint64 size;
- int result = BLUETOOTH_ERROR_NONE;
- GVariant *param = NULL;
- retv_if(sending_info == NULL, TRUE);
- retv_if(sending_info->transfer_info == NULL, TRUE);
-
- if (g_strcmp0(sending_info->transfer_info->transfer_path,
- transfer_path) != 0) {
- BT_INFO("Path mismatch, previous transfer failed! Returning");
- return FALSE;
- }
-
- size = sending_info->transfer_info->size;
- if (size != 0)
- percentage_progress = (int)(((gdouble)transferred /(gdouble)size) * 100);
- else
- percentage_progress = 0;
-
- sending_info->transfer_info->transfer_status = BT_TRANSFER_STATUS_PROGRESS;
- sending_info->result = result;
-
- previous_progress = (int)(((gdouble)sending_info->transfer_info->progress /(gdouble)size) * 100);
- if (percentage_progress == previous_progress &&
- sending_info->transfer_info->progress) {
- sending_info->transfer_info->progress = transferred;
- return TRUE;
- }
- BT_DBG("Sending progress [prev %d] [curr %d]",
- previous_progress, percentage_progress);
-
- sending_info->transfer_info->progress = transferred;
-
- /* Send the event in only error none case */
- param = g_variant_new("(istii)", result,
- sending_info->transfer_info->file_name,
- sending_info->transfer_info->size,
- percentage_progress,
- sending_info->request_id);
-
-
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS,
- param);
- BT_DBG("-");
-
- return TRUE;
-}
-
-gboolean _bt_obex_client_completed(const char *transfer_path, gboolean success)
-{
- BT_DBG("+");
-
- int result = BLUETOOTH_ERROR_NONE;
- GVariant *param = NULL;
- retv_if(sending_info == NULL, TRUE);
- retv_if(sending_info->transfer_info == NULL, TRUE);
-
- if (g_strcmp0(sending_info->transfer_info->transfer_path,
- transfer_path) != 0) {
- BT_INFO("Path mismatch, previous transfer failed! Returning");
- return FALSE;
- }
-
- result = (success == TRUE) ? BLUETOOTH_ERROR_NONE : BLUETOOTH_ERROR_CANCEL;
-
- sending_info->transfer_info->transfer_status = BT_TRANSFER_STATUS_COMPLETED;
- sending_info->result = result;
-
- if (!success) { /*In case of remote device reject, we need to send BLUETOOTH_EVENT_OPC_DISCONNECTED */
- BT_DBG("completed with error");
- if (!sending_info->is_canceled) {
- param = g_variant_new("(issti)", result,
- sending_info->address,
- sending_info->transfer_info->file_name,
- sending_info->transfer_info->size,
- sending_info->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE,
- param);
- __bt_free_transfer_info(sending_info->transfer_info);
- sending_info->transfer_info = NULL;
- /* Reset the file offset as we will cancelled remaining files also */
- file_offset = 0;
- }
- param = g_variant_new("(isi)", sending_info->result,
- sending_info->address,
- sending_info->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_DISCONNECTED,
- param);
- __bt_sending_release();
- /* Sending info should not freed after sending_release it's
- * already freed in that API and if any pending request is
- * present then it recreate sending_info again.
- * And if we free it here then CreateSession method call will
- * made but RemoveSession method call will not done.
- */
- } else {
- BT_DBG("complete success");
- /* Send the event in only error none case */
- param = g_variant_new("(issti)", result,
- sending_info->address,
- sending_info->transfer_info->file_name,
- sending_info->transfer_info->size,
- sending_info->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE,
- param);
- __bt_free_transfer_info(sending_info->transfer_info);
- sending_info->transfer_info = NULL;
- }
-
- BT_DBG("-");
-
- return TRUE;
-}
-
-gboolean _bt_obex_client_started(const char *transfer_path)
-{
- BT_DBG("+");
-
- int result = BLUETOOTH_ERROR_NONE;
- GError *error = NULL;
- GVariant *param = NULL;
- GDBusConnection *g_conn;
- GDBusProxy *properties_proxy;
- GDBusProxy *transfer_proxy;
-
- if (sending_info == NULL || sending_info->is_canceled == TRUE) {
- result = BLUETOOTH_ERROR_CANCEL_BY_USER;
- goto canceled;
- }
-
- /* Get the session bus. */
- g_conn = _bt_gdbus_get_session_gconn();
- retv_if(g_conn == NULL, FALSE);
- properties_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_OBEXD_DBUS_NAME,
- transfer_path, BT_PROPERTIES_INTERFACE,
- NULL, &error);
-
- retv_if(properties_proxy == NULL, FALSE);
-
- sending_info->transfer_info->properties_proxy = properties_proxy;
-
- transfer_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_OBEXD_DBUS_NAME,
- transfer_path, BT_OBEX_TRANSFER_INTERFACE,
- NULL, &error);
-
- retv_if(transfer_proxy == NULL, FALSE);
-
- sending_info->transfer_info->proxy = transfer_proxy;
-
- sending_info->transfer_info->transfer_status = BT_TRANSFER_STATUS_STARTED;
- sending_info->result = result;
-
- param = g_variant_new("(issti)", result,
- sending_info->address,
- sending_info->transfer_info->file_name,
- sending_info->transfer_info->size,
- sending_info->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_TRANSFER_STARTED,
- param);
-
- BT_DBG("-");
- return TRUE;
-canceled:
- error = g_error_new(__bt_opc_error_quark(), BT_OBEX_AGENT_ERROR_CANCEL,
- "CancelledByUser");
-
- g_error_free(error);
-
- BT_DBG("-");
- return FALSE;
-}
-
-static void __bt_free_sending_data(gpointer data)
-{
- int i;
- bt_sending_data_t *info = data;
-
- ret_if(info == NULL);
-
- for (i = 0; i < info->file_count; i++)
- g_free(info->file_path[i]);
-
- _bt_delete_request_id(info->request_id);
-
- g_free(info->file_path);
- g_free(info->address);
- g_free(info);
-}
-
-static void __bt_sending_release_cb(GDBusProxy *proxy,
- GAsyncResult *res, gpointer user_data)
-{
- BT_DBG("+");
- ret_if(sending_info == NULL);
-
- GError *error = NULL;
- int result = BLUETOOTH_ERROR_NONE;
- GVariant *param = NULL;
- GVariant *reply = NULL;
-
- reply = g_dbus_proxy_call_finish(proxy, res, &error);
- if (proxy)
- g_object_unref(proxy);
- if (reply)
- g_variant_unref(reply);
-
- if (error) {
- BT_ERR("%s", error->message);
- g_error_free(error);
-
- result = BLUETOOTH_ERROR_INTERNAL;
- } else {
- file_offset = 0;
- BT_DBG("Session Removed");
- }
-
- sending_info->result = result;
- param = g_variant_new("(isi)", sending_info->result,
- sending_info->address,
- sending_info->request_id);
- /* Send the event in only error none case */
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_DISCONNECTED,
- param);
-
- __bt_free_sending_info(sending_info);
- sending_info = NULL;
-
- _bt_opp_client_event_deinit();
-
- /* Operate remain works */
- if (g_slist_length(transfer_list) > 0) {
- bt_sending_data_t *data = NULL;
-
- data = transfer_list->data;
- if (data == NULL)
- goto fail;
-
- transfer_list = g_slist_remove(transfer_list, data);
-
- BT_DBG("calling __bt_opp_client_start_sending");
-
- if (__bt_opp_client_start_sending(data->request_id,
- data->address, data->file_path,
- data->file_count) != BLUETOOTH_ERROR_NONE) {
- goto fail;
- }
- }
-
- return;
-fail:
- g_slist_free_full(transfer_list,
- (GDestroyNotify)__bt_free_sending_data);
- transfer_list = NULL;
-
- BT_DBG("-");
-
- return;
-}
-
-static int _bt_remove_session()
-{
- GDBusConnection *g_conn;
- GDBusProxy *session_proxy;
- GError *err = NULL;
-
- g_conn = _bt_gdbus_get_session_gconn();
- retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
- retv_if(sending_info->session_path == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
-
- session_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_OBEXD_DBUS_NAME,
- BT_OBEX_CLIENT_PATH,
- BT_OBEX_CLIENT_INTERFACE,
- NULL, &err);
-
- retv_if(session_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- g_dbus_proxy_call(session_proxy, "RemoveSession",
- g_variant_new("(o)", sending_info->session_path),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIEMOUT, NULL,
- (GAsyncReadyCallback)__bt_sending_release_cb,
- NULL);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-static gboolean __bt_sending_release()
-{
- BT_DBG("+");
-
- retv_if(sending_info == NULL, FALSE);
-
- retv_if(_bt_remove_session() != BLUETOOTH_ERROR_NONE, FALSE);
-
- BT_DBG("-");
- return TRUE;
-}
-
-void _bt_opc_disconnected(const char *session_path)
-{
- BT_DBG("+");
- GVariant *param = NULL;
- ret_if(sending_info == NULL);
-
- if (g_strcmp0(sending_info->session_path,
- session_path) != 0) {
- BT_INFO("Path mismatch, previous transfer failed! Returning");
- return;
- }
-
- if (sending_info->transfer_info) {
- if (sending_info->transfer_info->transfer_status == BT_TRANSFER_STATUS_PROGRESS ||
- sending_info->transfer_info->transfer_status == BT_TRANSFER_STATUS_STARTED) {
- BT_INFO("Abnormal termination");
- param = g_variant_new("(issti)", sending_info->result,
- sending_info->address,
- sending_info->transfer_info->file_name,
- sending_info->transfer_info->size,
- sending_info->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE,
- param);
- __bt_free_transfer_info(sending_info->transfer_info);
- }
- }
- param = g_variant_new("(isi)", sending_info->result,
- sending_info->address,
- sending_info->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_DISCONNECTED,
- param);
-
- __bt_free_sending_info(sending_info);
- sending_info = NULL;
-
- BT_DBG("-");
-}
-
-static void __bt_send_file_cb(GDBusProxy *proxy,
- GAsyncResult *res, gpointer user_data)
-{
- BT_DBG("+");
- GVariant *value = NULL;
- GError *error = NULL;
- char *session_path = NULL;
- const char *transfer_name = NULL;
- const char *file_name = NULL;
- int size = 0;
- GVariantIter *iter = NULL;
- value = g_dbus_proxy_call_finish(proxy, res, &error);
- if (error) {
- g_dbus_error_strip_remote_error(error);
- BT_ERR("%s", error->message);
- /* If Obex is not able to open a file then continue with other if any */
- if (g_strcmp0("Unable to open file", error->message) == 0) {
- GVariant *param = NULL;
- gint64 size = 0;
-
- BT_ERR("Unable to open file [%s]", sending_info->file_name_array[file_offset]);
-
- param = g_variant_new("(issti)", BLUETOOTH_ERROR_NOT_FOUND,
- sending_info->address,
- sending_info->file_name_array[file_offset],
- size,
- sending_info->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_TRANSFER_STARTED,
- param);
-
- param = g_variant_new("(issti)", BLUETOOTH_ERROR_NOT_FOUND,
- sending_info->address,
- sending_info->file_name_array[file_offset],
- size,
- sending_info->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE,
- param);
- g_error_free(error);
- if (proxy)
- g_object_unref(proxy);
- file_offset++;
- _bt_sending_files();
- }
- return;
- }
- if (proxy)
- g_object_unref(proxy);
-
- if (value) {
- g_variant_get(value, "(oa{sv})", &session_path, &iter);
- g_variant_unref(value);
- }
-
- __bt_free_transfer_info(sending_info->transfer_info);
-
- sending_info->transfer_info = g_malloc0(sizeof(bt_transfer_info_t));
-
- if (iter) {
- const gchar *key;
- GVariant *val;
- gsize len = 0;
- while (g_variant_iter_loop(iter, "{sv}", &key, &val)) {
- if (g_strcmp0(key, "Name") == 0)
- transfer_name = g_variant_dup_string(val, &len);
- else if (g_strcmp0(key, "Filename") == 0)
- file_name = g_variant_dup_string(val, &len);
- else if (g_strcmp0(key, "Size") == 0)
- size = g_variant_get_uint64(val);
- }
- g_variant_iter_free(iter);
- }
-
- sending_info->transfer_info->transfer_name = g_strdup(transfer_name);
- sending_info->transfer_info->file_name = g_strdup(file_name);
- sending_info->transfer_info->size = size;
- sending_info->transfer_info->progress = 0;
- sending_info->transfer_info->transfer_path = session_path;
- sending_info->transfer_info->transfer_status = BT_TRANSFER_STATUS_QUEUED;
- sending_info->result = BLUETOOTH_ERROR_NONE;
- file_offset++;
-
- g_free((gchar *)transfer_name);
- g_free((gchar *)file_name);
-}
-
-void _bt_sending_files(void)
-{
- BT_DBG("+");
-
- GError *err = NULL;
- GDBusConnection *g_conn;
- GDBusProxy *client_proxy;
- char mime_type[BT_MIME_TYPE_MAX_LEN + 1] = { 0 };
-
- if (sending_info == NULL)
- return;
- if (file_offset < sending_info->file_count) {
- /* Get the session bus. */
- g_conn = _bt_gdbus_get_session_gconn();
- ret_if(g_conn == NULL);
-
- client_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_OBEXD_DBUS_NAME,
- sending_info->session_path,
- BT_OBEX_OBJECT_PUSH_INTERFACE,
- NULL, &err);
- ret_if(client_proxy == NULL);
- if (aul_get_mime_from_file(sending_info->file_name_array[file_offset],
- mime_type, BT_MIME_TYPE_MAX_LEN) == AUL_R_OK) {
- BT_DBG("MLME type = %s", mime_type);
-
- /* For IOPT compliance, change "text/x-iMelody" to "audio/imelody"
- * because few devices(multimedia players) reject the OPP put for text objects
- * since they support only multimedia files exchange */
- if (!strcasecmp(mime_type, "text/x-iMelody")) {
- strncpy(mime_type, "audio/imelody", BT_MIME_TYPE_MAX_LEN);
- BT_DBG("over writing mime type to = %s", mime_type);
- }
- if (!strcasecmp(mime_type, "text/vcard")) {
- strncpy(mime_type, "text/x-vcard", BT_MIME_TYPE_MAX_LEN);
- BT_DBG("over writing mime type to = %s", mime_type);
- }
- }
-
- BT_DBG("Calling SendFile");
- g_dbus_proxy_call(client_proxy, "SendFile",
- g_variant_new("(ss)", sending_info->file_name_array[file_offset],
- mime_type),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIEMOUT, NULL,
- (GAsyncReadyCallback)__bt_send_file_cb,
- sending_info);
- if (err != NULL) {
- BT_ERR("Calling SendFile failed: [%s]\n", err->message);
- g_clear_error(&err);
- return;
- }
-
- } else {
- file_offset = 0;
- __bt_sending_release();
- }
-
- BT_DBG("-");
-}
-
-static void __bt_create_session_cb(GDBusProxy *proxy,
- GAsyncResult *res, gpointer user_data)
-{
- BT_DBG("+");
-
- GError *error = NULL;
- GVariant *value;
- int result = BLUETOOTH_ERROR_NONE;
- char *session_path = NULL;
- GVariant *param = NULL;
-
- value = g_dbus_proxy_call_finish(proxy, res, &error);
- if (value) {
- g_variant_get(value, "(o)", &session_path);
- g_variant_unref(value);
- }
- if (error) {
-
- BT_ERR("%s", error->message);
- g_clear_error(&error);
-
- result = BLUETOOTH_ERROR_INTERNAL;
- } else {
- BT_DBG("Session created");
- if (sending_info != NULL)
- sending_info->session_path = g_strdup(session_path);
- }
- g_free(session_path);
- g_object_unref(proxy);
- ret_if(sending_info == NULL);
-
- sending_info->result = result;
- param = g_variant_new("(isi)", result,
- sending_info->address,
- sending_info->request_id);
- /* Send the event in only error none case */
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_CONNECTED,
- param);
-
- if (result != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Calling __bt_sending_release");
- gboolean ret = __bt_sending_release();
-
- __bt_free_sending_info(sending_info);
- sending_info = NULL;
-
- if (ret == FALSE) {
- BT_DBG("ReleaseSession Not called");
- /* Operate remain works */
- if (g_slist_length(transfer_list) > 0) {
- bt_sending_data_t *data = NULL;
-
- data = transfer_list->data;
- ret_if(data == NULL);
-
- transfer_list = g_slist_remove(transfer_list, data);
-
- BT_DBG("calling __bt_opp_client_start_sending");
-
- if (__bt_opp_client_start_sending(data->request_id,
- data->address, data->file_path,
- data->file_count) != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Sending Enqueued Transfer Failed");
- }
- }
- }
- } else {
- BT_DBG("Calling sending_files");
- _bt_sending_files();
- }
- BT_DBG("-");
-
-}
-
-static int __bt_opp_client_start_sending(int request_id, char *address,
- char **file_name_array, int file_count)
-{
- GVariantBuilder *builder;
- int i;
- GDBusConnection *g_conn;
- GDBusProxy *client_proxy;
- GError *error = NULL;
- BT_DBG("+");
-
- BT_CHECK_PARAMETER(address, return);
- BT_CHECK_PARAMETER(file_name_array, return);
-
- /* Get the session bus. */
- g_conn = _bt_gdbus_get_session_gconn();
- retv_if(g_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- client_proxy = g_dbus_proxy_new_sync(g_conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_OBEX_SERVICE_NAME,
- BT_OBEX_CLIENT_PATH,
- BT_OBEX_CLIENT_INTERFACE,
- NULL, &error);
-
- if (error) {
- BT_ERR("Unable to create client proxy: %s", error->message);
- g_clear_error(&error);
- }
-
- retv_if(client_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- builder = g_variant_builder_new(
- G_VARIANT_TYPE("a{sv}"));
-
- g_variant_builder_add(builder, "{sv}", "Target",
- g_variant_new_string("OPP"));
-
- __bt_free_sending_info(sending_info);
-
- sending_info = g_malloc0(sizeof(bt_sending_info_t));
- sending_info->address = g_strdup(address);
- sending_info->request_id = request_id;
-
- sending_info->file_count = file_count;
- sending_info->file_offset = 0;
- sending_info->file_name_array = g_new0(char *, file_count + 1);
-
- for (i = 0; i < file_count; i++) {
- sending_info->file_name_array[i] = g_strdup(file_name_array[i]);
- BT_DBG("file[%d]: %s", i, sending_info->file_name_array[i]);
- }
-
- _bt_opp_client_event_deinit();
- _bt_opp_client_event_init();
- //_bt_obex_client_started(agent_path);
-
- BT_DBG("Adapter Status %d", _bt_adapter_get_status());
- if (_bt_adapter_get_status() == BT_ACTIVATED) {
- BT_DBG("Going to call CreateSession");
- g_dbus_proxy_call(client_proxy, "CreateSession",
- g_variant_new("(sa{sv})", address, builder),
- G_DBUS_CALL_FLAGS_NONE,
- DBUS_TIEMOUT, NULL,
- (GAsyncReadyCallback)__bt_create_session_cb,
- NULL);
- } else {
- GVariant *param = g_variant_new("(isi)", BLUETOOTH_ERROR_INTERNAL,
- sending_info->address, sending_info->request_id);
-
- BT_DBG("Address[%s] RequestID[%d]", sending_info->address, sending_info->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT, BLUETOOTH_EVENT_OPC_CONNECTED,
- param);
- __bt_free_sending_info(sending_info);
- sending_info = NULL;
- }
- g_variant_builder_unref(builder);
-
- BT_DBG("-");
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_opp_client_push_files(int request_id, GDBusMethodInvocation *context,
- bluetooth_device_address_t *remote_address,
- char **file_path, int file_count)
-{
- BT_DBG("+");
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- bt_sending_data_t *data;
-
- GVariant *out_param1 = NULL;
-
- int result = BLUETOOTH_ERROR_NONE;
- int i;
-
- BT_CHECK_PARAMETER(remote_address, return);
- BT_CHECK_PARAMETER(file_path, return);
-
- /* Implement the queue */
- _bt_convert_addr_type_to_string(address, remote_address->addr);
-
- if (sending_info == NULL) {
- result = __bt_opp_client_start_sending(request_id,
- address, file_path, file_count);
- if (result != BLUETOOTH_ERROR_NONE)
- return result;
- } else {
- /* Insert data in the queue */
- data = g_malloc0(sizeof(bt_sending_data_t));
- if (data == NULL)
- return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
-
- data->file_path = g_new0(char *, file_count + 1);
- data->address = g_strdup(address);
- data->file_count = file_count;
- data->request_id = request_id;
-
- for (i = 0; i < file_count; i++) {
- data->file_path[i] = g_strdup(file_path[i]);
- DBG_SECURE("file[%d]: %s", i, data->file_path[i]);
- }
-
- transfer_list = g_slist_append(transfer_list, data);
- }
-
- out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
- &request_id, sizeof(int),
- TRUE, NULL, NULL);
-
-
- g_dbus_method_invocation_return_value(context,
- g_variant_new("(iv)", result, out_param1));
-
- BT_DBG("-");
-
- return result;
-}
-
-int _bt_opp_client_cancel_push(void)
-{
- BT_DBG("+");
-
- GError *err = NULL;
- int result = BLUETOOTH_ERROR_CANCEL_BY_USER;
- GVariant *ret = NULL;
- GVariant *param = NULL;
- retv_if(sending_info == NULL, BLUETOOTH_ERROR_NOT_IN_OPERATION);
-
- sending_info->is_canceled = TRUE;
- sending_info->result = result;
-
- if (sending_info->transfer_info) {
-
- ret = g_dbus_proxy_call_sync(sending_info->transfer_info->proxy,
- "Cancel", NULL,
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &err);
- if (ret == NULL) {
- if (err != NULL) {
- BT_ERR("Cancel Error: %s\n", err->message);
- g_error_free(err);
- }
- } else {
- g_variant_unref(ret);
- }
-
- param = g_variant_new("(issti)", result,
- sending_info->address,
- sending_info->transfer_info->file_name,
- sending_info->transfer_info->size,
- sending_info->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE,
- param);
-
- if (result == BLUETOOTH_ERROR_CANCEL_BY_USER) {
- BT_ERR("result is not BLUETOOTH_ERROR_NONE");
- __bt_sending_release();
- file_offset = 0;
- }
-
- } else {
- g_idle_add(__bt_cancel_push_cb, NULL);
- }
-
- BT_DBG("-");
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_opp_client_cancel_all_transfers(void)
-{
- BT_DBG("+");
- if (transfer_list) {
- g_slist_free_full(transfer_list,
- (GDestroyNotify)__bt_free_sending_data);
-
- transfer_list = NULL;
- }
-
- _bt_opp_client_cancel_push();
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_opp_client_is_sending(gboolean *sending)
-{
- BT_CHECK_PARAMETER(sending, return);
-
- *sending = sending_info ? TRUE : FALSE;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_opp_client_check_pending_transfer(const char *address)
-{
- BT_DBG("+");
-
- int result = BLUETOOTH_ERROR_CANCEL;
- GVariant *param = NULL;
- ret_if(sending_info == NULL);
- ret_if(sending_info->transfer_info == NULL);
-
- if (g_strcmp0(sending_info->address, address) == 0) {
- BT_INFO("Address Match.Cancel current transfer");
- sending_info->transfer_info->transfer_status = BT_TRANSFER_STATUS_COMPLETED;
- sending_info->result = result;
-
- if (!sending_info->is_canceled) {
- param = g_variant_new("(issti)", result,
- sending_info->address,
- sending_info->transfer_info->file_name,
- sending_info->transfer_info->size,
- sending_info->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE,
- param);
- __bt_free_transfer_info(sending_info->transfer_info);
- sending_info->transfer_info = NULL;
- /* Reset the file offset as we will cancelled remaining files also */
- file_offset = 0;
- }
- param = g_variant_new("(isi)", sending_info->result,
- sending_info->address,
- sending_info->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT,
- BLUETOOTH_EVENT_OPC_DISCONNECTED,
- param);
-
- __bt_sending_release();
- }
- BT_DBG("-");
-}
-
-int _bt_opp_get_client_progress(guint8 *progress)
-{
- if (sending_info == NULL || sending_info->transfer_info == NULL) {
- BT_ERR("No Active Outbound transfer");
- return BLUETOOTH_ERROR_NOT_FOUND;
- }
-
- *progress = (int)(((double)sending_info->transfer_info->progress /
- sending_info->transfer_info->size) * 100);
-
- BT_DBG("Percentage: %d", *progress);
- return BLUETOOTH_ERROR_NONE;
-}
-
-void _bt_cancel_queued_transfers(void)
-{
- bt_sending_data_t *data = NULL;
- GVariant *param = NULL;
-
- BT_INFO("Cancel queued Transfers:: Length of transfer list is %d",
- g_slist_length(transfer_list));
-
- while (transfer_list) {
- data = transfer_list->data;
- param = g_variant_new("(isi)", BLUETOOTH_ERROR_INTERNAL,
- data->address, data->request_id);
-
- BT_DBG("Address[%s] RequestID[%d]", data->address, data->request_id);
- _bt_send_event(BT_OPP_CLIENT_EVENT, BLUETOOTH_EVENT_OPC_CONNECTED,
- param);
-
- transfer_list = g_slist_remove(transfer_list, data);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <malloc.h>
-#include <stacktrim.h>
-#include <syspopup_caller.h>
-#include <vconf.h>
-#include <storage.h>
-
-#include "bt-internal-types.h"
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-#include "bt-service-pbap.h"
-#include <glib.h>
-#include <gio/gio.h>
-
-#define PBAP_OBEX_CLIENT_SERVICE "org.bluez.obex"
-#define PBAP_OBEX_CLIENT_PATH "/org/bluez/obex"
-#define PBAP_OBEX_CLIENT_INTERFACE "org.bluez.obex.Client1"
-
-#define PBAP_SESSION_SERVICE "org.bluez.obex"
-#define PBAP_SESSION_INTERFACE "org.bluez.obex.PhonebookAccess1"
-#define PBAP_VCARDLIST_MAXLENGTH 256
-
-#define PBAP_NUM_OF_FIELDS_ENTRY 29
-#define PBAP_FIELD_ALL (0xFFFFFFFFFFFFFFFFULL)
-
-#define PBAP_DEFAULT_DOWNLAOD_PATH "/opt/usr/home/owner/media/Downloads"
-#define PBAP_DEFAULT_FILE_NAME "pb.vcf"
-
-char *FIELDS[] = {
- "VERSION",
- "FN",
- "N",
- "PHOTO",
- "BDAY",
- "ADR",
- "LABEL",
- "TEL",
- "EMAIL",
- "MAILER",
- "TZ",
- "GEO",
- "TITLE",
- "ROLE",
- "LOGO",
- "AGENT",
- "ORG",
- "NOTE",
- "REV",
- "SOUND",
- "URL",
- "UID",
- "KEY",
- "NICKNAME",
- "CATEGORIES",
- "PROID",
- "CLASS",
- "SORT-STRING",
- "X-IRMC-CALL-DATETIME", /* 29 */
-};
-
-char *SOURCE[] = {
- "int", //Phone memory
- "sim" // SIM memory
-};
-
-char *TYPE[] = {
- "pb", //Phonebook for the saved contacts
- "ich", //Incoming call history
- "och", //Outgoing call history
- "mch", //Missed call history
- "cch", //Combined Call History cch = ich + och + mch
-};
-
-char *FORMAT[] = {
- "vcard21", // vCard Format 2.1 (Default)
- "vcard30", // vCard Format 3.0
-};
-
-char *ORDER[] = {
- "indexed", // Index (default)
- "alphanumeric", // Alphanumeric
- "phonetic", // Phonetic
-};
-
-char *SEARCH_FIELD[] = {
- "name", // Search by Name(default)
- "number", // Search by Phone Number
- "sound", // Search by phonetic sound
-};
-
-static char *g_pbap_session_path = NULL;
-static char *g_pbap_server_address = NULL;
-static GDBusProxy *g_pbap_proxy = NULL;
-static gboolean g_is_pbap_connecting;
-
-static struct {
- int type;
- int folder;
-} selected_path = { -1, -1};
-
-typedef enum {
- PBAP_NONE,
- GET_SIZE,
- PULL_ALL,
- GET_LIST,
- GET_VCARD,
- PB_SEARCH,
-} bt_pbap_operation_e;
-
-typedef struct {
- bt_pbap_operation_e operation;
- void *data;
- void *app_param;
-} bt_pbap_data_t;
-
-typedef struct {
- char *path;
- char *filename;
- char *remote_device;
- bt_pbap_operation_e operation;
-} bt_pbap_transfer_info_t;
-
-static GSList *transfers;
-
-int __bt_pbap_call_get_phonebook_size(GDBusProxy *proxy, bt_pbap_data_t *pbap_data);
-int __bt_pbap_call_get_phonebook(GDBusProxy *proxy, bt_pbap_data_t *pbap_data);
-int __bt_pbap_call_get_vcards_list(GDBusProxy *proxy, bt_pbap_data_t *pbap_data);
-int __bt_pbap_call_get_vcard(GDBusProxy *proxy, bt_pbap_data_t *pbap_data);
-int __bt_pbap_call_search_phonebook(GDBusProxy *proxy, bt_pbap_data_t *pbap_data);
-
-static void __bt_pbap_free_data(bt_pbap_data_t *pbap_data)
-{
- g_free(pbap_data->app_param);
- g_free(pbap_data->data);
- g_free(pbap_data);
-}
-
-static bt_pbap_transfer_info_t *__bt_find_transfer_by_path(const char *transfer_path)
-{
- GSList *l;
- bt_pbap_transfer_info_t *transfer;
-
- retv_if(transfer_path == NULL, NULL);
-
- for (l = transfers; l != NULL; l = l->next) {
- transfer = l->data;
-
- if (transfer == NULL)
- continue;
-
- if (g_strcmp0(transfer->path, transfer_path) == 0)
- return transfer;
- }
-
- return NULL;
-}
-
-static void __bt_free_transfer_info(bt_pbap_transfer_info_t *transfer_info)
-{
- ret_if(transfer_info == NULL);
-
- g_free(transfer_info->path);
- g_free(transfer_info->filename);
- g_free(transfer_info->remote_device);
- g_free(transfer_info);
-}
-
-void _bt_pbap_obex_transfer_completed(const char *transfer_path, gboolean transfer_status)
-{
- bt_pbap_transfer_info_t *transfer_info;
- int result = 0;
- int success = transfer_status;
- GVariant *signal = NULL;
- BT_DBG("Transfer [%s] Success [%d] \n", transfer_path, success);
-
- result = (success == TRUE) ? BLUETOOTH_ERROR_NONE
- : BLUETOOTH_ERROR_INTERNAL;
-
- transfer_info = __bt_find_transfer_by_path(transfer_path);
- ret_if(transfer_info == NULL);
-
- BT_DBG("Remote Device [%s] FileName: [%s] Operation[%d]",
- transfer_info->remote_device, transfer_info->filename,
- transfer_info->operation);
-
- signal = g_variant_new("(issi)", result,
- transfer_info->remote_device,
- transfer_info->filename, success);
- switch (transfer_info->operation) {
- case PULL_ALL: {
- _bt_send_event(BT_PBAP_CLIENT_EVENT,
- BLUETOOTH_PBAP_PHONEBOOK_PULL,
- signal);
- break;
- }
- case GET_VCARD: {
- _bt_send_event(BT_PBAP_CLIENT_EVENT,
- BLUETOOTH_PBAP_VCARD_PULL,
- signal);
- break;
- }
- default:
- BT_INFO("Case not handled");
- break;
-
- }
-
- transfers = g_slist_remove(transfers, transfer_info);
- __bt_free_transfer_info(transfer_info);
-}
-
-void _bt_obex_pbap_client_disconnect(char *path)
-{
- if (g_strcmp0(g_pbap_session_path, path) == 0) {
- int result = BLUETOOTH_ERROR_NONE;
- GVariant *signal = g_variant_new("(is)", result,
- g_pbap_server_address);
-
- _bt_send_event(BT_PBAP_CLIENT_EVENT,
- BLUETOOTH_PBAP_DISCONNECTED,
- signal);
-
- g_free(g_pbap_session_path);
- g_pbap_session_path = NULL;
-
- g_free(g_pbap_server_address);
- g_pbap_server_address = NULL;
-
- g_object_unref(g_pbap_proxy);
- g_pbap_proxy = NULL;
-
- selected_path.folder = -1;
- selected_path.type = -1;
- }
- BT_DBG("-");
-}
-
-static int __bt_pbap_get_error(const char *error_message)
-{
- if (error_message == NULL) {
- BT_ERR("Error message NULL");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- BT_ERR("Error message = %s", error_message);
- if (g_strcmp0(error_message, "Unable to find service record") == 0)
- return BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
- else if (g_strcmp0(error_message, "Transport got disconnected") == 0)
- return BLUETOOTH_ERROR_AUTHORIZATION_REJECTED;
- else if (g_str_has_prefix(error_message, "Connection refused") == 0)
- return BLUETOOTH_ERROR_AUTHENTICATION_REJECTED;
- else if (g_strcmp0(error_message, "Timed out waiting for response") == 0)
- return BLUETOOTH_ERROR_TIMEOUT;
- else
- return BLUETOOTH_ERROR_INTERNAL;
-}
-
-void __bt_pbap_connect_cb(GDBusProxy *proxy,
- GAsyncResult *res, gpointer user_data)
-{
- char *session_path = NULL;
- char *address_string = user_data;
- GError *error = NULL;
- GVariant *value;
- GVariant *signal = NULL;
- int result = BLUETOOTH_ERROR_INTERNAL;
-
- value = g_dbus_proxy_call_finish(proxy, res, &error);
- BT_DBG("Address = %s", address_string);
-
- if (value == NULL) {
- BT_ERR("g_dbus_proxy_call_finish failed");
- if (error) {
- g_dbus_error_strip_remote_error(error);
- result = __bt_pbap_get_error(error->message);
- BT_ERR("Failed to coonect with error[0x%x][%s]",
- result, error->message);
- g_error_free(error);
- }
- g_object_unref(g_pbap_proxy);
- g_pbap_proxy = NULL;
- } else {
- g_variant_get(value, "(&o)", &session_path);
-
- g_pbap_session_path = g_strdup(session_path);
- BT_DBG("Session Path = %s\n", g_pbap_session_path);
- result = BLUETOOTH_ERROR_NONE;
- g_pbap_server_address = g_strdup(address_string);
-
- g_variant_unref(value);
- }
-
- signal = g_variant_new("(is)", result, address_string);
-
- _bt_send_event(BT_PBAP_CLIENT_EVENT,
- BLUETOOTH_PBAP_CONNECTED,
- signal);
-
- g_free(address_string);
- BT_DBG("-");
-
- g_is_pbap_connecting = FALSE;
-}
-
-int _bt_pbap_connect(const bluetooth_device_address_t *address)
-{
- BT_DBG("+");
- GDBusConnection *g_conn;
- GError *error = NULL;
- char address_string[18] = { 0, };
- char *ptr = NULL;
- GVariantBuilder builder;
- GVariant *args;
-
- BT_CHECK_PARAMETER(address, return);
-
- /* check if already connected */
- if (g_pbap_session_path)
- return BLUETOOTH_ERROR_ALREADY_CONNECT;
-
- if (g_is_pbap_connecting == TRUE)
- return BLUETOOTH_ERROR_IN_PROGRESS;
-
- BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
- address->addr[0], address->addr[1],
- address->addr[2], address->addr[3],
- address->addr[4], address->addr[5]);
-
- _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
- BT_DBG("Address String: %s", address_string);
- g_conn = _bt_gdbus_get_session_gconn();
- if (g_conn == NULL) {
- BT_ERR("Couldn't connect to session bus");
- return BLUETOOTH_ERROR_INTERNAL;
- }
- g_pbap_proxy = g_dbus_proxy_new_sync(g_conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- PBAP_OBEX_CLIENT_SERVICE, PBAP_OBEX_CLIENT_PATH,
- PBAP_OBEX_CLIENT_INTERFACE, NULL, &error);
- if (!g_pbap_proxy) {
- BT_ERR("Failed to get a proxy for D-Bus\n");
- if (error) {
- ERR("Unable to create proxy: %s", error->message);
- g_clear_error(&error);
- }
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- /* Create Hash*/
- g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
- g_variant_builder_add(&builder, "{sv}", "Target",
- g_variant_new("s", "pbap"));
- args = g_variant_builder_end(&builder);
-
- ptr = g_strdup(address_string);
-
- GVariant *temp = g_variant_new("(s@a{sv})", ptr, args);
-
- g_is_pbap_connecting = TRUE;
- g_dbus_proxy_call(g_pbap_proxy, "CreateSession",
- temp,
- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- (GAsyncReadyCallback)__bt_pbap_connect_cb, ptr);
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-void __bt_pbap_disconnect_cb(GDBusProxy *proxy,
- GAsyncResult *res, gpointer user_data)
-{
- char *address_string = user_data;
- GError *error = NULL;
- GVariant *value;
- int result = BLUETOOTH_ERROR_INTERNAL ;
-
- BT_DBG("Address = %s", address_string);
-
- value = g_dbus_proxy_call_finish(proxy, res, &error);
- BT_DBG("Address = %s", address_string);
-
- if (value == NULL) {
- BT_ERR("g_dbus_proxy_call_finish failed");
- if (error) {
- BT_ERR("errCode[%x], message[%s]\n",
- error->code, error->message);
- g_clear_error(&error);
- }
- } else {
- g_object_unref(g_pbap_proxy);
- g_pbap_proxy = NULL;
-
- g_free(g_pbap_session_path);
- g_pbap_session_path = NULL;
-
- g_free(g_pbap_server_address);
- g_pbap_server_address = NULL;
-
- result = BLUETOOTH_ERROR_NONE;
- selected_path.folder = -1;
- selected_path.type = -1;
-
- g_variant_unref(value);
- }
-
- /* If the result is success, the event reciever will send the disconnect event */
- if (result != BLUETOOTH_ERROR_NONE) {
- GVariant *signal = NULL;
-
- signal = g_variant_new("(is)", result, address_string);
- _bt_send_event(BT_PBAP_CLIENT_EVENT,
- BLUETOOTH_PBAP_DISCONNECTED,
- signal);
- }
-
- g_free(address_string);
- BT_DBG("-");
-}
-
-int _bt_pbap_disconnect(const bluetooth_device_address_t *address)
-{
- BT_DBG("+");
- char address_string[18] = { 0, };
- char *ptr = NULL;
- BT_CHECK_PARAMETER(address, return);
-
- /* check if connected */
- if (g_pbap_session_path == NULL)
- return BLUETOOTH_ERROR_NOT_CONNECTED;
-
- BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
- address->addr[0], address->addr[1],
- address->addr[2], address->addr[3],
- address->addr[4], address->addr[5]);
-
- _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
- BT_DBG("Address String: %s", address_string);
- BT_DBG("Session Path: %s", g_pbap_session_path);
-
- ptr = g_strdup(address_string);
-
- g_dbus_proxy_call(g_pbap_proxy, "RemoveSession",
- g_variant_new("(o)", g_pbap_session_path),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- (GAsyncReadyCallback)__bt_pbap_disconnect_cb, ptr);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-void __bt_pbap_select_cb(GDBusProxy *proxy,
- GAsyncResult *res, gpointer user_data)
-{
- BT_DBG("+");
- GError *error = NULL;
- GVariant *value;
- bt_pbap_data_t *pbap_data = user_data;
- char *address_string = pbap_data->data;
-
- BT_DBG("Address = %s", address_string);
-
- value = g_dbus_proxy_call_finish(proxy, res, &error);
- if (value == NULL) {
- BT_ERR("g_dbus_proxy_call_finish failed");
- if (error) {
- BT_ERR("errCode[%x], message[%s]\n",
- error->code, error->message);
- g_clear_error(&error);
- }
-
- selected_path.folder = -1;
- selected_path.type = -1;
-
- g_object_unref(proxy);
- __bt_pbap_free_data(pbap_data);
- return;
- }
-
- switch (pbap_data->operation) {
- case GET_SIZE: {
- __bt_pbap_call_get_phonebook_size(proxy, pbap_data);
- break;
- }
- case PULL_ALL: {
- __bt_pbap_call_get_phonebook(proxy, pbap_data);
- break;
- }
- case GET_LIST: {
- __bt_pbap_call_get_vcards_list(proxy, pbap_data);
- break;
- }
- case GET_VCARD: {
- __bt_pbap_call_get_vcard(proxy, pbap_data);
- break;
- }
- case PB_SEARCH: {
- __bt_pbap_call_search_phonebook(proxy, pbap_data);
- break;
- }
- default: {
- selected_path.folder = -1;
- selected_path.type = -1;
- g_object_unref(proxy);
- __bt_pbap_free_data(pbap_data);
- }
- } // End of Case
-
- g_variant_unref(value);
- BT_DBG("-");
-}
-
-
-void __bt_pbap_get_phonebook_size_cb(GDBusProxy *proxy,
- GAsyncResult *res, gpointer user_data)
-{
- BT_DBG("+");
- GError *error = NULL;
- int result = BLUETOOTH_ERROR_INTERNAL;
- bt_pbap_data_t *pbap_data = user_data;
- char *address_string = pbap_data->data;
- unsigned short int size = 0;
- GVariant *value;
- GVariant *signal = NULL;
-
- BT_DBG("Address = %s", address_string);
- value = g_dbus_proxy_call_finish(proxy, res, &error);
-
- if (value == NULL) {
- BT_ERR("g_dbus_proxy_call_finish failed");
- if (error) {
- BT_ERR("errCode[%x], message[%s]\n",
- error->code, error->message);
- g_clear_error(&error);
- }
- } else {
- g_variant_get(value, "(q)", &size);
- result = BLUETOOTH_ERROR_NONE;
- }
-
- BT_DBG("Size of Phonebook: %d", size);
-
- signal = g_variant_new("(isi)", result, address_string, size);
- _bt_send_event(BT_PBAP_CLIENT_EVENT,
- BLUETOOTH_PBAP_PHONEBOOK_SIZE,
- signal);
-
- g_variant_unref(value);
- g_object_unref(proxy);
- __bt_pbap_free_data(pbap_data);
- BT_DBG("-");
-}
-
-void __bt_pbap_get_phonebook_cb(GDBusProxy *proxy,
- GAsyncResult *res, gpointer user_data)
-{
- BT_DBG("+");
- GError *error = NULL;
- bt_pbap_data_t *pbap_data = user_data;
- char *address_string = pbap_data->data;
- bt_pbap_transfer_info_t *transfer_info;
- char *transfer = NULL;
- const gchar *filename = NULL;
- GVariant *value;
- GVariant *properties;
-
- BT_DBG("Address = %s", address_string);
- value = g_dbus_proxy_call_finish(proxy, res, &error);
- if (value == NULL) {
- BT_ERR("g_dbus_proxy_call_finish failed");
- if (error) {
- BT_ERR("errCode[%x], message[%s]\n",
- error->code, error->message);
- g_clear_error(&error);
- }
- } else {
- g_variant_get(value, "(o@a{sv})", &transfer, &properties);
-
- if (g_variant_lookup(properties, "Filename", "s", &filename) == FALSE)
- filename = NULL;
-
- BT_DBG("Transfer Path: %s", transfer);
- BT_DBG("File Name: %s", filename);
- transfer_info = g_new0(bt_pbap_transfer_info_t, 1);
- transfer_info->path = transfer;
- transfer_info->remote_device = g_strdup(address_string);
- transfer_info->filename = (char *)filename;
- transfer_info->operation = PULL_ALL;
- transfers = g_slist_append(transfers, transfer_info);
-
- g_variant_unref(value);
- }
-
- g_object_unref(proxy);
- __bt_pbap_free_data(pbap_data);
- BT_DBG("-");
-}
-
-void __bt_pbap_get_vcard_list_cb(GDBusProxy *proxy,
- GAsyncResult *res, gpointer user_data)
-{
- BT_DBG("+");
- GError *error = NULL;
- int i;
- int result = BLUETOOTH_ERROR_INTERNAL;
- bt_pbap_data_t *pbap_data = user_data;
- char *address_string = pbap_data->data;
- char **vcard_list = NULL;
- char list_entry[PBAP_VCARDLIST_MAXLENGTH] = { 0, };
- int length = 0;
- GVariant *value;
- GVariant *signal = NULL;
-
- value = g_dbus_proxy_call_finish(proxy, res, &error);
- if (value == NULL) {
- BT_ERR("g_dbus_proxy_call_finish failed");
- if (error) {
- BT_ERR("errCode[%x], message[%s]\n",
- error->code, error->message);
- g_clear_error(&error);
- }
- } else {
- result = BLUETOOTH_ERROR_NONE;
- gchar *elname, *elval;
-
- GVariantIter iter;
- GVariant *child = NULL;
- GVariant *value1 = NULL;
-
- g_variant_get(value, "(@a(ss))", &value1); /* Format for value1 a(ss)*/
- gsize items = g_variant_iter_init(&iter, value1);
- vcard_list = g_new0(char *, items + 1);
-
- for (i = 0; (child = g_variant_iter_next_value(&iter)) != NULL; i++) {
- g_variant_get(child, "(&s&s)", &elname, &elval);
-
- memset(list_entry, 0, PBAP_VCARDLIST_MAXLENGTH);
-#if 0
- g_snprintf(list_entry, PBAP_VCARDLIST_MAXLENGTH - 1,
- "<card handle = \"%s\" name = \"%s\"/>", elname, elval);
-#else
- g_snprintf(list_entry, PBAP_VCARDLIST_MAXLENGTH - 1,
- "%s", elval);
-#endif
- //If possible send as Array of <STRING, STRING>
- BT_DBG("%s", list_entry);
- vcard_list[i] = g_strdup(list_entry);
- g_variant_unref(child);
- }
-
- length = i;
- g_variant_unref(value1);
- g_variant_unref(value);
- }
-
- BT_DBG("Address = %s", address_string);
- GVariant *temp = g_variant_new_strv((const gchar * const *)vcard_list, length);
- signal = g_variant_new("(isv)", result, address_string, temp);
-
- _bt_send_event(BT_PBAP_CLIENT_EVENT,
- BLUETOOTH_PBAP_VCARD_LIST,
- signal);
-
- for (i = 0; i < length; i++)
- g_free(vcard_list[i]);
-
- g_free(vcard_list);
- g_object_unref(proxy);
- __bt_pbap_free_data(pbap_data);
- BT_DBG("-");
-}
-
-void __bt_pbap_get_vcard_cb(GDBusProxy *proxy,
- GAsyncResult *res, gpointer user_data)
-{
- BT_DBG("+");
- GError *error = NULL;
- bt_pbap_data_t *pbap_data = user_data;
- char *address_string = pbap_data->data;
- bt_pbap_transfer_info_t *transfer_info;
- char *transfer = NULL;
- const gchar *filename = NULL;
- GVariant *value;
- GVariant *properties;
-
- BT_DBG("Address = %s", address_string);
- value = g_dbus_proxy_call_finish(proxy, res, &error);
- if (value == NULL) {
- BT_ERR("g_dbus_proxy_call_finish failed");
- if (error) {
- BT_ERR("errCode[%x], message[%s]\n",
- error->code, error->message);
- g_clear_error(&error);
- }
- } else {
- g_variant_get(value, "(o@a{sv})", &transfer, &properties);
-
- if (g_variant_lookup(properties, "Filename", "s", &filename) == FALSE)
- filename = NULL;
-
- BT_DBG("Transfer Path: %s", transfer);
- BT_DBG("File Name: %s", filename);
- transfer_info = g_new0(bt_pbap_transfer_info_t, 1);
- transfer_info->path = transfer;
- transfer_info->remote_device = g_strdup(address_string);
- transfer_info->filename = (char *)filename;
- transfer_info->operation = GET_VCARD;
- transfers = g_slist_append(transfers, transfer_info);
-
- g_variant_unref(properties);
- g_variant_unref(value);
- }
-
- g_object_unref(proxy);
- __bt_pbap_free_data(pbap_data);
- BT_DBG("-");
-}
-
-void __bt_pbap_search_phonebook_cb(GDBusProxy *proxy,
- GAsyncResult *res, gpointer user_data)
-{
- BT_DBG("+");
- GError *error = NULL;
- int i;
- bt_pbap_data_t *pbap_data = user_data;
- char *address_string = pbap_data->data;
- char **vcard_list = NULL;
- char list_entry[PBAP_VCARDLIST_MAXLENGTH] = { 0, };
- int length = 0;
- int result = BLUETOOTH_ERROR_INTERNAL;
- GVariant *value;
- GVariant *signal = NULL;
-
- value = g_dbus_proxy_call_finish(proxy, res, &error);
- if (value == NULL) {
- BT_ERR("g_dbus_proxy_call_finish failed");
- if (error) {
- BT_ERR("errCode[%x], message[%s]\n",
- error->code, error->message);
- g_clear_error(&error);
- }
- } else {
- result = BLUETOOTH_ERROR_NONE;
- gchar *elname, *elval;
-
- GVariantIter iter;
- GVariant *child = NULL;
- GVariant *value1 = NULL;
-
- g_variant_get(value, "(@a(ss))", &value1);
- gsize items = g_variant_iter_init(&iter, value1);
- vcard_list = g_new0(char *, items + 1);
-
- for (i = 0; (child = g_variant_iter_next_value(&iter)) != NULL; i++) {
- g_variant_get(child, "(&s&s)", &elname, &elval);
-
- memset(list_entry, 0, PBAP_VCARDLIST_MAXLENGTH);
- g_snprintf(list_entry, PBAP_VCARDLIST_MAXLENGTH - 1,
- "<card handle = \"%s\" name = \"%s\"/>", elname, elval);
- //If possible send as Array of <STRING, STRING>
- BT_DBG("%s", list_entry);
- vcard_list[i] = g_strdup(list_entry);
-
- g_variant_unref(child);
- }
- length = i;
- g_variant_unref(value1);
- g_variant_unref(value);
- }
-
- BT_DBG("Address = %s", address_string);
-
- signal = g_variant_new("(is@as)", result, address_string,
- g_variant_new_strv((const gchar * const *)vcard_list, length));
-
- _bt_send_event(BT_PBAP_CLIENT_EVENT,
- BLUETOOTH_PBAP_PHONEBOOK_SEARCH,
- signal);
-
- for (i = 0; i < length; i++)
- g_free(vcard_list[i]);
-
- g_free(vcard_list);
- g_object_unref(proxy);
- __bt_pbap_free_data(pbap_data);
- BT_DBG("-");
-}
-
-int __bt_pbap_call_get_phonebook_size(GDBusProxy *proxy, bt_pbap_data_t *pbap_data)
-{
- BT_DBG("+");
-
- g_dbus_proxy_call(proxy, "GetSize",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- (GAsyncReadyCallback)__bt_pbap_get_phonebook_size_cb,
- pbap_data);
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int __bt_pbap_call_get_phonebook(GDBusProxy *proxy, bt_pbap_data_t *pbap_data)
-{
- BT_DBG("+");
-
- int i;
- int ret;
- char *format_str = NULL;
- char *fields_str = NULL;
- char *order_str = NULL;
- char *download_path = NULL;
- char *target_file = NULL;
- bt_pbap_pull_parameters_t *app_param = pbap_data->app_param;
- GVariantBuilder builder;
- GVariantBuilder inner_builder;
- GVariant *filters;
-
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
- g_variant_builder_init(&inner_builder, G_VARIANT_TYPE_ARRAY);
-
- /* Add MaxlistCount*/
- g_variant_builder_add(&builder, "{sv}", "MaxCount",
- g_variant_new("u", app_param->maxlist));
-
- /* Add Order Filter only if other than Indexed (default)*/
- if (app_param->order > 0) {
- order_str = g_strdup(ORDER[app_param->order]);
- g_variant_builder_add(&builder, "{sv}", "Order",
- g_variant_new("s", order_str));
- }
-
- /* Add Offset Filter only if other than 0 (default)*/
- if (app_param->offset > 0) {
- g_variant_builder_add(&builder, "{sv}", "Offset",
- g_variant_new("u", app_param->offset));
- }
-
- /* Add Format Filter only if other than vCard 2.1 (default)*/
- if (app_param->format > 0) {
- format_str = g_strdup(FORMAT[app_param->format]);
- g_variant_builder_add(&builder, "{sv}", "Format",
- g_variant_new("s", format_str));
- }
-
- /* Add Filter AttributeMask (64bit) */
- if (app_param->fields > 0) {
- if (app_param->fields == PBAP_FIELD_ALL) {
- BT_DBG("** CHECKED ALL **");
- fields_str = g_strdup("ALL");
- g_variant_builder_add(&inner_builder, "s", fields_str);
- g_free(fields_str);
- } else {
- for (i = 0; i < PBAP_NUM_OF_FIELDS_ENTRY; i++) {
- if (app_param->fields & (1ULL << i)) {
- BT_DBG("** CHECKED[%d]", i);
- fields_str = g_strdup(FIELDS[i]);
- g_variant_builder_add(&inner_builder, "s", fields_str);
- g_free(fields_str);
- }
- }
- }
-
- g_variant_builder_add(&builder, "{sv}", "Fields",
- g_variant_new("as", &inner_builder));
- }
-
- filters = g_variant_builder_end(&builder);
-
-//****************************
-// Add code for Fields
-//
-//****************************
-
- ret = storage_get_directory(STORAGE_TYPE_INTERNAL,
- STORAGE_DIRECTORY_DOWNLOADS, &download_path);
-
- if (ret != STORAGE_ERROR_NONE) {
- target_file = g_strdup_printf("%s/%s", PBAP_DEFAULT_DOWNLAOD_PATH,
- PBAP_DEFAULT_FILE_NAME);
- } else {
- target_file = g_strdup_printf("%s/%s", download_path,
- PBAP_DEFAULT_FILE_NAME);
-
- if (download_path)
- free(download_path);
- }
-
- DBG_SECURE("Target flie: %s", target_file);
-
- g_dbus_proxy_call(proxy, "PullAll",
- g_variant_new("(s@a{sv})", target_file, filters),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- (GAsyncReadyCallback)__bt_pbap_get_phonebook_cb,
- pbap_data);
-
- g_free(format_str);
- g_free(order_str);
- g_free(target_file);
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int __bt_pbap_call_get_vcards_list(GDBusProxy *proxy, bt_pbap_data_t *pbap_data)
-{
- BT_DBG("+");
- char *order_str = NULL;
- char *folder = NULL;
- GVariantBuilder builder;
- GVariant *filters;
-
- bt_pbap_list_parameters_t *app_param = pbap_data->app_param;
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
-
- /* Add MaxlistCount*/
- g_variant_builder_add(&builder, "{sv}", "MaxCount",
- g_variant_new("u", app_param->maxlist));
-
- /* Add Order Filter only if other than Indexed (default)*/
- if (app_param->order > 0) {
- order_str = g_strdup(ORDER[app_param->order]);
- g_variant_builder_add(&builder, "{sv}", "Order",
- g_variant_new("s", order_str));
- }
-
- /* Add Offset Filter only if other than 0 (default)*/
- if (app_param->offset > 0) {
- g_variant_builder_add(&builder, "{sv}", "Offset",
- g_variant_new("u", app_param->offset));
- }
-
- filters = g_variant_builder_end(&builder);
-
- folder = g_strdup(TYPE[selected_path.type]);
- BT_DBG("Folder: %s", folder);
-
-
- g_dbus_proxy_call(proxy, "List",
- g_variant_new("(s@a{sv})", folder, filters),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- (GAsyncReadyCallback)__bt_pbap_get_vcard_list_cb,
- pbap_data);
-
- g_free(folder);
- g_free(order_str);
- g_hash_table_unref((GHashTable *)filters);
- /* In _bt_pbap_get_list(), path(type) is set to "nil", but current type is not null.
- The path should be reset here */
- selected_path.type = -1;
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int __bt_pbap_call_get_vcard(GDBusProxy *proxy, bt_pbap_data_t *pbap_data)
-{
- BT_DBG("+");
-
- int i;
- int ret;
- char *format_str = NULL;
- char *fields_str = NULL;
- char *target_file = NULL;
- char *download_path = NULL;
- char *vcard_handle = NULL;
- char vcard[20] = { 0, };
- GVariantBuilder builder;
- GVariantBuilder inner_builder;
- GVariant *filters;
- bt_pbap_pull_vcard_parameters_t *app_param = pbap_data->app_param;
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
- g_variant_builder_init(&inner_builder, G_VARIANT_TYPE_ARRAY);
-
- /* Add Format Filter only if other than vCard 2.1 (default)*/
-// if (app_param->format > 0) {
- format_str = g_strdup(FORMAT[app_param->format]);
- g_variant_builder_add(&builder, "{sv}", "Format",
- g_variant_new("s", format_str));
-// }
-
- /* Add Filter AttributeMask (64bit) */
- if (app_param->fields > 0) {
- if (app_param->fields == PBAP_FIELD_ALL) {
- BT_DBG("** CHECKED ALL **");
- fields_str = g_strdup("ALL");
- g_variant_builder_add(&inner_builder, "s", fields_str);
- g_free(fields_str);
- } else {
- for (i = 0; i < PBAP_NUM_OF_FIELDS_ENTRY; i++) {
- if (app_param->fields & (1ULL << i)) {
- BT_DBG("** CHECKED[%d]", i);
- fields_str = g_strdup(FIELDS[i]);
- g_variant_builder_add(&inner_builder, "s", fields_str);
- g_free(fields_str);
- }
- }
- }
-
- g_variant_builder_add(&builder, "{sv}", "Fields",
- g_variant_new("as", &inner_builder));
- }
-
- filters = g_variant_builder_end(&builder);
-
-//****************************
-// Add code for Fields
-//
-//****************************
-
- sprintf(vcard, "%d.vcf", app_param->index);
- BT_DBG("Handle: %s", vcard);
- vcard_handle = g_strdup(vcard);
- BT_DBG("vcard_handle: %s", vcard_handle);
-
- ret = storage_get_directory(STORAGE_TYPE_INTERNAL,
- STORAGE_DIRECTORY_DOWNLOADS, &download_path);
-
- if (ret != STORAGE_ERROR_NONE) {
- target_file = g_strdup_printf("%s/%s", PBAP_DEFAULT_DOWNLAOD_PATH,
- PBAP_DEFAULT_FILE_NAME);
- } else {
- if (vcard_handle)
- target_file = g_strdup_printf("%s/%s", download_path,
- vcard_handle);
- else
- target_file = g_strdup_printf("%s/%s", download_path,
- PBAP_DEFAULT_FILE_NAME);
-
- if (download_path)
- free(download_path);
- }
-
- DBG_SECURE("Target flie: %s", target_file);
-
- GVariant *temp = g_variant_new("(ss@a{sv})", vcard_handle, target_file, filters);
-
- g_dbus_proxy_call(proxy, "Pull",
- temp,
- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- (GAsyncReadyCallback)__bt_pbap_get_vcard_cb,
- pbap_data);
-
- g_free(format_str);
- g_free(vcard_handle);
- g_free(target_file);
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int __bt_pbap_call_search_phonebook(GDBusProxy *proxy, bt_pbap_data_t *pbap_data)
-{
- BT_DBG("+");
-
- char *order_str = NULL;
- char *field = NULL;
- char *value = NULL;
- bt_pbap_search_parameters_t *app_param = pbap_data->app_param;
- GVariantBuilder builder;
- GVariant *filters;
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
-
- /* Add MaxlistCount*/
- g_variant_builder_add(&builder, "{sv}", "MaxCount",
- g_variant_new("u", app_param->maxlist));
-
- /* Add Order Filter only if other than Indexed (default)*/
- if (app_param->order > 0) {
- order_str = g_strdup(ORDER[app_param->order]);
- g_variant_builder_add(&builder, "{sv}", "Order",
- g_variant_new("s", order_str));
- }
-
- /* Add Offset Filter only if other than 0 (default)*/
- if (app_param->offset > 0) {
- g_variant_builder_add(&builder, "{sv}", "Offset",
- g_variant_new("u", app_param->offset));
- }
-
- filters = g_variant_builder_end(&builder);
-
- field = g_strdup(SEARCH_FIELD[app_param->search_attribute]);
- value = g_strdup(app_param->search_value);
-
- g_dbus_proxy_call(proxy, "Search",
- g_variant_new("(ss@a{sv})", field, value, filters),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- (GAsyncReadyCallback)__bt_pbap_search_phonebook_cb,
- pbap_data);
-
- g_free(value);
- g_free(order_str);
- g_free(field);
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_pbap_is_connected(bluetooth_device_address_t *device_address,
- gboolean *connected)
-{
- char address_string[18] = { 0, };
-
- BT_CHECK_PARAMETER(device_address, return);
- BT_CHECK_PARAMETER(connected, return);
-
- /* In now, only 1 pbap connection is allowed */
- if (g_pbap_server_address == NULL) {
- *connected = FALSE;
- return 0;
- }
-
- _bt_convert_addr_type_to_string(address_string,
- (unsigned char *)device_address->addr);
- BT_DBG("Address String: %s", address_string);
-
- if (g_strcmp0(address_string, g_pbap_server_address) == 0)
- *connected = TRUE;
- else
- *connected = FALSE;
-
- return 0;
-}
-
-int _bt_pbap_get_phonebook_size(const bluetooth_device_address_t *address,
- int source, int type)
-{
- BT_DBG("+");
- GDBusConnection *g_conn;
- GDBusProxy *g_pbap_session_proxy = NULL;
- char address_string[18] = { 0, };
- char *source_string = NULL;
- char *type_string = NULL;
- GError *err = NULL;
- bt_pbap_data_t *pbap_data = NULL;
-
- BT_CHECK_PARAMETER(address, return);
-
- /* check if connected */
- if (g_pbap_session_path == NULL) {
- BT_ERR("NOT CONNECTED");
- return BLUETOOTH_ERROR_NOT_CONNECTED;
- }
-
- BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
- address->addr[0], address->addr[1],
- address->addr[2], address->addr[3],
- address->addr[4], address->addr[5]);
-
- _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
- BT_DBG("Address String: %s", address_string);
- source_string = g_strdup(SOURCE[source]);
- type_string = g_strdup(TYPE[type]);
-
- BT_DBG("Address[%s] Source[%s] Type[%s]",
- address_string, source_string, type_string);
- BT_DBG("Session Path = %s\n", g_pbap_session_path);
-
- g_conn = _bt_gdbus_get_session_gconn();
- if (g_conn == NULL) {
- BT_ERR("Couldn't connect to session bus");
- g_free(source_string);
- g_free(type_string);
- return 0;
- }
- g_pbap_session_proxy = g_dbus_proxy_new_sync(g_conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- PBAP_SESSION_SERVICE, g_pbap_session_path,
- PBAP_SESSION_INTERFACE, NULL, &err);
-
- if (!g_pbap_session_proxy) {
- BT_ERR("Failed to get a proxy for D-Bus\n");
- if (err) {
- ERR("Unable to create proxy: %s", err->message);
- g_clear_error(&err);
- }
- g_free(source_string);
- g_free(type_string);
- return -1;
- }
-
- BT_DBG("Prepare PBAP data");
- pbap_data = g_new0(bt_pbap_data_t, 1);
- pbap_data->operation = GET_SIZE;
- pbap_data->data = g_strdup(address_string);
-
- if (source == selected_path.folder && type == selected_path.type) {
- BT_DBG("Call get_phonebook_size directly");
- g_free(source_string);
- g_free(type_string);
- return __bt_pbap_call_get_phonebook_size(g_pbap_session_proxy, pbap_data);
- }
-
- BT_DBG("Call SELECT");
- g_dbus_proxy_call(g_pbap_session_proxy, "Select",
- g_variant_new("(ss)", source_string, type_string),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- (GAsyncReadyCallback)__bt_pbap_select_cb,
- pbap_data);
-
- BT_DBG("Set Folders");
- selected_path.folder = source;
- selected_path.type = type;
-
- g_free(source_string);
- g_free(type_string);
- return 0;
-}
-
-int _bt_pbap_get_phonebook(const bluetooth_device_address_t *address,
- int source, int type, bt_pbap_pull_parameters_t *app_param)
-{
- BT_DBG("+");
- GDBusConnection *g_conn;
- GDBusProxy *g_pbap_session_proxy = NULL;
- char address_string[18] = { 0, };
- char *source_string = NULL;
- char *type_string = NULL;
- GError *err = NULL;
-
- bt_pbap_data_t *pbap_data = NULL;
- bt_pbap_pull_parameters_t *param = NULL;
-
- BT_CHECK_PARAMETER(address, return);
-
- /* check if connected */
- if (g_pbap_session_path == NULL) {
- BT_ERR("NOT CONNECTED");
- return BLUETOOTH_ERROR_NOT_CONNECTED;
- }
-
- BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
- address->addr[0], address->addr[1],
- address->addr[2], address->addr[3],
- address->addr[4], address->addr[5]);
-
- _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
- BT_DBG("Address String: %s", address_string);
-
- source_string = g_strdup(SOURCE[source]);
- type_string = g_strdup(TYPE[type]);
-
- BT_DBG("Address[%s] Source[%s] Type[%s]",
- address_string, source_string, type_string);
-
- BT_DBG("Session Path = %s\n", g_pbap_session_path);
-
- g_conn = _bt_gdbus_get_session_gconn();
- if (g_conn == NULL) {
- BT_ERR("Couldn't connect to session bus");
- g_free(source_string);
- g_free(type_string);
- return 0;
- }
- g_pbap_session_proxy = g_dbus_proxy_new_sync(g_conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- PBAP_SESSION_SERVICE, g_pbap_session_path,
- PBAP_SESSION_INTERFACE, NULL, &err);
-
- if (!g_pbap_session_proxy) {
- BT_ERR("Failed to get a proxy for D-Bus\n");
- if (err) {
- ERR("Unable to create proxy: %s", err->message);
- g_clear_error(&err);
- }
- g_free(source_string);
- g_free(type_string);
- return -1;
- }
-
- pbap_data = g_new0(bt_pbap_data_t, 1);
- pbap_data->operation = PULL_ALL;
- pbap_data->data = g_strdup(address_string);
- param = g_new0(bt_pbap_pull_parameters_t, 1);
- memcpy(param, app_param, sizeof(bt_pbap_pull_parameters_t));
- pbap_data->app_param = param;
-
- if (source == selected_path.folder && type == selected_path.type) {
- g_free(source_string);
- g_free(type_string);
- return __bt_pbap_call_get_phonebook(g_pbap_session_proxy, pbap_data);
- }
-
- g_dbus_proxy_call(g_pbap_session_proxy, "Select",
- g_variant_new("(ss)", source_string, type_string),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- (GAsyncReadyCallback)__bt_pbap_select_cb,
- pbap_data);
-
- selected_path.folder = source;
- selected_path.type = type;
- g_free(source_string);
- g_free(type_string);
-
- return 0;
-}
-
-int _bt_pbap_get_list(const bluetooth_device_address_t *address, int source,
- int type, bt_pbap_list_parameters_t *app_param)
-{
- BT_DBG("+");
- GDBusConnection *g_conn;
- GDBusProxy *g_pbap_session_proxy = NULL;
- char address_string[18] = { 0, };
- char *source_string = NULL;
- char *type_string = NULL;
- GError *err = NULL;
-
- bt_pbap_data_t *pbap_data = NULL;
- bt_pbap_list_parameters_t *param = NULL;
-
- BT_CHECK_PARAMETER(address, return);
-
- /* check if connected */
- if (g_pbap_session_path == NULL) {
- BT_ERR("NOT CONNECTED");
- return BLUETOOTH_ERROR_NOT_CONNECTED;
- }
-
- BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
- address->addr[0], address->addr[1],
- address->addr[2], address->addr[3],
- address->addr[4], address->addr[5]);
-
- _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
- BT_DBG("Address String: %s", address_string);
-
- source_string = g_strdup(SOURCE[source]);
- type_string = g_strdup("nil");
-
- BT_DBG("Address[%s] Source[%s] Type[%s]",
- address_string, source_string, type_string);
-
- BT_DBG("Session Path = %s\n", g_pbap_session_path);
-
- g_conn = _bt_gdbus_get_session_gconn();
- if (g_conn == NULL) {
- BT_ERR("Couldn't connect to session bus");
- g_free(source_string);
- g_free(type_string);
- return 0;
- }
- g_pbap_session_proxy = g_dbus_proxy_new_sync(g_conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- PBAP_SESSION_SERVICE, g_pbap_session_path,
- PBAP_SESSION_INTERFACE, NULL, &err);
-
- if (!g_pbap_session_proxy) {
- BT_ERR("Failed to get a proxy for D-Bus\n");
- if (err) {
- ERR("Unable to create proxy: %s", err->message);
- g_clear_error(&err);
- }
- g_free(source_string);
- g_free(type_string);
- return -1;
- }
-
- BT_DBG("Set PBAP Data");
- pbap_data = g_new0(bt_pbap_data_t, 1);
- pbap_data->operation = GET_LIST;
- pbap_data->data = g_strdup(address_string);
- param = g_new0(bt_pbap_list_parameters_t, 1);
- memcpy(param, app_param, sizeof(bt_pbap_list_parameters_t));
- pbap_data->app_param = param;
-
- /* Always Call Select for vCardListing
- if (source == selected_path.folder && type == selected_path.type) {
- BT_DBG("Call Directly");
- return __bt_pbap_call_get_vcards_list(g_pbap_session_proxy, pbap_data);
- } */
- BT_DBG("Call SELECT");
- g_dbus_proxy_call(g_pbap_session_proxy, "Select",
- g_variant_new("(ss)", source_string, type_string),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- (GAsyncReadyCallback)__bt_pbap_select_cb,
- pbap_data);
- BT_DBG("Set Folders");
- selected_path.folder = source;
- selected_path.type = type;
- g_free(source_string);
- g_free(type_string);
-
- return 0;
-}
-
-
-int _bt_pbap_pull_vcard(const bluetooth_device_address_t *address,
- int source, int type, bt_pbap_pull_vcard_parameters_t *app_param)
-{
- BT_DBG("+");
- GDBusConnection *g_conn;
- GDBusProxy *g_pbap_session_proxy = NULL;
- char address_string[18] = { 0, };
- char *source_string = NULL;
- char *type_string = NULL;
- bt_pbap_data_t *pbap_data = NULL;
- bt_pbap_pull_vcard_parameters_t *param = NULL;
- GError *err = NULL;
-
- BT_CHECK_PARAMETER(address, return);
-
- /* check if connected */
- if (g_pbap_session_path == NULL) {
- BT_ERR("NOT CONNECTED");
- return BLUETOOTH_ERROR_NOT_CONNECTED;
- }
-
- BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
- address->addr[0], address->addr[1],
- address->addr[2], address->addr[3],
- address->addr[4], address->addr[5]);
-
- _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
- BT_DBG("Address String: %s", address_string);
-
- source_string = g_strdup(SOURCE[source]);
- type_string = g_strdup(TYPE[type]);
-
- BT_DBG("Address[%s] Source[%s] Type[%s]",
- address_string, source_string, type_string);
-
- BT_DBG("Session Path = %s\n", g_pbap_session_path);
-
- g_conn = _bt_gdbus_get_session_gconn();
- if (g_conn == NULL) {
- BT_ERR("Couldn't connect to session bus");
- g_free(source_string);
- g_free(type_string);
- return 0;
- }
- g_pbap_session_proxy = g_dbus_proxy_new_sync(g_conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- PBAP_SESSION_SERVICE, g_pbap_session_path,
- PBAP_SESSION_INTERFACE, NULL, &err);
-
- if (!g_pbap_session_proxy) {
- BT_ERR("Failed to get a proxy for D-Bus\n");
- if (err) {
- ERR("Unable to create proxy: %s", err->message);
- g_clear_error(&err);
- }
- g_free(source_string);
- g_free(type_string);
- return -1;
- }
-
- pbap_data = g_new0(bt_pbap_data_t, 1);
- pbap_data->operation = GET_VCARD;
- pbap_data->data = g_strdup(address_string);
- param = g_new0(bt_pbap_pull_vcard_parameters_t, 1);
- memcpy(param, app_param, sizeof(bt_pbap_pull_vcard_parameters_t));
- pbap_data->app_param = param;
-
- if (source == selected_path.folder && type == selected_path.type) {
- g_free(source_string);
- g_free(type_string);
- return __bt_pbap_call_get_vcard(g_pbap_session_proxy, pbap_data);
- }
-
- g_dbus_proxy_call(g_pbap_session_proxy, "Select",
- g_variant_new("(ss)", source_string, type_string),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- (GAsyncReadyCallback)__bt_pbap_select_cb,
- pbap_data);
-
- selected_path.folder = source;
- selected_path.type = type;
- g_free(source_string);
- g_free(type_string);
-
- return 0;
-}
-
-int _bt_pbap_phonebook_search(const bluetooth_device_address_t *address,
- int source, int type, bt_pbap_search_parameters_t *app_param)
-{
- BT_DBG("+");
- GDBusConnection *g_conn;
- GDBusProxy *g_pbap_session_proxy = NULL;
- char address_string[18] = { 0, };
- char *source_string = NULL;
- char *type_string = NULL;
- bt_pbap_data_t *pbap_data = NULL;
- bt_pbap_search_parameters_t *param = NULL;
- GError *err = NULL;
-
- BT_CHECK_PARAMETER(address, return);
-
- /* check if connected */
- if (g_pbap_session_path == NULL) {
- BT_ERR("NOT CONNECTED");
- return BLUETOOTH_ERROR_NOT_CONNECTED;
- }
-
- BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
- address->addr[0], address->addr[1],
- address->addr[2], address->addr[3],
- address->addr[4], address->addr[5]);
-
- _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
- BT_DBG("Address String: %s", address_string);
-
- source_string = g_strdup(SOURCE[source]);
- type_string = g_strdup(TYPE[type]);
-
- BT_DBG("Address[%s] Source[%s] Type[%s]",
- address_string, source_string, type_string);
-
- BT_DBG("Session Path = %s\n", g_pbap_session_path);
-
- g_conn = _bt_gdbus_get_session_gconn();
- if (g_conn == NULL) {
- BT_ERR("Couldn't connect to session bus");
- g_free(source_string);
- g_free(type_string);
- return 0;
- }
- g_pbap_session_proxy = g_dbus_proxy_new_sync(g_conn,
- G_DBUS_PROXY_FLAGS_NONE, NULL,
- PBAP_SESSION_SERVICE, g_pbap_session_path,
- PBAP_SESSION_INTERFACE, NULL, &err);
-
- if (!g_pbap_session_proxy) {
- BT_ERR("Failed to get a proxy for D-Bus\n");
- if (err) {
- ERR("Unable to create proxy: %s", err->message);
- g_clear_error(&err);
- }
- g_free(source_string);
- g_free(type_string);
- return -1;
- }
-
- pbap_data = g_new0(bt_pbap_data_t, 1);
- pbap_data->operation = PB_SEARCH;
- pbap_data->data = g_strdup(address_string);
- param = g_new0(bt_pbap_search_parameters_t, 1);
- memcpy(param, app_param, sizeof(bt_pbap_search_parameters_t));
- pbap_data->app_param = param;
-
- /* Call Select for vCardListing
- if (source == selected_path.folder && type == selected_path.type) {
- return __bt_pbap_call_search_phonebook(g_pbap_session_proxy, pbap_data);
- }*/
-
- g_dbus_proxy_call(g_pbap_session_proxy, "Select",
- g_variant_new("(ss)", source_string, type_string),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
- (GAsyncReadyCallback)__bt_pbap_select_cb,
- pbap_data);
-
- selected_path.folder = source;
- selected_path.type = type;
-
- g_free(source_string);
- g_free(type_string);
-
- return 0;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <gio/gio.h>
-#include <dlog.h>
-#include <string.h>
-#include <syspopup_caller.h>
-#include <vconf.h>
-#include <bundle_internal.h>
-
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-
-#include "bt-service-common.h"
-#include "bt-service-device.h"
-#include "bt-service-proximity.h"
-
-char *_bt_convert_alert_level_to_string(int value)
-{
- if (value == BT_PXP_ALERT_MILD)
- return g_strdup("mild");
- else if (value == BT_PXP_ALERT_HIGH)
- return g_strdup("high");
- else
- return g_strdup("none");
-}
-
-int _bt_convert_string_to_alert_level(const char *str)
-{
- if (g_strcmp0("high", str) == 0)
- return BT_PXP_ALERT_HIGH;
- else if (g_strcmp0("mild", str) == 0)
- return BT_PXP_ALERT_MILD;
-
- return BT_PXP_ALERT_NONE;
-}
-
-char *_bt_convert_property_to_string(int value)
-{
- if (value == BT_PXP_PROPERTY_LLS)
- return g_strdup("LinkLossAlertLevel");
- else if (value == BT_PXP_PROPERTY_IAS)
- return g_strdup("ImmediateAlertLevel");
- else if (value == BT_PXP_PROPERTY_TX_POWER)
- return g_strdup("SignalLevel");
-
- return NULL;
-}
-
-int bt_set_proximity_property(bluetooth_device_address_t *device_address,
- unsigned int property, int alert_level)
-{
- GDBusProxy *proxy;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
-
- GDBusConnection *conn;
- char *device_path = NULL;
- GError *error = NULL;
- GVariant *ret = NULL;
- char *value_str = NULL;
- char *property_str = NULL;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- device_path = _bt_get_device_object_path(address);
-
- if (device_path == NULL)
- return BLUETOOTH_ERROR_NOT_CONNECTED;
- else
- BT_INFO("device_path is created[%s]", device_path);
-
- value_str = _bt_convert_alert_level_to_string(alert_level);
- property_str = _bt_convert_property_to_string(property);
-
- if (value_str == NULL || property_str == NULL) {
- g_free(property_str);
- g_free(value_str);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
-
- g_free(device_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- ret = g_dbus_proxy_call_sync(proxy, "Set",
- g_variant_new("(ssv)", BT_PROXIMITY_MONITOR_INTERFACE, property_str, g_variant_new("s", value_str)),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (ret)
- g_variant_unref(ret);
- g_object_unref(proxy);
- g_free(property_str);
- g_free(value_str);
-
- if (error) {
- BT_ERR("SetProperty error: [%s]", error->message);
- g_error_free(error);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int bt_get_proximity_property(bluetooth_device_address_t *device_address,
- unsigned int property, int *alert_level)
-{
- GDBusProxy *proxy;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
- GDBusConnection *conn;
- char *device_path = NULL;
- GError *error = NULL;
- GVariant *result = NULL;
- GVariant *tmp_value;
- GVariant *value;
- char *value_str = NULL;
- char *property_str = NULL;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- device_path = _bt_get_device_object_path(address);
-
- if (device_path == NULL)
- return BLUETOOTH_ERROR_NOT_CONNECTED;
- else
- BT_INFO("device_path is created[%s]", device_path);
-
- property_str = _bt_convert_property_to_string(property);
-
- if (property_str == NULL)
- return BLUETOOTH_ERROR_INTERNAL;
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
-
- g_free(device_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy, "GetAll",
- g_variant_new("(s)", BT_PROXIMITY_MONITOR_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (result == NULL) {
- if (error != NULL) {
- BT_ERR("Error occured in Proxy call [%s]\n", error->message);
- g_error_free(error);
- }
- g_object_unref(proxy);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_get(result , "(@a{sv})", &value);
- g_variant_unref(result);
-
- tmp_value = g_variant_lookup_value(value, property_str, G_VARIANT_TYPE_STRING);
- if (tmp_value == NULL) {
- g_object_unref(proxy);
- g_variant_unref(value);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- value_str = (char *)g_variant_get_string(tmp_value, NULL);
- if (value_str)
- *alert_level = _bt_convert_string_to_alert_level(value_str);
-
- g_variant_unref(tmp_value);
- g_variant_unref(value);
- g_object_unref(proxy);
- g_free(property_str);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int bt_get_proximity_supported_services(bluetooth_device_address_t *device_address,
- unsigned int *supported_services)
-{
- GDBusProxy *proxy;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
-
- GDBusConnection *conn;
- char *device_path = NULL;
- GError *error = NULL;
- GVariant *result = NULL;
- GVariant *tmp_value;
- GVariant *value;
-
- BT_CHECK_PARAMETER(device_address, return);
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- device_path = _bt_get_device_object_path(address);
-
- if (device_path == NULL)
- return BLUETOOTH_ERROR_NOT_CONNECTED;
- else
- BT_INFO("device_path is created[%s]", device_path);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- device_path, BT_PROPERTIES_INTERFACE, NULL, NULL);
-
- g_free(device_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy, "GetAll",
- g_variant_new("(s)", BT_PROXIMITY_MONITOR_INTERFACE),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (result == NULL) {
- if (error != NULL) {
- BT_ERR("Error occured in Proxy call [%s]\n", error->message);
- g_error_free(error);
- }
- g_object_unref(proxy);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- g_variant_get(result , "(@a{sv})", &value);
- g_variant_unref(result);
-
- *supported_services = 0;
- tmp_value = g_variant_lookup_value(value, "LinkLossAlertLevel", G_VARIANT_TYPE_STRING);
- if (tmp_value == NULL) {
- g_object_unref(proxy);
- g_variant_unref(value);
- return BLUETOOTH_ERROR_INTERNAL;
- } else {
- *supported_services |= BT_PXP_PROPERTY_LLS;
- g_variant_unref(tmp_value);
- }
-
- tmp_value = g_variant_lookup_value(value, "ImmediateAlertLevel", G_VARIANT_TYPE_STRING);
- if (tmp_value == NULL) {
- if (*supported_services == 0) {
- g_object_unref(proxy);
- g_variant_unref(value);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- } else {
- *supported_services |= BT_PXP_PROPERTY_IAS;
- g_variant_unref(tmp_value);
- }
-
- tmp_value = g_variant_lookup_value(value, "SignalLevel", G_VARIANT_TYPE_STRING);
- if (tmp_value == NULL) {
- if (*supported_services == 0) {
- g_object_unref(proxy);
- g_variant_unref(value);
- return BLUETOOTH_ERROR_INTERNAL;
- }
- } else {
- *supported_services |= BT_PXP_PROPERTY_TX_POWER;
- g_variant_unref(tmp_value);
- }
-
- g_variant_unref(value);
- g_object_unref(proxy);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int bt_register_proximity_reporter()
-{
- GDBusProxy *proxy;
-
- GDBusConnection *conn;
- char *adapter_path = NULL;
- GError *error = NULL;
- GVariant *result = NULL;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_path = _bt_get_adapter_path();
- if (adapter_path == NULL) {
- BT_ERR("Could not get adapter path\n");
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- BT_INFO("Adapter path %s", adapter_path);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME, adapter_path,
- BT_PROXIMITY_REPORTER_INTERFACE, NULL, NULL);
-
- g_free(adapter_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy, "RegisterProximity",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
- if (result == NULL) {
- if (error != NULL) {
- BT_ERR("Error occured in Proxy call [%s]\n", error->message);
- g_error_free(error);
- }
- g_object_unref(proxy);
- return BLUETOOTH_ERROR_INTERNAL;
- } else {
- g_variant_unref(result);
- }
- g_object_unref(proxy);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int bt_unregister_proximity_reporter()
-{
- GDBusProxy *proxy;
-
- GDBusConnection *conn;
- char *adapter_path = NULL;
- GError *error = NULL;
- GVariant *result = NULL;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- adapter_path = _bt_get_adapter_path();
- if (adapter_path == NULL) {
- BT_ERR("Could not get adapter path\n");
- return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
- }
-
- BT_INFO("Adapter path %s", adapter_path);
-
- proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME, adapter_path,
- BT_PROXIMITY_REPORTER_INTERFACE, NULL, NULL);
-
- g_free(adapter_path);
- retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(proxy, "UnregisterProximity",
- NULL, G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
- if (result == NULL) {
- if (error != NULL) {
- BT_ERR("Error occured in Proxy call [%s]\n", error->message);
- g_error_free(error);
- }
- g_object_unref(proxy);
- return BLUETOOTH_ERROR_INTERNAL;
- } else {
- g_variant_unref(result);
- }
- g_object_unref(proxy);
-
- return BLUETOOTH_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <dlog.h>
-#include <string.h>
-#include <fcntl.h>
-
-#include <gio/gio.h>
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-#include "bt-service-util.h"
-#include "bt-service-rfcomm-client.h"
-#include "bt-service-rfcomm-server.h"
-
-typedef struct {
- int req_id;
- char *channel;
- char *address;
- char *uuid;
- GDBusProxy *rfcomm_proxy;
-} rfcomm_function_data_t;
-
-rfcomm_function_data_t *rfcomm_info;
-GSList *client_list;
-
-static int __bt_rfcomm_terminate_client(int socket_fd)
-{
- return BLUETOOTH_ERROR_NONE;
-}
-
-
-int _bt_rfcomm_connect_using_uuid(int request_id,
- bluetooth_device_address_t *device_address,
- char *remote_uuid)
-{
- return BLUETOOTH_ERROR_NONE;
-}
-
-/* Range of the Channel : 0 <= channel <= 30 */
-int _bt_rfcomm_connect_using_channel(int request_id,
- bluetooth_device_address_t *device_address,
- char *channel)
-{
- return BLUETOOTH_ERROR_NONE;
-}
-
-/* Be used in RFCOMM client /server */
-int _bt_rfcomm_disconnect(int socket_fd)
-{
- return __bt_rfcomm_terminate_client(socket_fd);
-}
-
-/* Be used in RFCOMM client /server */
-int _bt_rfcomm_write(int socket_fd, char *buf, int length)
-{
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_rfcomm_cancel_connect(void)
-{
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_rfcomm_is_connected(gboolean *connected)
-{
- BT_CHECK_PARAMETER(connected, return);
-
- *connected = (client_list == NULL || g_slist_length(client_list) == 0) ?
- FALSE : TRUE;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_rfcomm_is_device_connected(bluetooth_device_address_t *device_address,
- gboolean *connected)
-{
- GSList *l;
- bt_rfcomm_info_t *client_info;
- char address[BT_ADDRESS_STRING_SIZE] = { 0 };
-
- BT_CHECK_PARAMETER(device_address, return);
- BT_CHECK_PARAMETER(connected, return);
-
- _bt_convert_addr_type_to_string(address, device_address->addr);
-
- *connected = FALSE;
-
- for (l = client_list; l != NULL; l = l->next) {
- client_info = l->data;
-
- if (client_info == NULL)
- continue;
-
- if (g_strcmp0(address, client_info->address) == 0) {
- *connected = TRUE;
- return BLUETOOTH_ERROR_NONE;
- }
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_rfcomm_client_disconnect_all(void)
-{
- GSList *l;
- bt_rfcomm_info_t *client_info;
-
- for (l = client_list; l != NULL; l = l->next) {
- client_info = l->data;
-
- if (client_info == NULL)
- continue;
-
- _bt_rfcomm_disconnect(client_info->fd);
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include <dlog.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-
-#include "bluetooth-api.h"
-#include "bt-internal-types.h"
-
-#include "bt-service-common.h"
-#include "bt-service-event.h"
-#include "bt-service-util.h"
-#include "bt-service-rfcomm-client.h"
-#include "bt-service-rfcomm-server.h"
-#include "bt-service-agent.h"
-
-/* Range of RFCOMM server ID : 0 ~ 244 */
-#define BT_RFCOMM_SERVER_ID_MAX 245
-
-#define BT_RFCOMM_PROXY_ADDRESS "x00/bluez/rfcomm"
-#define BT_RFCOMM_SOCKET_ADDRESS "/bluez/rfcomm"
-
-typedef struct {
- int data_fd;
- char *uuid;
- char *remote_address;
-} bt_rfcomm_event_info_t;
-
-GSList *server_list;
-bt_rfcomm_server_info_t *_bt_rfcomm_get_server_info_using_uuid(char *uuid)
-{
- GSList *l;
- bt_rfcomm_server_info_t *server_info;
-
- retv_if(uuid == NULL, NULL);
-
- for (l = server_list; l != NULL; l = l->next) {
- server_info = l->data;
-
- if (server_info == NULL)
- continue;
-
- if (g_strcmp0(server_info->uuid, uuid) == 0)
- return server_info;
- }
-
- return NULL;
-}
-
-int _bt_rfcomm_create_socket(char *sender, char *uuid)
-{
- return BLUETOOTH_ERROR_INTERNAL;
-}
-
-int __bt_rfcomm_server_get_address(bt_rfcomm_server_info_t *server_info)
-{
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_rfcomm_listen(int socket_fd, int max_pending, gboolean is_native)
-{
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_rfcomm_remove_socket(int socket_fd)
-{
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_rfcomm_server_disconnect(int data_fd)
-{
- return BLUETOOTH_ERROR_NONE;
-}
-
-/* To support the BOT */
-int _bt_rfcomm_is_uuid_available(char *uuid, gboolean *available)
-{
- return BLUETOOTH_ERROR_NONE;
-}
-
-/* To support the BOT */
-int _bt_rfcomm_accept_connection(void)
-{
- BT_DBG("+");
- if (!_bt_agent_reply_authorize(TRUE))
- return BLUETOOTH_ERROR_INTERNAL;
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-/* To support the BOT */
-int _bt_rfcomm_reject_connection(void)
-{
- BT_DBG("+");
- if (!_bt_agent_reply_authorize(FALSE))
- return BLUETOOTH_ERROR_INTERNAL;
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_rfcomm_server_disconnect_all_connection(void)
-{
- GSList *l;
- bt_rfcomm_server_info_t *server_info;
-
- for (l = server_list; l != NULL; l = l->next) {
- server_info = l->data;
-
- if (server_info == NULL)
- continue;
-
- _bt_rfcomm_disconnect(server_info->data_fd);
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_rfcomm_server_check_existence(gboolean *existence)
-{
- BT_CHECK_PARAMETER(existence, return);
-
- if (server_list && g_slist_length(server_list) > 0)
- *existence = TRUE;
- else
- *existence = FALSE;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-int _bt_rfcomm_server_check_termination(char *name)
-{
- GSList *l;
- bt_rfcomm_server_info_t *server_info;
-
- BT_CHECK_PARAMETER(name, return);
-
- for (l = server_list; l != NULL; l = l->next) {
- server_info = l->data;
-
- if (server_info == NULL)
- continue;
-
- if (g_strcmp0(server_info->sender, name) == 0)
- _bt_rfcomm_remove_socket(server_info->control_fd);
-
- }
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <string.h>
-#include <glib.h>
-#include <dlog.h>
-#include <gio/gio.h>
-
-#include "bluetooth-api.h"
-#include "bt-service-common.h"
-#include "bt-service-util.h"
-
-static GSList *req_list = NULL;
-
-/* available request id : 0 ~ 244 */
-#define BT_REQUEST_ID_RANGE_MAX 245
-
-static int assigned_id;
-static gboolean req_id_used[BT_REQUEST_ID_RANGE_MAX];
-
-void _bt_init_request_id(void)
-{
- assigned_id = 0;
- memset(req_id_used, 0x00, BT_REQUEST_ID_RANGE_MAX);
-}
-
-int _bt_assign_request_id(void)
-{
- int index;
-
- index = assigned_id + 1;
-
- if (index >= BT_REQUEST_ID_RANGE_MAX)
- index = 0;
-
- while (req_id_used[index] == TRUE) {
- if (index == assigned_id) {
- /* No available ID */
- BT_ERR("All request ID is used");
- return -1;
- }
-
- index++;
-
- if (index >= BT_REQUEST_ID_RANGE_MAX)
- index = 0;
- }
-
- assigned_id = index;
- req_id_used[index] = TRUE;
-
- return assigned_id;
-}
-
-void _bt_delete_request_id(int request_id)
-{
- ret_if(request_id >= BT_REQUEST_ID_RANGE_MAX);
- ret_if(request_id < 0);
-
- req_id_used[request_id] = FALSE;
-}
-
-void _bt_init_request_list(void)
-{
- _bt_clear_request_list();
-}
-
-/* insert request next to head */
-int _bt_insert_request_list(int req_id, int service_function,
- char *name, GDBusMethodInvocation *context)
-{
- request_info_t *info;
-
- info = g_malloc0(sizeof(request_info_t));
- info->req_id = req_id;
- info->service_function = service_function;
- info->context = context;
-
- req_list = g_slist_append(req_list, info);
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-request_info_t *_bt_get_request_info(int req_id)
-{
- GSList *l;
- request_info_t *info;
-
- for (l = req_list; l != NULL; l = g_slist_next(l)) {
- info = l->data;
- if (info == NULL)
- continue;
-
- if (info->req_id == req_id)
- return info;
- }
-
- return NULL;
-}
-
-/* delete request which has the target req_id */
-int _bt_delete_request_list(int req_id)
-{
- GSList *l;
- request_info_t *info;
-
- for (l = req_list; l != NULL; l = g_slist_next(l)) {
- info = l->data;
- if (info == NULL)
- continue;
-
- if (info->req_id == req_id) {
- req_list = g_slist_remove(req_list, info);
- _bt_delete_request_id(info->req_id);
- g_free(info);
- return BLUETOOTH_ERROR_NONE;
- }
- }
-
- return BLUETOOTH_ERROR_NOT_FOUND;
-}
-
-void _bt_clear_request_list(void)
-{
- if (req_list) {
- g_slist_foreach(req_list, (GFunc)g_free, NULL);
- g_slist_free(req_list);
- req_list = NULL;
- }
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_REQUEST_HANDLER_H_
-#define _BT_REQUEST_HANDLER_H_
-
-#include <sys/types.h>
-#include <glib.h>
-#include <glib-object.h>
-
-#include "bt-internal-types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define BT_SERVICE_NAME "org.projectx.bt"
-#define BT_SERVICE_PATH "/org/projectx/bt_service"
-
-gboolean _is_name_acquired(void);
-
-int _bt_service_register(void);
-
-void _bt_service_unregister(void);
-
-int _bt_service_cynara_init(void);
-
-void _bt_service_cynara_deinit(void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_REQUEST_HANDLER_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_ADAPTER_LE_H_
-#define _BT_SERVICE_ADAPTER_LE_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include "bluetooth-api.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define BT_LE_SCAN_INTERVAL_MIN 2.5
-#define BT_LE_SCAN_INTERVAL_MAX 10240
-#define BT_LE_SCAN_WINDOW_MIN 2.5
-#define BT_LE_SCAN_WINDOW_MAX 10240
-
-#define BT_LE_TX_LEN_DEFAULT 0x001b
-#define BT_LE_TX_TIME_DEFAULT 0x0148
-#define BT_LE_TX_LEN_MAX 0x00fb
-#define BT_LE_TX_TIME_MAX 0x0848
-
-typedef enum {
- BT_LE_AD_TYPE_INCOMP_LIST_16_BIT_SERVICE_CLASS_UUIDS = 0x02,
- BT_LE_AD_TYPE_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS = 0x03,
- BT_LE_AD_TYPE_INCOMP_LIST_128_BIT_SERVICE_CLASS_UUIDS = 0x06,
- BT_LE_AD_TYPE_COMP_LIST_128_BIT_SERVICE_CLASS_UUIDS = 0x07,
- BT_LE_AD_TYPE_SHORTENED_LOCAL_NAME = 0x08,
- BT_LE_AD_TYPE_COMPLETE_LOCAL_NAME = 0x09,
- BT_LE_AD_TYPE_LIST_16_BIT_SERVICE_SOLICITATION_UUIDS = 0x14,
- BT_LE_AD_TYPE_LIST_128_BIT_SERVICE_SOLICITATION_UUIDS = 0x15,
- BT_LE_AD_TYPE_SERVICE_DATA = 0x16,
- BT_LE_AD_TYPE_MANUFACTURER_SPECIFIC_DATA = 0xFF,
-} bt_le_advertising_data_type_e;
-
-typedef enum {
- BT_LE_PASSIVE_SCAN = 0x00,
- BT_LE_ACTIVE_SCAN
-} bt_le_scan_type_t;
-
-typedef struct {
- char *addr;
- int addr_type;
- int rssi;
- int data_len;
- char *data;
- guint timer_id;
-} bt_le_adv_info_t;
-
-int _bt_service_adapter_le_init(void);
-
-void _bt_service_adapter_le_deinit(void);
-
-gboolean _bt_update_le_feature_support(const char *item, const char *value);
-
-const char* _bt_get_adv_slot_owner(int slot_id);
-
-int _bt_get_adv_slot_adv_handle(int slot_id);
-
-void _bt_set_advertising_status(int slot_id, gboolean mode);
-
-gboolean _bt_is_advertising(void);
-
-void _bt_stop_advertising_by_terminated_process(const char* terminated_name);
-
-int _bt_set_advertising(const char *sender, int adv_handle, gboolean enable, gboolean use_reserved_slot);
-
-int _bt_set_custom_advertising(const char *sender, int adv_handle, gboolean enable, bluetooth_advertising_params_t *params, gboolean use_reserved_slot);
-
-int _bt_hold_current_advertising(void);
-
-int _bt_get_advertising_data(bluetooth_advertising_data_t *adv, int *length);
-
-int _bt_set_advertising_data(const char *sender, int adv_handle, bluetooth_advertising_data_t *data, int length, gboolean use_reserved_slot);
-
-int _bt_get_scan_response_data(bluetooth_scan_resp_data_t *response, int *length);
-
-int _bt_set_scan_response_data(const char *sender, int adv_handle, bluetooth_scan_resp_data_t *response, int length, gboolean use_reserved_slot);
-
-int _bt_set_scan_parameters(bluetooth_le_scan_params_t *params);
-
-int _bt_prepare_scan_parameters(bluetooth_le_scan_params_t *params, int scan_type);
-
-gboolean _bt_is_scan_filter_supported(void);
-
-int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *filter);
-
-int _bt_unregister_all_scan_filters(const char *sender);
-
-int _bt_start_le_scan(const char *sender);
-
-int _bt_stop_le_scan(const char *sender);
-
-void _bt_disable_all_scanner_status(void);
-
-void _bt_set_le_scan_status(gboolean mode);
-
-gboolean _bt_is_le_scanning(void);
-
-void _bt_set_le_scan_type(bt_le_scan_type_t type);
-
-bt_le_scan_type_t _bt_get_le_scan_type(void);
-
-void _bt_send_scan_result_event(const bt_remote_le_dev_info_t *le_dev_info, const bt_le_adv_info_t *adv_info);
-
-void _bt_send_ibeacon_scan_result_event(const bt_remote_ibeacon_dev_info_t *ibeacon_dev_info);
-
-int _bt_add_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type);
-
-int _bt_remove_white_list(bluetooth_device_address_t *device_address, bluetooth_device_address_type_t address_type);
-
-int _bt_clear_white_list(void);
-
-int _bt_le_read_maximum_data_length(bluetooth_le_read_maximum_data_length_t *max_le_datalength);
-
-int _bt_le_write_host_suggested_default_data_length(const unsigned int def_tx_Octets, const unsigned int def_tx_Time);
-
-int _bt_le_read_host_suggested_default_data_length(bluetooth_le_read_host_suggested_data_length_t *def_data_length);
-
-int _bt_le_set_data_length(bluetooth_device_address_t *device_address, const unsigned int max_tx_Octets, const unsigned int max_tx_Time);
-
-int _bt_le_set_max_packet_len(void);
-
-int _bt_initialize_ipsp(void);
-
-int _bt_deinitialize_ipsp(void);
-
-void _bt_init_gatt_client_senders(void);
-
-int _bt_insert_gatt_client_sender(char *sender);
-
-int _bt_delete_gatt_client_sender(char *sender);
-
-void _bt_clear_gatt_client_senders(void);
-
-void _bt_send_char_value_changed_event(void *param);
-
-gboolean _bt_is_set_scan_parameter(void);
-
-void _bt_unregister_adv_slot_owner(int slot_id);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_ADAPTER_LE_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_ADAPTER_H_
-#define _BT_SERVICE_ADAPTER_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include "bluetooth-api.h"
-#include "alarm.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- BT_DEACTIVATED,
- BT_ACTIVATED,
- BT_ACTIVATING,
- BT_DEACTIVATING,
-} bt_status_t;
-
-typedef enum {
- BT_LE_DEACTIVATED,
- BT_LE_ACTIVATED,
- BT_LE_ACTIVATING,
- BT_LE_DEACTIVATING,
-} bt_le_status_t;
-
-int _bt_adapter_request_delayed(int function);
-
-int _bt_enable_adapter_check_status(void);
-
-int _bt_enable_adapter(void);
-
-int _bt_disable_adapter_check_status(void);
-
-void _bt_keep_bt_status_vconf(void);
-
-int _bt_disable_adapter(void);
-
-int _bt_recover_adapter(void);
-
-int _bt_enable_adapter_le(void);
-
-int _bt_disable_adapter_le(void);
-
-int _bt_reset_adapter(void);
-
-void _bt_set_bluetooth_status(void);
-
-int _bt_enable_core(void);
-
-void _bt_handle_adapter_added(void);
-
-void _bt_handle_adapter_removed(void);
-
-int _bt_check_adapter(int *status);
-
-void *_bt_get_adapter_agent(void);
-
-void _bt_service_register_poweroff_event(void);
-
-void _bt_service_unregister_poweroff_event(void);
-
-void _bt_service_register_vconf_handler(void);
-
-void _bt_service_unregister_vconf_handler(void);
-
-gboolean _bt_is_deactivated_by_flight_ps_mode(void);
-
-void _bt_set_discovery_status(gboolean mode);
-
-int _bt_get_local_address(bluetooth_device_address_t *local_address);
-
-int _bt_get_local_version(bluetooth_version_t *local_version);
-
-int _bt_get_local_name(bluetooth_device_name_t *local_name);
-
-int _bt_set_local_name(char *local_name);
-
-int _bt_is_service_used(char *service_uuid, gboolean *used);
-
-int _bt_get_discoverable_mode(int *mode);
-
-int _bt_set_discoverable_mode(int discoverable_mode, int timeout);
-
-gboolean _bt_is_connectable(void);
-
-int _bt_set_connectable(gboolean connectable);
-
-int _bt_start_discovery(void);
-
-int _bt_start_custom_discovery(bt_discovery_role_type_t role);
-
-int _bt_cancel_discovery(void);
-
-int _bt_get_bonded_devices(GArray **dev_list);
-
-int _bt_get_profile_connected_devices(char *profile_uuid, GArray **addr_list);
-
-int _bt_get_bonded_device_info(bluetooth_device_address_t *device_address,
- bluetooth_device_info_t *dev_info);
-
-int _bt_is_alias_set(bluetooth_device_address_t *device_address, gboolean *is_alias_set);
-
-int _bt_get_timeout_value(int *timeout);
-
-gboolean _bt_is_discovering(void);
-
-int _bt_enable_rssi(bluetooth_device_address_t *bd_addr, int link_type,
- int low_threshold, int in_range_threshold, int high_threshold);
-
-int _bt_get_rssi_strength(bluetooth_device_address_t *bd_addr,
- int link_type);
-
-gboolean _bt_get_advertising_params(bluetooth_advertising_params_t *params);
-
-gboolean _bt_get_cancel_by_user(void);
-
-void _bt_set_cancel_by_user(gboolean value);
-
-gboolean _bt_get_discovering_property(bt_discovery_role_type_t discovery_type);
-
-unsigned int _bt_get_discoverable_timeout_property(void);
-
-void _bt_adapter_set_status(bt_status_t status);
-
-bt_status_t _bt_adapter_get_status(void);
-
-void _bt_adapter_set_le_status(bt_le_status_t status);
-
-bt_le_status_t _bt_adapter_get_le_status(void);
-
-void _bt_adapter_set_vconf_status(gboolean enable);
-
-void _bt_set_booting_time_flag(gboolean flag);
-
-void _bt_set_le_intended_status(gboolean value);
-
-void _bt_adapter_start_enable_timer(void);
-
-void _bt_adapter_start_le_enable_timer(void);
-
-void _bt_set_disabled(int result);
-
-void _bt_set_le_disabled(int result);
-
-int _bt_set_le_privacy(gboolean set_privacy);
-
-int _bt_set_le_static_random_address(gboolean is_enable);
-
-int _bt_set_manufacturer_data(bluetooth_manufacturer_data_t *m_data);
-
-void _bt_start_log_dump(const char *path);
-
-int _bt_disable_cb(void);
-
-int _bt_get_enable_timer_id(void);
-
-void _bt_force_hci_dump(int timeout);
-
-typedef int (*bt_set_alarm_cb) (alarm_id_t alarm_id, void* user_param);
-
-int _bt_service_set_alarm(int timeout, bt_set_alarm_cb call_back,
- void *user_data, alarm_id_t *alarm_id);
-
-int _bt_service_remove_alarm(alarm_id_t alarm_id);
-
-gint compare_alarm(gconstpointer list_data, gconstpointer data);
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_ADAPTER_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef BT_SERVICE_AGENT_H
-#define BT_SERVICE_AGENT_H
-
-#include <stdint.h>
-#include <glib.h>
-#include <unistd.h>
-#include <dlog.h>
-#include <stdio.h>
-
-#undef LOG_TAG
-#define LOG_TAG "BLUETOOTH_FRWK_SERVICE"
-#define ERR(fmt, args...) SLOGE(fmt, ##args)
-
-#define BT_MAX_EVENT_STR_LENGTH 50
-
-#ifndef TIZEN_PROFILE_WEARABLE
-#define BT_FILE_VISIBLE_TIME "file/private/libug-setting-bluetooth-efl/visibility_time"
-#endif
-
-typedef enum {
- HS_PROFILE_UUID = ((unsigned short)0x1108), /**<HS*/
- AUDIO_SOURCE_UUID = ((unsigned short)0x110A), /**<AUDIO SOURCE*/
- AUDIO_SINK_UUID = ((unsigned short)0x110B), /**<AUDIO SINK*/
- AV_REMOTE_CONTROL_TARGET_UUID = ((unsigned short)0x110C),/**<AV REMOTE CONTROL TARGET*/
- ADVANCED_AUDIO_PROFILE_UUID = ((unsigned short)0x110D), /**<A2DP*/
- AV_REMOTE_CONTROL_UUID = ((unsigned short)0x110E), /**<AV REMOTE CONTROL UUID*/
- HF_PROFILE_UUID = ((unsigned short)0x111E), /**<HF*/
-} bt_agent_service_uuid_list_t;
-
-typedef enum {
- BT_AGENT_EVENT_PIN_REQUEST,
- BT_AGENT_EVENT_PASSKEY_CONFIRM_REQUEST,
- BT_AGENT_EVENT_PASSKEY_AUTO_ACCEPTED,
- BT_AGENT_EVENT_PASSKEY_REQUEST,
- BT_AGENT_EVENT_PASSKEY_DISPLAY_REQUEST,
- BT_AGENT_EVENT_AUTHORIZE_REQUEST,
- BT_AGENT_EVENT_CONFIRM_MODE_REQUEST,
- BT_AGENT_EVENT_APP_CONFIRM_REQUEST,
- BT_AGENT_EVENT_FILE_RECEIVED,
- BT_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST,
- BT_AGENT_EVENT_SECURITY,
- BT_AGENT_EVENT_TERMINATE,
- BT_AGENT_EVENT_EXCHANGE_REQUEST,
- BT_AGENT_EVENT_PBAP_REQUEST,
- BT_AGENT_EVENT_MAP_REQUEST,
- BT_AGENT_EVENT_SYSTEM_RESET_REQUEST,
- BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
-} bt_agent_event_type_t;
-
-typedef struct {
- int type;
- char *uuid;
- char *path;
- int fd;
-} bt_agent_osp_server_t;
-
-void* _bt_create_agent(const char *path, gboolean adapter);
-
-void _bt_destroy_agent(void *agent);
-
-gboolean _bt_agent_is_canceled(void);
-void _bt_agent_set_canceled(gboolean value);
-
-gboolean _bt_agent_register_osp_server(const gint type,
- const char *uuid, char *path, int fd);
-
-gboolean _bt_agent_unregister_osp_server(const gint type, const char *uuid);
-
-gboolean _bt_agent_reply_authorize(gboolean accept);
-
-int _bt_agent_reply_cancellation(void);
-
-int _bt_launch_system_popup(bt_agent_event_type_t event_type,
- const char *device_name,
- const unsigned char *auth_info,
- char *passkey,
- const char *filename,
- const char *agent_path);
-
-int _bt_set_passkey_notification(const char *sender, gboolean enable);
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_AUDIO_H_
-#define _BT_SERVICE_AUDIO_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include "bluetooth-api.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
- int req_id;
- int type;
- int disconnection_type;
- char *address;
- gboolean ag_flag;
-} bt_headset_wait_t;
-
-typedef struct {
- int key;
- const char *property;
-} bt_player_settinngs_t;
-
-typedef enum {
- BT_PENDING_NONE = 0x00,
- BT_PENDING_CONNECT,
- BT_PENDING_DISCONNECT
-} bt_pending_request_t;
-
-typedef struct {
- int req_id;
- char *address;
- bt_pending_request_t pending;
- int type;
-} bt_audio_function_data_t;
-
-typedef enum {
- BT_AUDIO_HSP = 0x01,
- BT_AUDIO_A2DP,
- BT_AUDIO_ALL,
- BT_AVRCP,
- BT_AUDIO_A2DP_SOURCE,
- BT_AVRCP_TARGET
-} bt_audio_type_t;
-
-typedef enum {
- BT_STATE_NONE = 0x00,
- BT_STATE_CONNECTING,
- BT_STATE_CONNECTED,
- BT_STATE_DISCONNECTING,
- BT_STATE_DISCONNECTED
-} bt_headset_device_state_t;
-
-#define BT_CONTENT_PROTECTION_PATH "/org/tizen/bluetooth/a2dpcontentprotection"
-#define BT_CONTENT_PROTECTION_INTERFACE "org.tizen.bluetooth.A2dpContentProtection"
-
-#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
-#define BT_AUTO_CONNECT_TIMEOUT_AFTER_BT_ACTIVATED 2 /* 2 sec */
-#define BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS 30 /* 30 sec */
-#define BT_AUTO_CONNECT_TIMEOUT_RETRY_TIME 3600 /* 60 minute */
-#endif
-
-int _bt_audio_connect(int request_id, int type,
- bluetooth_device_address_t *device_address,
- GArray *out_param1);
-
-int _bt_audio_disconnect(int request_id, int type,
- bluetooth_device_address_t *device_address,
- GArray *out_param1);
-
-int _bt_hf_connect(int request_id,
- bluetooth_device_address_t *device_address,
- GArray *out_param1);
-
-int _bt_hf_disconnect(int request_id,
- bluetooth_device_address_t *device_address,
- GArray *out_param1);
-
-int _bt_audio_get_speaker_gain(unsigned int *gain);
-
-int _bt_audio_set_speaker_gain(unsigned int gain);
-
-int _bt_audio_set_content_protect(gboolean status);
-
-void _bt_set_audio_wait_data_flag(gboolean flag);
-
-bt_headset_wait_t *_bt_get_audio_wait_data(void);
-
-void _bt_rel_wait_data(void);
-
-void _bt_add_headset_to_list(int type, int status, const char *address);
-
-void _bt_remove_headset_from_list(int type, const char *address);
-
-gboolean _bt_is_headset_type_connected(int type, char *address);
-void _bt_remove_from_connected_list(const char *address);
-
-int _bt_get_device_state_from_list(int type, const char *address);
-
-void _bt_remove_from_connected_list(const char *address);
-
-void _bt_audio_check_pending_connect();
-
-gboolean _bt_is_service_connected(char *address, int type);
-
-#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
-int _bt_audio_start_auto_connect(gboolean linkloss_flag);
-
-int _bt_audio_stop_auto_connect(void);
-
-void _bt_audio_set_auto_connect_device_addr(const char *address);
-#endif
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_AUDIO_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_AVRCP_CONTROLLER_H_
-#define _BT_SERVICE_AVRCP_CONTROLLER_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include <gio/gio.h>
-
-#include "bluetooth-api.h"
-#include "bluetooth-media-control.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define BT_MEDIA_CONTROL_PATH "%s/player0"
-
-int _bt_avrcp_control_cmd(int type);
-
-int _bt_avrcp_control_set_property(int type, unsigned int value);
-
-int _bt_avrcp_control_get_property(int type, unsigned int *value);
-
-int _bt_avrcp_control_get_track_info(media_metadata_attributes_t *metadata);
-
-void _bt_handle_avrcp_control_event(GVariant *reply, const char *path);
-
-void _bt_set_control_device_path(const char *path);
-
-void _bt_remove_control_device_path(const char *path);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_AVRCP_CONTROLLER_H_*/
-
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_AVRCP_H_
-#define _BT_SERVICE_AVRCP_H_
-
-#include <glib.h>
-#include <sys/types.h>
-
-#include "bluetooth-api.h"
-#include "bluetooth-media-control.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define BT_MEDIA_OBJECT_PATH "/Musicplayer"
-
-#define BT_AVRCP_ERROR (__bt_avrcp_error_quark())
-
-#define BT_ERROR_INTERNAL "InternalError"
-#define BT_ERROR_INVALID_PARAM "InvalidParameters"
-#define BT_ERROR_INVALID_INTERFACE "InvalidInterface"
-
-typedef enum {
- BT_AVRCP_ERROR_NONE,
- BT_AVRCP_ERROR_INTERNAL,
- BT_AVRCP_ERROR_INVALID_PARAM,
- BT_AVRCP_ERROR_NOT_SUPPORTED,
- BT_AVRCP_ERROR_INVALID_INTERFACE
-} bt_avrcp_error_t;
-
-int _bt_register_media_player(void);
-
-int _bt_unregister_media_player(void);
-
-int _bt_avrcp_set_track_info(media_metadata_attributes_t *meta_data);
-
-int _bt_avrcp_set_properties(media_player_settings_t *properties);
-
-int _bt_avrcp_set_property(int type, unsigned int value);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_AVRCP_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_COMMON_H_
-#define _BT_SERVICE_COMMON_H_
-
-#include <sys/types.h>
-#include <dlog.h>
-#include <glib.h>
-#include <gio/gio.h>
-
-#include "bluetooth-api.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#undef LOG_TAG
-#define LOG_TAG "BLUETOOTH_FRWK_SERVICE"
-
-#ifdef FUNCTION_TRACE
-#define FN_START BT_DBG("[ENTER FUNC]")
-#define FN_END BT_DBG("[EXIT FUNC]")
-#else
-#define FN_START
-#define FN_END
-#endif
-
-#define LOG_COLOR_RESET "\033[0m"
-#define LOG_COLOR_RED "\033[31m"
-#define LOG_COLOR_YELLOW "\033[33m"
-#define LOG_COLOR_GREEN "\033[32m"
-#define LOG_COLOR_BLUE "\033[36m"
-#define LOG_COLOR_PURPLE "\033[35m"
-
-
-#ifndef TIZEN_TV
-#define BT_DBG(fmt, args...) \
- SLOGD(fmt, ##args)
-#define BT_INFO(fmt, args...) \
- SLOGI(fmt, ##args)
-#define BT_ERR(fmt, args...) \
- SLOGE(fmt, ##args)
-#else
-#define BT_DBG(fmt, args...) \
- LOGI(fmt, ##args)
-#define BT_INFO(fmt, args...) \
- LOGI(fmt, ##args)
-#define BT_ERR(fmt, args...) \
- LOGE(fmt, ##args)
-#endif
-
-#define BT_INFO_C(fmt, arg...) \
- SLOGI_IF(TRUE, LOG_COLOR_GREEN" "fmt" "LOG_COLOR_RESET, ##arg)
-#define BT_ERR_C(fmt, arg...) \
- SLOGI_IF(TRUE, LOG_COLOR_RED" "fmt" "LOG_COLOR_RESET, ##arg)
-
-#define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
-#define INFO_SECURE(fmt, args...) SECURE_SLOGI(fmt, ##args)
-#define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
-
-#define ret_if(expr) \
- do { \
- if (expr) { \
- BT_ERR("(%s) return", #expr); \
- return; \
- } \
- } while (0)
-
-#define retv_if(expr, val) \
- do { \
- if (expr) { \
- BT_ERR("(%s) return", #expr); \
- return (val); \
- } \
- } while (0)
-
-#define BT_CHECK_PARAMETER(arg, func) \
- do { \
- if (arg == NULL) { \
- BT_ERR("%s is NULL", #arg); \
- func BLUETOOTH_ERROR_INVALID_PARAM; \
- } \
- } while (0)
-
-
-#define BT_ADDRESS_LENGTH_MAX 6
-#define BT_ADDRESS_STRING_SIZE 18
-#define BT_RFCOMM_BUFFER_MAX 1024
-#define BT_LOWER_ADDRESS_LENGTH 9
-
-#define BT_AGENT_AUTO_PAIR_BLACKLIST_FILE (APP_SYSCONFDIR"/auto-pair-blacklist")
-#define BT_AGENT_NEW_LINE "\r\n"
-
-#define BT_MAX_DBUS_TIMEOUT 45000
-#ifndef TIZEN_TV
-#define BT_ENABLE_TIMEOUT 20000 /* 20 seconds */
-#else
-#define BT_ENABLE_TIMEOUT 5000 /* 5 seconds */
-#endif
-#define BT_DISCOVERY_FINISHED_DELAY 200
-
-#define BT_SESSION_BUS_GET_TIMEOUT 200 /* 200 ms */
-
-#define MANAGER_EVENT_MATCH_RULE \
- "type='signal'," \
- "interface='%s'," \
- "member='%s'"
-
-#define EVENT_MATCH_RULE \
- "type='signal'," \
- "interface='%s',"
-
-#define BT_TEMINATING_WAIT_TIME 200
-
-#define BT_TIMEOUT_MESSAGE "Did not receive a reply. Possible causes include: " \
- "the remote application did not send a reply, " \
- "the message bus security policy blocked the reply, " \
- "the reply timeout expired, or the network connection " \
- "was broken."
-
-#define BT_DBUS_TIMEOUT_MESSAGE "Timeout was reached"
-
-#define BT_BLUEZ_NAME "org.bluez"
-
-#define BT_BLUEZ_PATH "/org/bluez"
-#define BT_BLUEZ_HCI_PATH "/org/bluez/hci0"
-#define BT_AGENT_NAME "org.bluez.frwk_agent"
-#define BT_AGENT_PATH "/org/bluez/agent/frwk_agent"
-#define BT_DEVICE_AGENT_PATH "/org/tizen/device_agent"
-#define BT_ADAPTER_AGENT_PATH "/org/tizen/adapter_agent"
-#define BT_MANAGER_PATH "/"
-
-
-#define BT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
-#define BT_ADAPTER_INTERFACE "org.bluez.Adapter1"
-#define BT_AGENT_INTERFACE "org.bluez.Agent1"
-#define BT_AGENT_MANAGER_INTERFACE "org.bluez.AgentManager1"
-#define BT_DEVICE_INTERFACE "org.bluez.Device1"
-#define BT_NETWORK_SERVER_INTERFACE "org.bluez.NetworkServer1"
-#define BT_MEDIA_INTERFACE "org.bluez.Media1"
-#define BT_MEDIA_PLAYER_INTERFACE "org.mpris.MediaPlayer2.Player"
-#define BT_MEDIATRANSPORT_INTERFACE "org.bluez.MediaTransport1"
-#define BT_MEDIA_CONTROL_INTERFACE "org.bluez.MediaControl1"
-#define BT_PLAYER_CONTROL_INTERFACE "org.bluez.MediaPlayer1"
-#define BT_GATT_CHAR_INTERFACE "org.bluez.GattCharacteristic1"
-
-#define BT_INPUT_INTERFACE "org.bluez.Input1"
-#define BT_NETWORK_INTERFACE "org.bluez.Network"
-#define BT_NETWORK_CLIENT_INTERFACE "org.bluez.Network1"
-#define BT_SERIAL_INTERFACE "org.bluez.Serial"
-#define BT_SERIAL_MANAGER_INTERFACE "org.bluez.SerialProxyManager"
-#define BT_SERIAL_PROXY_INTERFACE "org.bluez.SerialProxy"
-#define BT_SINK_INTERFACE "org.bluez.AudioSink"
-#define BT_AUDIO_INTERFACE "org.bluez.Audio"
-#define BT_HEADSET_INTERFACE "org.bluez.Headset"
-#define BT_OOB_INTERFACE "org.bluez.OutOfBand"
-#define BT_HANDSFREE_GATEWAY_INTERFACE "org.bluez.HandsfreeGateway"
-#define BT_OBEXD_INTERFACE "org.openobex"
-#define BT_OBEXD_MANAGER_INTERFACE "org.openobex.Manager"
-#define BT_OBEXD_TRANSFER_INTERFACE "org.openobex.Transfer"
-#define BT_A2DP_SOURCE_INTERFACE "org.bluez.AudioSource"
-#define BT_PROXIMITY_MONITOR_INTERFACE "org.bluez.ProximityMonitor1"
-#define BT_PROXIMITY_REPORTER_INTERFACE "org.bluez.ProximityReporter1"
-
-#define BT_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
-
-#define BT_OBEX_SERVICE_NAME "org.bluez.obex"
-#define BT_OBEX_CLIENT_PATH "/org/bluez/obex"
-#define BT_OBEX_CLIENT_INTERFACE "org.bluez.obex.Client1"
-
-
-
-#define BT_OBEX_TRANSFER_INTERFACE "org.bluez.obex.Transfer1"
-#define BT_OBEX_AGENT_INTERFACE "org.bluez.obex.Agent1"
-
-
-
-#define BT_OBEXD_DBUS_NAME "org.bluez.obex"
-#define BT_OBEX_OBJECT_PUSH_INTERFACE "org.bluez.obex.ObjectPush1"
-
-
-#define BT_FREEDESKTOP_INTERFACE "org.freedesktop.DBus"
-#define BT_FREEDESKTOP_PATH "/org/freedesktop/DBus"
-
-
-#define BT_DUMP_SERVICE_NAME "org.tizen.system.dumpservice"
-#define BT_DUMP_SERVICE_PATH "/Org/Tizen/System/DumpService"
-#define BT_DUMP_SERVICE_INTERFACE BT_DUMP_SERVICE_NAME
-
-#define BT_DUMP_SERVICE_SIGNAL "Dump"
-#define BT_DUMP_SERVICE_START_SIGNAL "Start"
-#define BT_DUMP_SERVICE_FINISH_SIGNAL "Finish"
-
-
-#define BT_DEVICED_POWEROFF_INTERFACE "org.tizen.system.deviced.PowerOff"
-#define BT_DEVICED_POWEROFF_OBJECT_PATH "/Org/Tizen/System/DeviceD/PowerOff"
-
-#define BT_DEVICED_POWEROFF_SIGNAL "ChangeState"
-#define BT_DEVICED_POWEROFF_SIGNAL_POWEROFF_POPUP (1)
-#define BT_DEVICED_POWEROFF_SIGNAL_POWEROFF (2)
-#define BT_DEVICED_POWEROFF_SIGNAL_REBOOT (3)
-
-
-#define BT_INTERFACES_ADDED "InterfacesAdded"
-#define BT_INTERFACES_REMOVED "InterfacesRemoved"
-#define BT_NAME_OWNER_CHANGED "NameOwnerChanged"
-#define BT_PROPERTIES_CHANGED "PropertiesChanged"
-
-
-
-#define BT_SESSION_BASEPATH_SERVER "/org/bluez/obex/server"
-#define BT_SESSION_BASEPATH_CLIENT "/org/bluez/obex/client"
-
-#define BT_SERVICE_ERR_MSG_NOT_SUPPORTED "Operation is not supported"
-
-/* UUID */
-#define GENERIC_AUDIO_UUID "00001203-0000-1000-8000-00805f9b34fb"
-
-#define AVRCP_TARGET_UUID "0000110c-0000-1000-8000-00805f9b34fb"
-#define AVRCP_REMOTE_UUID "0000110e-0000-1000-8000-00805f9b34fb"
-#define ADVANCED_AUDIO_UUID "0000110d-0000-1000-8000-00805f9b34fb"
-#define A2DP_SINK_UUID "0000110b-0000-1000-8000-00805f9b34fb"
-#define A2DP_SOURCE_UUID "0000110a-0000-1000-8000-00805f9b34fb"
-
-#define HFP_HS_UUID "0000111e-0000-1000-8000-00805f9b34fb"
-#define HFP_AG_UUID "0000111f-0000-1000-8000-00805f9b34fb"
-
-#define HSP_HS_UUID "00001108-0000-1000-8000-00805f9b34fb"
-#define HSP_AG_UUID "00001112-0000-1000-8000-00805f9b34fb"
-
-#define RFCOMM_UUID_STR "00000003-0000-1000-8000-00805f9b34fb"
-#define HID_DEVICE_UUID "00001124-0000-1000-8000-00805f9b43bf"
-#define HID_UUID "00001124-0000-1000-8000-00805f9b34fb"
-#define PANU_UUID "00001115-0000-1000-8000-00805f9b34fb"
-#define NAP_UUID "00001116-0000-1000-8000-00805f9b34fb"
-#define PNP_UUID "00001200-0000-1000-8000-00805f9b34fb"
-#define PBAP_UUID "0000112f-0000-1000-8000-00805f9b34fb"
-
-#define OBEX_OPP_UUID "00001105-0000-1000-8000-00805f9b34fb"
-#define OBEX_PSE_UUID "0000112f-0000-1000-8000-00805f9b34fb"
-
-#define GATT_UUID "00001801-0000-1000-8000-00805f9b34fb"
-
-/* Privilege */
-#define BT_PRIVILEGE_PUBLIC "http://tizen.org/privilege/bluetooth"
-#define BT_PRIVILEGE_PLATFORM "http://tizen.org/privilege/bluetooth.admin"
-#define MEDIASTORAGE_PRIVILEGE "http://tizen.org/privilege/mediastorage"
-
-/* BD Address type */
-#define BDADDR_BREDR 0x00
-#define BDADDR_LE_PUBLIC 0x01
-#define BDADDR_LE_RANDOM 0x02
-
-/* Advertising report event types */
-#define BT_LE_ADV_IND 0x00
-#define BT_LE_ADV_DIRECT_IND 0x01
-#define BT_LE_ADV_SCAN_IND 0x02
-#define BT_LE_ADV_NONCONN_IND 0x03
-#define BT_LE_ADV_SCAN_RSP 0x04
-
-/* Profile states matched to btd_service_state_t of bluez service.h */
-typedef enum {
- BT_PROFILE_STATE_UNAVAILABLE,
- BT_PROFILE_STATE_DISCONNECTED,
- BT_PROFILE_STATE_CONNECTING,
- BT_PROFILE_STATE_CONNECTED,
- BT_PROFILE_STATE_DISCONNECTING,
-} bt_profile_state_t;
-
-typedef enum {
- BT_ADV_IND_INFO = 0x00,
- BT_SCAN_RSP_INFO = 0x01,
-} bt_le_device_info_type_t;
-
-typedef enum {
- BT_PROFILE_CONN_RFCOMM = 0x01,
- BT_PROFILE_CONN_A2DP = 0x02,
- BT_PROFILE_CONN_HSP = 0x04,
- BT_PROFILE_CONN_HID = 0x08,
- BT_PROFILE_CONN_NAP = 0x10,
- BT_PROFILE_CONN_HFG = 0x20,
- BT_PROFILE_CONN_GATT = 0x40,
- BT_PROGILE_CONN_NAP = 0x80,
- BT_PROFILE_CONN_A2DP_SINK = 0x100,
- BT_PROFILE_CONN_PBAP = 0x200,
- BT_PROFILE_CONN_ALL = 0xffffffff,
-} bt_profile_type_t;
-
-typedef struct {
- char *address;
- int addr_type;
- int rssi;
- int adv_type;
- bt_le_device_info_type_t dev_type;
- int adv_data_len;
- char *adv_data;
-} bt_remote_le_dev_info_t;
-
-typedef struct {
- char *address;
- int addr_type;
- int rssi;
- int adv_type;
- int company_id;
- int ibeacon_type;
- int major_id;
- int minor_id;
- int measured_power;
- char *uuid;
-} bt_remote_ibeacon_dev_info_t;
-
-typedef struct {
- int rssi;
- int class;
- char *address;
- char *name;
- char **uuids;
- unsigned int uuid_count;
- gboolean paired;
- bluetooth_connected_link_t connected;
- gboolean trust;
- gboolean is_alias_set;
- char *manufacturer_data;
- int manufacturer_data_len;
- guchar addr_type;
-#if 0 /* Should match with bt_dev_info_t in bluetooth-api.h */
- bt_remote_le_dev_info_t le_dev_info;
-#endif
-} bt_remote_dev_info_t;
-
-/* RFCOMM client /server will use this structure*/
-typedef struct {
- int fd;
- GIOChannel *io_channel;
- guint io_event;
- char *dev_node;
- char *address;
- char *uuid;
-} bt_rfcomm_info_t;
-
-typedef struct {
- int req_id;
- char *address;
-} bt_function_data_t;
-
-GDBusConnection *_bt_gdbus_get_system_gconn(void);
-
-GDBusConnection *_bt_gdbus_get_session_gconn(void);
-
-void *_bt_get_net_conn(void);
-
-GDBusProxy *_bt_get_manager_proxy(void);
-
-GDBusProxy *_bt_get_adapter_proxy(void);
-
-GDBusProxy *_bt_get_adapter_properties_proxy(void);
-
-char *_bt_get_device_object_path(char *address);
-
-char *_bt_get_profile_uuid128(bt_profile_type_t profile_type);
-
-const char *_bt_convert_uuid_to_string(const char *uuid);
-
-const char *_bt_convert_error_to_string(int error);
-
-const char *_bt_convert_disc_reason_to_string(int reason);
-
-const char *_bt_convert_profile_state_to_string(bt_profile_state_t state);
-
-const char *_bt_convert_service_function_to_string(int function);
-
-void _bt_logging_connection(gboolean connect, int addr_type);
-
-char *_bt_get_adapter_path(void);
-
-void _bt_deinit_proxys(void);
-
-void _bt_convert_device_path_to_address(const char *device_path,
- char *device_address);
-
-void _bt_convert_addr_string_to_type(unsigned char *addr,
- const char *address);
-
-void _bt_convert_addr_string_to_secure_string(char *addr,
- const char *address);
-
-void _bt_convert_addr_type_to_string(char *address,
- unsigned char *addr);
-
-void _bt_swap_byte_ordering(char *data, int data_len);
-
-int _bt_byte_arr_cmp(const char *data1, const char *data2, int data_len);
-
-int _bt_byte_arr_cmp_with_mask(const char *data1, const char *data2,
- const char *mask, int data_len);
-
-void _bt_print_device_address_t(const bluetooth_device_address_t *addr);
-
-void _bt_divide_device_class(bluetooth_device_class_t *device_class,
- unsigned int cod);
-
-void _bt_free_device_info(bt_remote_dev_info_t *dev_info);
-
-void _bt_free_le_device_info(bt_remote_le_dev_info_t *le_dev_info);
-
-int _bt_copy_utf8_string(char *dest, const char *src, unsigned int length);
-
-gboolean _bt_utf8_validate(char *name);
-
-int _bt_register_osp_server_in_agent(int type, char *uuid, char *path, int fd);
-
-int _bt_unregister_osp_server_in_agent(int type, char *uuid);
-
-int _bt_set_socket_non_blocking(int socket_fd);
-
-int _bt_set_non_blocking_tty(int sk);
-
-void _bt_deinit_bluez_proxy(void);
-
-int _bt_eventsystem_set_value(const char *event, const char *key, const char *value);
-
-void __bt_get_auth_info(GVariant *reply, char *auth_info);
-
-int _bt_convert_gerror(GError *g_error);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_COMMON_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_DEVICE_H_
-#define _BT_SERVICE_DEVICE_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include "bluetooth-api.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int _bt_bond_device(int request_id,
- bluetooth_device_address_t *device_address,
- unsigned short conn_type, GArray **out_param1);
-
-int _bt_cancel_bonding(void);
-
-int _bt_passkey_reply(const char *passkey, gboolean authentication_reply);
-
-int _bt_passkey_confirmation_reply(gboolean confirmation_reply);
-
-int _bt_unbond_device(int request_id,
- bluetooth_device_address_t *device_address,
- GArray **out_param1);
-
-int _bt_cancel_search_device(void);
-
-int _bt_search_device(int request_id,
- bluetooth_device_address_t *device_address);
-
-int _bt_set_alias(bluetooth_device_address_t *device_address,
- const char *alias);
-
-int _bt_set_authorization(bluetooth_device_address_t *device_address,
- gboolean authorize);
-
-int _bt_is_gatt_connected(bluetooth_device_address_t *device_address,
- gboolean *is_connected);
-
-int _bt_is_device_connected(bluetooth_device_address_t *device_address,
- int connection_type, gboolean *is_connected);
-
-int _bt_get_connected_link(bluetooth_device_address_t *device_address,
- bluetooth_connected_link_t *connected);
-
-int _bt_set_pin_code(bluetooth_device_address_t *device_address,
- bluetooth_device_pin_code_t *pin_code);
-
-int _bt_unset_pin_code(bluetooth_device_address_t *device_address);
-
-int _bt_get_device_pin_code(const char *address, char *pin_code);
-
-gboolean _bt_is_device_creating(void);
-
-void _bt_set_autopair_status_in_bonding_info(gboolean is_autopair);
-
-bt_remote_dev_info_t *_bt_get_remote_device_info(char *address);
-
-bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(const char *object_path);
-
-char *_bt_get_device_name(const char *address);
-
-gboolean _bt_is_bonding_device_address(const char *address);
-
-void _bt_pending_connect_le_device(void);
-
-int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
- gboolean auto_connect);
-
-int _bt_disconnect_le_device(int req_id,
- const bluetooth_device_address_t *bd_addr);
-
-void _bt_add_le_connected_dev_info(const char *address);
-void _bt_remove_le_connected_dev_info(const char *address);
-int _bt_remove_all_le_conn_param_info(const char *sender);
-
-int _bt_le_conn_update(const char *sender,
- unsigned char *device_address,
- float interval_min, float interval_max,
- guint16 latency, guint16 time_out);
-
-int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode,
- bluetooth_le_connection_param_t *param);
-
-int _bt_connect_profile(char *address, char *uuid,
- void *cb, gpointer func_data);
-
-int _bt_disconnect_all(char *address);
-
-int _bt_disconnect_profile(char *address, char *uuid,
- void *cb, gpointer func_data);
-
-int _bt_request_att_mtu(int request_id, bluetooth_device_address_t *device_address,
- unsigned int mtu);
-
-int _bt_get_att_mtu(bluetooth_device_address_t *device_address,
- unsigned int *mtu);
-
-int _bt_get_device_ida(bluetooth_device_address_t *device_address,
- bluetooth_device_address_t *id_address);
-
-int _bt_set_trust_profile(bluetooth_device_address_t *bd_addr,
- bluetooth_trusted_profile_t profile, gboolean trust);
-
-int _bt_get_trust_profile(bluetooth_device_address_t *bd_addr,
- bluetooth_trusted_profile_t profile, guint *trust);
-
-int _bt_set_restrict_profile(bluetooth_device_address_t *bd_addr,
- bluetooth_restricted_profile_t profile, gboolean restricted);
-
-int _bt_get_restrict_profile(bluetooth_device_address_t *bd_addr,
- bluetooth_restricted_profile_t profile, guint *restricted);
-
-bluetooth_trusted_profile_t _bt_get_trusted_profile_enum(const char *uuid);
-
-int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr);
-
-int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr);
-
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_ADAPTER_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifdef TIZEN_DPM_ENABLE
-
-#ifndef _BT_SERVICE_DPM_H_
-#define _BT_SERVICE_DPM_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include "bluetooth-api.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
- /**
- * @brief DPM BT allowance state
- * @see
- */
-typedef enum {
- DPM_BT_ERROR = -1, /**< bluetooth allowance error */
- DPM_BT_ALLOWED, /**< bluetooth allowance allowed */
- DPM_BT_HANDSFREE_ONLY, /**< bluetooth allowance handsfree only */
- DPM_BT_RESTRICTED, /**< bluetooth allowance restricted */
-} dpm_bt_allow_t;
-
- /**
- * @brief DPM API result
- * @see
- */
-typedef enum _dpm_result {
- DPM_RESULT_SERVICE_NOT_ENABLED = -5, /**< DPM API result service not enabled. */
- DPM_RESULT_ACCESS_DENIED = -4, /**< DPM API result access denied. */
- DPM_RESULT_INVALID_PARAM = -3, /**< DPM API result invalid parameter. */
- DPM_RESULT_NOT_SUPPORTED = -2, /**< DPM API result not supported. */
- DPM_RESULT_FAIL = -1, /**< DPM API result fail. */
- DPM_RESULT_SUCCESS = 0, /**< DPM API result success. */
-} dpm_result_t;
-
-/**
- * @brief DPM Policy status
- * @see
- */
-typedef enum _dpm_status {
- DPM_STATUS_ERROR = -1,
-
- DPM_ALLOWED = 0, /**< DPM Policy status allowed. */
- DPM_RESTRICTED = 1, /**< DPM Policy status restricted. */
-
- DPM_ENABLE = 1, /**< DPM Policy status enabled. */
- DPM_DISABLE = 0, /**< DPM Policy status disabled. */
-
- DPM_FALSE = 0, /**< DPM Policy status false. */
- DPM_TRUE = 1, /**< DPM Policy status true. */
-} dpm_status_t;
-
-typedef enum _dpm_policy_cmd {
- /* policy-group : BLUETOOTH */
- DPM_POLICY_ALLOW_BLUETOOTH,
- DPM_POLICY_BLUETOOTH_DEVICE_RESTRICTION,
- DPM_POLICY_BLUETOOTH_UUID_RESTRICTION,
- DPM_POLICY_BLUETOOTH_DEVICES_WHITELIST,
- DPM_POLICY_BLUETOOTH_DEVICES_BLACKLIST,
- DPM_POLICY_BLUETOOTH_UUIDS_WHITELIST,
- DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST,
- DPM_POLICY_ALLOW_BLUETOOTH_OUTGOING_CALL,
- DPM_POLICY_BLUETOOTH_PAIRING_STATE,
- DPM_POLICY_BLUETOOTH_DESKTOP_CONNECTIVITY_STATE,
- DPM_POLICY_BLUETOOTH_DISCOVERABLE_STATE,
- DPM_POLICY_BLUETOOTH_LIMITED_DISCOVERABLE_STATE,
- DPM_POLICY_BLUETOOTH_DATA_TRANSFER_STATE,
- DPM_POLICY_END,
-} dpm_policy_cmd_t;
-
-
-struct dpm_policy {
- union {
- int value;
- GSList *list;
- };
-};
-typedef struct dpm_policy dpm_policy_t;
-
-
-typedef enum dpm_profile {
- DPM_POLICY_BLUETOOTH_A2DP_PROFILE_STATE,
- DPM_POLICY_BLUETOOTH_AVRCP_PROFILE_STATE,
- DPM_POLICY_BLUETOOTH_BPP_PROFILE_STATE,
- DPM_POLICY_BLUETOOTH_DUN_PROFILE_STATE,
- DPM_POLICY_BLUETOOTH_FTP_PROFILE_STATE,
- DPM_POLICY_BLUETOOTH_HFP_PROFILE_STATE,
- DPM_POLICY_BLUETOOTH_HSP_PROFILE_STATE,
- DPM_POLICY_BLUETOOTH_PBAP_PROFILE_STATE,
- DPM_POLICY_BLUETOOTH_SAP_PROFILE_STATE,
- DPM_POLICY_BLUETOOTH_SPP_PROFILE_STATE,
- DPM_PROFILE_NONE,
-} dpm_profile_t;
-
-struct dpm_profile_val {
- int value; /* tells whether the profile is enabled or disabled */
-};
-typedef struct dpm_profile_val dpm_profile_state_t;
-
-dpm_result_t _bt_dpm_set_allow_bluetooth_mode(dpm_bt_allow_t value);
-dpm_bt_allow_t _bt_dpm_get_allow_bluetooth_mode(void);
-dpm_result_t _bt_dpm_activate_bluetooth_device_restriction(dpm_status_t value);
-dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void);
-dpm_result_t _bt_dpm_activate_bluetoooth_uuid_restriction(dpm_status_t value);
-dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void);
-dpm_result_t _bt_dpm_add_bluetooth_devices_to_blacklist(bluetooth_device_address_t *bd_addr);
-dpm_result_t _bt_dpm_add_bluetooth_devices_to_whitelist(bluetooth_device_address_t *bd_addr);
-dpm_result_t _bt_dpm_add_bluetooth_uuids_to_blacklist(const char *uuid);
-dpm_result_t _bt_dpm_add_bluetooth_uuids_to_whitelist(const char *uuid);
-dpm_result_t _bt_dpm_set_allow_bluetooth_outgoing_call(dpm_status_t value);
-dpm_status_t _bt_dpm_get_allow_bluetooth_outgoing_call(void);
-dpm_result_t _bt_dpm_clear_bluetooth_devices_from_blacklist(void);
-dpm_result_t _bt_dpm_clear_bluetooth_devices_from_whitelist(void);
-dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_blacklist(void);
-dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_whitelist(void);
-dpm_result_t _bt_dpm_get_bluetooth_devices_from_blacklist(GArray **out_param1);
-dpm_result_t _bt_dpm_get_bluetooth_devices_from_whitelist(GArray **out_param1);
-dpm_result_t _bt_dpm_get_bluetooth_uuids_from_blacklist(GArray **out_param1);
-dpm_result_t _bt_dpm_get_bluetooth_uuids_from_whitelist(GArray **out_param1);
-dpm_status_t _bt_dpm_is_bluetooth_device_restriction_active(void);
-dpm_status_t _bt_dpm_is_bluetooth_uuid_restriction_active(void);
-dpm_status_t _bt_dpm_set_bluetooth_pairing_state(dpm_status_t value);
-dpm_status_t _bt_dpm_get_bluetooth_pairing_state(void);
-dpm_status_t _bt_dpm_set_bluetooth_profile_state(dpm_profile_t profile, dpm_status_t value);
-dpm_status_t _bt_dpm_get_bluetooth_profile_state(dpm_profile_t profile);
-dpm_status_t _bt_dpm_set_bluetooth_desktop_connectivity_state(dpm_status_t value);
-dpm_status_t _bt_dpm_get_bluetooth_desktop_connectivity_state(void);
-dpm_status_t _bt_dpm_set_bluetooth_discoverable_state(dpm_status_t value);
-dpm_status_t _bt_dpm_get_bluetooth_discoverable_state(void);
-dpm_result_t _bt_dpm_clear_bluetooth_devices_from_list(void);
-dpm_result_t _bt_dpm_clear_bluetooth_uuids_from_list(void);
-dpm_status_t _bt_dpm_set_bluetooth_limited_discoverable_state(dpm_status_t value);
-dpm_status_t _bt_dpm_get_bluetooth_limited_discoverable_state(void);
-dpm_status_t _bt_dpm_set_bluetooth_data_transfer_state(dpm_status_t value);
-dpm_status_t _bt_dpm_get_allow_bluetooth_data_transfer_state(void);
-dpm_result_t _bt_dpm_remove_bluetooth_devices_from_whitelist(bluetooth_device_address_t *bd_addr);
-dpm_result_t _bt_dpm_remove_bluetooth_devices_from_blacklist(bluetooth_device_address_t *bd_addr);
-dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_whitelist(const char *uuids);
-dpm_result_t _bt_dpm_remove_bluetooth_uuids_from_blacklist(const char *uuids);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_DPM_H_*/
-#endif /* #ifdef TIZEN_DPM_ENABLE */
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_EVENT_H_
-#define _BT_SERVICE_EVENT_H_
-
-#include <sys/types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int _bt_send_event(int event_type, int event, GVariant *param);
-
-int _bt_send_event_to_dest(const char* dest, int event_type, int event, GVariant *param);
-
-int _bt_init_service_event_sender(void);
-void _bt_deinit_service_event_sender(void);
-
-int _bt_init_service_event_receiver(void);
-void _bt_deinit_service_event_receiver(void);
-
-int _bt_opp_client_event_init(void);
-void _bt_opp_client_event_deinit(void);
-
-int _bt_send_hf_local_term_event(char *address);
-int _bt_init_hf_local_term_event_sender(void);
-void _bt_deinit_hf_local_term_event_sender(void);
-
-int _bt_send_dump_signal(char *signal);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_EVENT_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef SC_CORE_AGENT_H
-#define SC_CORE_AGENT_H
-
-#include <stdint.h>
-#include <glib.h>
-#include <gio/gio.h>
-
-#define BLUEZ_DEVICE_INTERFACE "org.bluez.Device"
-
-typedef enum {
- GAP_AGENT_EXEC_NO_OPERATION,
- GAP_AGENT_EXEC_PAIRING,
- GAP_AGENT_EXEC_AUTHORZATION,
- GAP_AGENT_EXEC_CONFIRM_MODE,
-} GapAgentExecType;
-
-typedef struct _GapAgentPrivate GapAgentPrivate;
-
-typedef gboolean(*GapAgentPasskeyFunc) (GapAgentPrivate *agent,
- GDBusProxy *device);
-typedef gboolean(*GapAgentDisplayFunc) (GapAgentPrivate *agent, GDBusProxy *device,
- guint passkey);
-typedef gboolean(*GapAgentConfirmFunc) (GapAgentPrivate *agent, GDBusProxy *device,
- guint passkey);
-typedef gboolean(*GapAgentAuthorizeFunc) (GapAgentPrivate *agent,
- GDBusProxy *device, const char *uuid);
-typedef gboolean(*GapAgentConfirmModeFunc) (GapAgentPrivate *agent,
- const char *mode, const char *sender,
- gboolean need_popup, void *data);
-typedef gboolean(*GapAgentCancelFunc) (GapAgentPrivate *agent,
- const char *address);
-typedef gboolean(*GapAgentIgnoreAutoPairingFunc) (const char *address);
-typedef uint8_t bool_t;
-
-typedef struct {
- GapAgentPasskeyFunc pincode_func;
- GapAgentDisplayFunc display_func;
- GapAgentPasskeyFunc passkey_func;
- GapAgentConfirmFunc confirm_func;
- GapAgentAuthorizeFunc authorize_func;
- GapAgentCancelFunc pairing_cancel_func;
- GapAgentCancelFunc authorization_cancel_func;
-} GAP_AGENT_FUNC_CB;
-
-typedef enum {
- GAP_AGENT_ACCEPT,
- GAP_AGENT_REJECT,
- GAP_AGENT_CANCEL,
- GAP_AGENT_TIMEOUT,
- GAP_AGENT_ACCEPT_ALWAYS,
-} GAP_AGENT_ACCEPT_TYPE_T;
-
-struct _GapAgentPrivate {
- gchar *busname;
- gchar *path;
-
- GDBusProxy *agent_manager;
-
- GDBusProxy *dbus_proxy;
-
- GapAgentExecType exec_type;
- GDBusMethodInvocation *reply_context;
- char *uuid;
-
- char pairing_addr[18];
- char authorize_addr[18];
-
- GSList *osp_servers;
-
- GAP_AGENT_FUNC_CB cb;
- gboolean canceled;
-};
-
-void _gap_agent_setup_dbus(GapAgentPrivate *agent, GAP_AGENT_FUNC_CB *func_cb,
- const char *path, GDBusProxy *adapter);
-gboolean _gap_agent_register(GapAgentPrivate *agent);
-void _gap_agent_reset_dbus(GapAgentPrivate *agent);
-
-gboolean gap_agent_reply_pin_code(GapAgentPrivate *agent, const guint accept,
- const char *pin_code,
- GDBusMethodInvocation *context);
-gboolean gap_agent_reply_passkey(GapAgentPrivate *agent, const guint accept,
- const char *passkey,
- GDBusMethodInvocation *context);
-gboolean gap_agent_reply_confirmation(GapAgentPrivate *agent, const guint accept,
- GDBusMethodInvocation *context);
-gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
- GDBusMethodInvocation *context);
-
-gboolean _gap_agent_exist_osp_server(GapAgentPrivate *agent, int type, char *uuid);
-
-bt_agent_osp_server_t *_gap_agent_get_osp_server(GapAgentPrivate *agent, int type,
- char *uuid);
-
-gchar* _gap_agent_get_path(GapAgentPrivate *agent);
-
-gboolean _gap_agent_is_canceled(GapAgentPrivate *agent);
-
-void _gap_agent_set_canceled(GapAgentPrivate *agent, gboolean value);
-
-gboolean _gap_agent_register_osp_server(GapAgentPrivate *agent,
- const gint type,
- const char *uuid,
- const char *path,
- int fd);
-
-gboolean _gap_agent_unregister_osp_server(GapAgentPrivate *agent,
- const gint type,
- const char *uuid);
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __BT_SERVICE_HEADSET_CONNECTION__
-#define __BT_SERVICE_HEADSET_CONNECTION__
-
-#undef LOG_TAG
-#define LOG_TAG "BLUETOOTH_FRWK_SERVICE"
-#define ERR(fmt, args...) SLOGE(fmt, ##args)
-
-#define CONNECT_TIMEOUT (3 * 1000)
-
-void _bt_headset_set_local_connection(gboolean value);
-gboolean _bt_headset_get_local_connection();
-void _bt_start_timer_for_connection(char *remote_address, int connection_type);
-void __bt_connection_manager_set_state(char *remote_address, int event);
-
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_HID_H_
-#define _BT_SERVICE_HID_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include "bluetooth-api.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int _bt_hid_connect(int request_id,
- bluetooth_device_address_t *device_address);
-
-int _bt_hid_disconnect(int request_id,
- bluetooth_device_address_t *device_address);
-
-int _bt_hid_enable_barcode_feature(void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_HID_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_NETWORK_H_
-#define _BT_SERVICE_NETWORK_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include "bluetooth-api.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define NAP_UUID_NAME "nap"
-#define GN_UUID_NAME "gn"
-#define PANU_UUID_NAME "panu"
-#define NET_BRIDGE_INTERFACE "pan0"
-
-int _bt_network_activate(void);
-
-int _bt_network_deactivate(void);
-
-int _bt_network_connect(int request_id, int role,
- bluetooth_device_address_t *device_address);
-
-int _bt_network_disconnect(int request_id,
- bluetooth_device_address_t *device_address);
-
-int _bt_network_server_disconnect(int request_id,
- bluetooth_device_address_t *device_address);
-
-void *_bt_network_connected_profile(void *connection, unsigned char *address);
-
-int _bt_is_network_connected(void *connection, unsigned char *address,
- gboolean *is_connected);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_NETWORK_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef __BT_SERVICE_OBEX_AGENT_H
-#define __BT_SERVICE_OBEX_AGENT_H
-
-#include <glib-object.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef enum {
- BT_OBEX_AGENT_ERROR_REJECT,
- BT_OBEX_AGENT_ERROR_CANCEL,
- BT_OBEX_AGENT_ERROR_TIMEOUT,
-} bt_agent_error_t;
-
-G_BEGIN_DECLS
-typedef struct {
- GObject parent;
-} BtObexAgent;
-
-typedef struct {
- GObjectClass parent_class;
-} BtObexAgentClass;
-
-GType bt_obex_agent_get_type(void);
-
-#define BT_OBEX_TYPE_AGENT (bt_obex_agent_get_type())
-#define BT_OBEX_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), BT_OBEX_TYPE_AGENT, BtObexAgent))
-#define BT_OBEX_AGENT_CLASS(agent_class) (G_TYPE_CHECK_CLASS_CAST((agent_class), BT_OBEX_TYPE_AGENT, BtObexAgentClass))
-#define BT_OBEX_GET_AGENT_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), BT_OBEX_TYPE_AGENT, BtObexAgentClass))
-
-typedef gboolean(*bt_obex_authorize_cb)(GDBusMethodInvocation *context,
- const char *path,
- gpointer data);
-
-typedef gboolean(*bt_obex_request_cb)(GDBusMethodInvocation *context,
- GDBusProxy *transfer,
- gpointer data);
-
-typedef gboolean(*bt_obex_progress_cb)(GDBusMethodInvocation *context,
- GDBusProxy *transfer,
- guint64 transferred,
- gpointer data);
-
-typedef gboolean(*bt_obex_error_cb)(GDBusMethodInvocation *context,
- GDBusProxy *transfer,
- const char *message,
- gpointer data);
-
-typedef gboolean(*bt_obex_complete_cb)(GDBusMethodInvocation *context,
- GDBusProxy *transfer,
- gpointer data);
-
-typedef gboolean(*bt_obex_release_cb)(GDBusMethodInvocation *context,
- gpointer data);
-
-G_END_DECLS
-
-void _bt_obex_set_authorize_cb(char *object_path,
- bt_obex_authorize_cb func,
- gpointer data);
-
-void _bt_obex_set_request_cb(char *object_path,
- bt_obex_request_cb func,
- gpointer data);
-
-void _bt_obex_set_progress_cb(char *object_path,
- bt_obex_progress_cb func,
- gpointer data);
-
-void _bt_obex_set_error_cb(char *object_path,
- bt_obex_error_cb func,
- gpointer data);
-
-void _bt_obex_set_complete_cb(char *object_path,
- bt_obex_complete_cb func,
- gpointer data);
-
-void _bt_obex_set_release_cb(char *object_path,
- bt_obex_release_cb func,
- gpointer data);
-
-void _bt_obex_agent_new(char *path);
-
-void _bt_obex_agent_destroy(char *path);
-
-gboolean _bt_obex_setup(const char *path);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* __BT_SERVICE_OBEX_AGENT_H */
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_OBEX_SERVER_H_
-#define _BT_SERVICE_OBEX_SERVER_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include "bluetooth-api.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int _bt_register_obex_server(void);
-
-int _bt_unregister_obex_server(void);
-
-int _bt_obex_server_allocate(char *sender, const char *dest_path, int app_pid,
- gboolean is_native);
-
-int _bt_obex_server_deallocate(int app_pid, gboolean is_native);
-
-int _bt_obex_server_accept_authorize(const char *filename, gboolean is_native);
-
-int _bt_obex_server_reject_authorize(void);
-
-int _bt_obex_server_set_destination_path(const char *dest_path,
- gboolean is_native);
-
-int _bt_obex_server_set_root(const char *root);
-
-int _bt_obex_server_cancel_transfer(int transfer_id);
-
-int _bt_obex_server_cancel_all_transfers(void);
-
-int _bt_obex_server_is_activated(gboolean *activated);
-
-int _bt_obex_server_check_allocation(gboolean *allocation);
-
-int _bt_obex_server_check_termination(char *sender);
-
-int _bt_obex_server_accept_connection(int request_id);
-
-int _bt_obex_server_reject_connection(void);
-
-int _bt_opp_get_server_progress(int transfer_id, guint8 *progress);
-
-int _bt_obex_server_is_receiving(gboolean *receiving);
-
-
-void _bt_obex_transfer_progress(const char *transfer_path,
- guint64 transferred);
-void _bt_obex_transfer_completed(const char *transfer_path, gboolean success);
-
-void _bt_obex_transfer_started(const char *transfer_path);
-
-void _bt_obex_check_pending_transfer(const char *address);
-
-void _bt_obex_transfer_connected(const char *obj_path);
-
-void _bt_obex_transfer_disconnected(char *address);
-
-int _bt_obex_get_native_pid(void);
-
-void _bt_obex_server_reply_accept(void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_OBEX_SERVER_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_OOB_H_
-#define _BT_SERVICE_OOB_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include "bluetooth-api.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int _bt_oob_read_local_data(bt_oob_data_t *local_oob_data);
-
-int _bt_oob_add_remote_data(
- bluetooth_device_address_t *remote_device_address,
- bt_oob_data_t *remote_oob_data);
-
-int _bt_oob_remove_remote_data(
- bluetooth_device_address_t *remote_device_address);
-
-int _bt_le_oob_read_local_data(bt_oob_data_t *local_oob_data);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_OOB_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_PROXIMITY_H_
-#define _BT_SERVICE_PROXIMITY_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include "bluetooth-api.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-typedef enum {
- BT_PXP_ALERT_NONE = 0,
- BT_PXP_ALERT_MILD,
- BT_PXP_ALERT_HIGH
-} bt_proximity_alert_value_t;
-
-typedef enum {
- BT_PXP_PROPERTY_LLS = 0x01,
- BT_PXP_PROPERTY_IAS = 0x02,
- BT_PXP_PROPERTY_TX_POWER = 0x04
-} bt_proximity_alert_property_t;
-
-typedef enum {
- BT_PXP_REPORTER_ROLE = 0x00,
- BT_PXP_MONITOR_ROLE = 0x01,
-} bt_proximity_role_t;
-
-int bt_set_proximity_property(bluetooth_device_address_t *device_address,
- unsigned int property, int value);
-
-int bt_get_proximity_property(bluetooth_device_address_t *device_address,
- unsigned int property, int *value);
-
-int bt_get_proximity_supported_services(bluetooth_device_address_t *device_address,
- unsigned int *supported_services);
-
-int bt_register_proximity_reporter();
-
-int bt_unregister_proximity_reporter();
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_PROXIMITY_H_*/
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _BT_SERVICE_RFCOMM_CLIENT_H_
-#define _BT_SERVICE_RFCOMM_CLIENT_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include "bluetooth-api.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int _bt_rfcomm_connect_using_uuid(int request_id,
- bluetooth_device_address_t *device_address,
- char *remote_uuid);
-
-int _bt_rfcomm_connect_using_channel(int request_id,
- bluetooth_device_address_t *device_address,
- char *channel);
-
-int _bt_rfcomm_disconnect(int socket_fd);
-
-int _bt_rfcomm_write(int socket_fd, char *buf, int length);
-
-int _bt_rfcomm_cancel_connect(void);
-
-int _bt_rfcomm_is_device_connected(bluetooth_device_address_t *device_address,
- gboolean *connected);
-
-int _bt_rfcomm_is_connected(gboolean *connected);
-
-int _bt_rfcomm_client_disconnect_all(void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_RFCOMM_CLIENT_H_*/
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _BT_SERVICE_RFCOMM_SERVER_H_
-#define _BT_SERVICE_RFCOMM_SERVER_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include "bluetooth-api.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_RFCOMM_SERVER_H_*/
-
-typedef struct {
- int server_id;
- int accept_id;
- int server_type;
- int control_fd;
- int data_fd;
- guint control_id;
- guint data_id;
- char *serial_path;
- char *uuid;
- char *sender;
- char *remote_address;
- GIOChannel *control_io;
- GIOChannel *data_io;
-// DBusGProxy *serial_proxy;
-// DBusGProxy *manager_proxy;
-} bt_rfcomm_server_info_t;
-
-int _bt_rfcomm_create_socket(char *sender, char *uuid);
-
-int _bt_rfcomm_remove_socket(int socket_fd);
-
-int _bt_rfcomm_listen(int socket_fd, int max_pending, gboolean is_native);
-
-int _bt_rfcomm_is_uuid_available(char *uuid, gboolean *available);
-
-int _bt_rfcomm_accept_connection(void);
-
-int _bt_rfcomm_reject_connection(void);
-
-int _bt_rfcomm_server_disconnect(int data_fd);
-
-bt_rfcomm_server_info_t *_bt_rfcomm_get_server_info_using_uuid(char *uuid);
-
-int _bt_rfcomm_server_disconnect_all_connection(void);
-
-int _bt_rfcomm_server_check_existence(gboolean *existence);
-
-int _bt_rfcomm_server_check_termination(char *name);
-
+++ /dev/null
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef _BT_SERVICE_UTIL_H_
-#define _BT_SERVICE_UTIL_H_
-
-#include <sys/types.h>
-#include <gio/gio.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#define BT_NODE_NAME_LEN 50
-
-typedef struct {
- int req_id;
- int service_function;
- char name[BT_NODE_NAME_LEN];
- GDBusMethodInvocation *context;
-} request_info_t;
-
-
-void _bt_init_request_id(void);
-
-int _bt_assign_request_id(void);
-
-void _bt_delete_request_id(int request_id);
-
-
-void _bt_init_request_list(void);
-
-int _bt_insert_request_list(int req_id, int service_function,
- char *name, GDBusMethodInvocation *context);
-
-int _bt_delete_request_list(int req_id);
-
-request_info_t *_bt_get_request_info(int req_id);
-
-void _bt_clear_request_list(void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*_BT_SERVICE_UTIL_H_*/
-
Name: bluetooth-frwk
Summary: Bluetooth framework for BlueZ and Obexd. This package is Bluetooth framework based on BlueZ and Obexd stack.
-Version: 0.3.0
+Version: 0.4.0
Release: 1
Group: Network & Connectivity/Bluetooth
License: Apache-2.0