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-gap-agent.c)
LIST(APPEND SRCS ./services/obex/bt-service-avrcp.c)
-LIST(APPEND SRCS ./services/obex/bt-service-agent.c)
LIST(APPEND SRCS ./services/obex/bt-service-obex-event-receiver.c)
LIST(APPEND SRCS ./services/obex/bt-service-oob.c)
ENDIF()
#include "bt-service-audio-common.h"
#include "bt-service-core-adapter-le.h"
#include "bt-service-gatt.h"
-#ifdef TIZEN_FEATURE_BT_OBEX
-#include "bt-service-avrcp.h"
-#include "bt-service-opp-client.h"
-#include "bt-service-obex-server.h"
-#endif
+
#ifdef TIZEN_DPM_ENABLE
#include "bt-service-dpm.h"
#endif
int alarm_id;
} bt_adapter_timer_t;
-#ifdef TIZEN_FEATURE_BT_OBEX
-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_recovery_mode = FALSE;
-static gboolean is_discovering;
-static void *adapter_agent = NULL;
-static guint le_timer_id = 0;
-static uint status_reg_id;
-static void alarm_data_free(void *data);
-#endif
-
static bt_adapter_timer_t visible_timer;
static guint timer_id = 0;
{
return __bt_adapter_state_handle_request(FALSE);
}
-#ifdef TIZEN_FEATURE_BT_OBEX
-static void alarm_data_free(void *data)
-{
- bt_service_alarm_t *p_data = (bt_service_alarm_t *)data;
- g_free(p_data);
- return;
-}
-#endif
+
int _bt_start_discovery(unsigned short max_response,
unsigned short duration, unsigned int cod_mask)
{
free(phone_name);
}
-void _bt_set_discovery_status(gboolean mode)
-{
- is_discovering = mode;
-}
-
-int _bt_check_adapter(int *status)
-{
-if (!TIZEN_PROFILE_TV) {
- 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 {
- 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;
-}
-}
-
-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;
- }
-
- if (TIZEN_PROFILE_MOBILE || 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 if (TIZEN_PROFILE_TV) {
- if (_bt_set_discoverable_mode(BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE, 0) != BLUETOOTH_ERROR_NONE)
- BT_ERR("Fail to set discoverable mode");
- }
-
- /* 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
-
- if (!TIZEN_PROFILE_TV)
- __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);
-
- if (!TIZEN_FEATURE_BT_USB_DONGLE &&
- _bt_adapter_get_le_state() != BT_LE_DEACTIVATED) {
- /* Send disabled event */
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_DISABLED,
- g_variant_new("(i)", result));
- }
-
- BT_INFO("Adapter disabled");
-}
-
-#if 0
-void _bt_adapter_set_status(bt_status_t status)
-{
- BT_INFO("adapter_status changed [%d] -> [%d]", adapter_status, status);
- adapter_status = status;
-}
-#endif
-
bt_status_t _bt_adapter_get_status(void)
{
return adapter_state;
}
-
-void *_bt_get_adapter_agent(void)
-{
- return adapter_agent;
-}
-
-
-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\n");
-
- 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));
-
- if (!TIZEN_PROFILE_TV)
- __bt_set_local_name();
-
- BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
-}
-
-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;
-
- status = _bt_adapter_get_status();
- le_status = _bt_adapter_get_le_state();
- BT_DBG("status : %d", status);
- BT_DBG("le_status : %d", le_status);
-
- if (!TIZEN_FEATURE_BT_USB_DONGLE) {
- 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;
- }
- }
- }
-
- if (_bt_register_media_player() != BLUETOOTH_ERROR_NONE)
- BT_ERR("Fail to register media player");
-
-#ifdef TIZEN_FEATURE_BT_OBEX
- if (_bt_register_obex_server() != BLUETOOTH_ERROR_NONE)
- BT_ERR("Fail to init obex server");
-#endif
-
-#ifdef TIZEN_FEATURE_BT_PAN_NAP
- 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");
-
-/* unregister all the services/servers/profiles registered on bluez-adapter
- once adapter is removed, reinitializing of the state-varaibles becomes
- a problem */
- if (_bt_unregister_obex_server() != BLUETOOTH_ERROR_NONE)
- BT_ERR("Fail to unregister obex server");
-
- if (_bt_unregister_media_player() != BLUETOOTH_ERROR_NONE)
- BT_ERR("Fail to unregister media player");
-
-/* Other unregister APIs should be placed here */
-
- if (!TIZEN_FEATURE_BT_USB_DONGLE) {
- _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);
- }
-
- if (eventsystem_unregister_event(status_reg_id) != ES_R_OK)
- BT_ERR("Fail to unregister system event");
-}
-
#include "bluetooth-api.h"
#include "bt-service-common.h"
-#ifdef TIZEN_FEATURE_BT_OBEX
-#include "bt-service-agent.h"
-#endif
#include <oal-manager.h>
BT_DBG("-");
return TRUE;
}
-#ifdef TIZEN_FEATURE_BT_OBEX
-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;
-}
-#endif
int _bt_set_socket_non_blocking(int socket_fd)
{
return BLUETOOTH_ERROR_NONE;
}
-#ifdef TIZEN_FEATURE_BT_OBEX
-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, "ManufacturerDataLen",
- 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, "ManufacturerData",
- 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_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);
-}
-#endif
BT_ERR("Fail to init BT Stack");
return 0;
}
-#ifdef TIZEN_FEATURE_BT_OBEX
- bluetooth_plugin_init();
-#endif
g_timeout_add(500, (GSourceFunc)__bt_check_bt_service, NULL);
g_main_loop_run(main_loop);
BT_DBG("g_main_loop_quit called!");
-#ifdef TIZEN_FEATURE_BT_OBEX
- bluetooth_plugin_deinit();
-#endif
bluetooth_plugin_deinit();
#include "bt-service-agent-util.h"
#include "bt-service-a2dp-src.h"
#include "bt-service-a2dp-sink.h"
+#ifdef TIZEN_FEATURE_BT_OBEX
+#include "bt-service-obex-server.h"
+#endif
/* OAL headers */
#include <oal-event.h>
case AVRCP_CT_SERVICE_ID:
BT_INFO("Incoming AVRCP (Controller) Profile conn Req from device addr [%s]", address);
break;
+#ifdef TIZEN_FEATURE_BT_OBEX
+ case OPP_SERVICE_ID: {
+ GVariant *param = NULL;
+ char *name = g_strdup(address); /* TODO: Retrieve and send correct name in OBEX conn auth req event */
+
+ BT_INFO("Incoming OPP conn Req from device addr [%s]", address);
+ _bt_obex_server_set_pending_conn_auth_device_addr(address);
+ param = g_variant_new("(iss)", BLUETOOTH_ERROR_NONE, address, name);
+ _bt_send_event(BT_OPP_SERVER_EVENT,
+ BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE, param);
+ g_free(name);
+ return;
+ }
+#endif
default:
/* For now, reject authorization for any service apart from above switch cases */
BT_INFO("Incoming Profile conn req with service ID [%d] from device addr [%s]", service_d, address);
#include "bluetooth-api.h"
#include "bt-request-handler.h"
#include <oal-manager.h>
-#ifdef TIZEN_FEATURE_BT_OBEX
-#include "bt-service-agent.h"
-#endif
#ifdef __cplusplus
extern "C" {
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_free_remote_dev(bt_remote_dev_info_t * dev_info);
-#ifdef TIZEN_FEATURE_BT_OBEX
-void __bt_get_auth_info(GVariant *reply, char *auth_info);
-#endif
-
void _bt_set_device_values(gboolean connected, int state);
void _bt_string_to_uuid(char *str, service_uuid_t *p_uuid);
int _bt_cleanup_profiles(void);
-#ifdef TIZEN_FEATURE_BT_OBEX
-
-void _bt_adapter_set_status(bt_status_t status);
-
bt_status_t _bt_adapter_get_status(void);
-
-void _bt_set_disabled(int result);
-
-typedef int (*bt_set_alarm_cb) (alarm_id_t alarm_id, void* user_param);
-void *_bt_get_adapter_agent(void);
-
-void _bt_handle_adapter_added(void);
-#endif
-
-
#ifdef __cplusplus
}
#endif /* __cplusplus */
+++ /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 <vconf.h>
-#include <bundle_internal.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-core-adapter.h"
-#include "bt-service-event.h"
-#include "bt-service-device.h"
-#include "bt-service-audio.h"
-
-#ifdef TIZEN_FEATURE_BT_DPM
-#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 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];
- int ret = BLUETOOTH_ERROR_NONE;
-#ifdef TIZEN_FEATURE_BT_DPM
- int pairing_state = DPM_STATUS_ERROR;
-#endif
-
- BT_DBG("+");
-
-#ifdef TIZEN_FEATURE_BT_DPM
- _bt_dpm_get_bluetooth_pairing_state(&pairing_state);
- if (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);
-
- if (headed_plugin_info->plugin_headed_enabled) {
- headed_plugin_info->headed_plugin->bt_launch_system_popup(BT_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST,
- name, auth_info, str_passkey, NULL, _gap_agent_get_path(agent));
- } else {
- GVariant *param = NULL;
- param = g_variant_new("(isss)", ret, address, name, str_passkey);
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
- }
- } 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 {
- if (headed_plugin_info->plugin_headed_enabled) {
- BT_DBG("Show Pin entry");
- headed_plugin_info->headed_plugin->bt_launch_system_popup(BT_AGENT_EVENT_PIN_REQUEST, name, auth_info,
- NULL, NULL, _gap_agent_get_path(agent));
- } else {
- BT_INFO("Plugin Headed not Enabled");
- GVariant *param = NULL;
- param = g_variant_new("(iss)", ret, address, name);
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_PIN_REQUEST, param);
- }
- }
-
-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;
- int ret = BLUETOOTH_ERROR_NONE;
-#ifdef TIZEN_FEATURE_BT_DPM
- int pairing_state = DPM_STATUS_ERROR;
-#endif
-
- BT_DBG("+");
-
-#ifdef TIZEN_FEATURE_BT_DPM
- _bt_dpm_get_bluetooth_pairing_state(&pairing_state);
- if (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);
-
- if (headed_plugin_info->plugin_headed_enabled) {
- headed_plugin_info->headed_plugin->bt_launch_system_popup(BT_AGENT_EVENT_PASSKEY_REQUEST, name, auth_info,
- NULL, NULL, _gap_agent_get_path(agent));
- } else {
- BT_INFO("Plugin Headed not Enabled");
- GVariant *param = NULL;
- param = g_variant_new("(iss)", ret, address, name);
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_PASSKEY_REQUEST, param);
- }
-
-
-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;
- int ret = BLUETOOTH_ERROR_NONE;
-
- 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);
-
- GVariant *param = NULL;
- param = g_variant_new("(ss)", address, str_passkey);
-
- if (passkey_watcher) {
- BT_INFO("Send passkey to %s", passkey_watcher);
- _bt_send_event_to_dest(passkey_watcher, BT_ADAPTER_EVENT,
- BLUETOOTH_EVENT_PASSKEY_NOTIFICATION, param);
- } else {
- if (headed_plugin_info->plugin_headed_enabled) {
- BT_INFO("Plugin Headed Enabled");
- headed_plugin_info->headed_plugin->bt_launch_system_popup(BT_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST, name,
- auth_info, str_passkey, NULL, _gap_agent_get_path(agent));
- } else {
- BT_INFO("Plugin Headed not Enabled");
- GVariant *param = NULL;
- param = g_variant_new("(isss)", ret, address, name, str_passkey);
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
- }
- }
-
- 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;
- int ret = BLUETOOTH_ERROR_NONE;
-#ifdef TIZEN_FEATURE_BT_DPM
- int pairing_state = DPM_STATUS_ERROR;
-#endif
- BT_DBG("+ passkey[%.6d]", passkey);
-
-#ifdef TIZEN_FEATURE_BT_DPM
- _bt_dpm_get_bluetooth_pairing_state(&pairing_state);
- if (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);
-
- if (headed_plugin_info->plugin_headed_enabled) {
- BT_DBG("LAUNCH SYSPOPUP");
- headed_plugin_info->headed_plugin->bt_launch_system_popup(BT_AGENT_EVENT_PASSKEY_CONFIRM_REQUEST, name,
- auth_info, str_passkey, NULL,
- _gap_agent_get_path(agent));
- } else {
- BT_DBG("Headless Confirmation");
- GVariant *param = NULL;
- param = g_variant_new("(isss)", ret, address, name, str_passkey);
- _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST, param);
- }
-
-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");
-
- if (headed_plugin_info->plugin_headed_enabled)
- headed_plugin_info->headed_plugin->bt_destroy_popup_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;
- 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);
- if (TIZEN_FEATURE_NETWORK_TETHERING_ENABLE) {
- if (nap_connected_device_count >=
- BT_PAN_MAX_CONNECTION) {
- BT_ERR("Max connection exceeded");
- goto fail;
- }
-
- if (headed_plugin_info->plugin_headed_enabled) {
- if (headed_plugin_info->headed_plugin->bt_is_tethering_enabled() == FALSE) {
- BT_ERR("BT tethering is not enabled");
- goto fail;
- }
- }
- }
-
- gap_agent_reply_authorize(agent, GAP_AGENT_ACCEPT,
- NULL);
- goto done;
-fail:
- gap_agent_reply_authorize(agent, GAP_AGENT_REJECT,
- NULL);
-
- goto done;
- }
-
- 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;
- }
- /* TODO: MAP? see above */
-
- 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;
- /* TODO: MAP is already here */
-
- if (trust || !headed_plugin_info->plugin_headed_enabled) {
- BT_INFO("Trusted or Headless device, so authorize\n");
- gap_agent_reply_authorize(agent,
- GAP_AGENT_ACCEPT, NULL);
-
- goto done;
- }
-
- if (headed_plugin_info->plugin_headed_enabled) {
- headed_plugin_info->headed_plugin->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);
-
- if (headed_plugin_info->plugin_headed_enabled)
- headed_plugin_info->headed_plugin->bt_destroy_popup_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 <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-obex-agent.h"
-#include "bt-service-gap-agent.h"
-#include "bt-service-core-adapter.h"
-
-#include "bt-service-device.h"
-#include "bt-service-gap-agent.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));
- g_object_unref(proxy);
- BT_DBG("Busname: %s", priv->busname);
- }
-
-}
-
-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>
#include "bt-service-main.h"
#include "bt-service-device.h"
#include "bt-service-obex-server.h"
-#include "bt-service-agent.h"
+#include "bt-service-obex-agent.h"
#include "bt-service-pbap.h"
#include "bt-service-opp-client.h"
#include "bt-service-map-client.h"
gboolean paired = FALSE;
bt_remote_dev_info_t *remote_dev_info;
g_variant_get(val, "b", &paired);
- _bt_agent_set_canceled(FALSE);
+ //_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 */
BT_DBG("Enable Adapter");
_bt_enable_adapter();
#else
- _bt_handle_adapter_added();
+ //_bt_handle_adapter_added();
#endif
} else {
bt_event = __bt_parse_event(value);
#include "bt-service-util.h"
#include "bt-service-obex-agent.h"
#include "bt-service-obex-server.h"
-#include "bt-service-agent.h"
+#include <oal-device-mgr.h>
#define DBUS_TIMEOUT 20 * 1000 /* 20 Seconds */
#define BT_OBEX_SERVER_AGENT_PATH "/org/obex/server_agent"
static bt_obex_agent_info_t agent_info;
static GSList *session_list = NULL;
+static char *pending_auth_address = NULL;
+
static bt_session_info_t *__bt_find_session_by_path(char *transfer_path)
{
GSList *l;
return name;
}
+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, "ManufacturerDataLen",
+ 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, "ManufacturerData",
+ 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_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);
+}
+
static void __bt_get_remote_device_name_authinfo(const char *bdaddress,
char **device_name, unsigned char *auth_info)
{
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);
+ if (OAL_STATUS_SUCCESS !=
+ device_set_osp_server(OAL_OSP_SERVER_OBEX, FALSE))
+ BT_ERR("device_set_osp_server failed");
} else {
if (agent_info.custom_server) {
BT_ERR("obex custom server busy");
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);
+ if (OAL_STATUS_SUCCESS !=
+ device_set_osp_server(OAL_OSP_SERVER_OBEX, TRUE))
+ BT_ERR("device_set_osp_server failed");
}
g_free(dst_path);
/* 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);
+ if (OAL_STATUS_SUCCESS !=
+ device_set_osp_server(OAL_OSP_SERVER_OBEX, TRUE))
+ BT_ERR("device_set_osp_server failed");
}
} else {
retv_if(agent_info.custom_server == NULL,
__bt_free_server_info(agent_info.custom_server);
agent_info.custom_server = NULL;
- _bt_unregister_osp_server_in_agent(BT_OBEX_SERVER, NULL);
+ if (OAL_STATUS_SUCCESS !=
+ device_set_osp_server(OAL_OSP_SERVER_OBEX, FALSE))
+ BT_ERR("device_set_osp_server failed");
/* Change the control to native */
if (agent_info.native_server)
return FALSE;
}
+void _bt_obex_server_set_pending_conn_auth_device_addr(const char *address)
+{
+ if (pending_auth_address)
+ g_free(pending_auth_address);
+
+ pending_auth_address = g_strdup(address);
+}
+
/* To support the BOT */
int _bt_obex_server_accept_connection(int request_id)
{
- if (!_bt_agent_reply_authorize(TRUE))
+ int res;
+ bt_address_t bd_addr;
+
+ BT_INFO("address: %s", pending_auth_address);
+ _bt_convert_addr_string_to_type(bd_addr.addr, pending_auth_address);
+ res = device_reply_auth_request(&bd_addr, OPP_SERVICE_ID, TRUE, FALSE);
+ g_free(pending_auth_address);
+ pending_auth_address = NULL;
+ if (res != OAL_STATUS_SUCCESS) {
+ BT_ERR("device_reply_auth_request failed");
return BLUETOOTH_ERROR_INTERNAL;
+ }
agent_info.accept_id = request_id;
/* To support the BOT */
int _bt_obex_server_reject_connection(void)
{
- if (!_bt_agent_reply_authorize(FALSE))
+ int res;
+ bt_address_t bd_addr;
+
+ BT_INFO("address: %s", pending_auth_address);
+ _bt_convert_addr_string_to_type(bd_addr.addr, pending_auth_address);
+ res = device_reply_auth_request(&bd_addr, OPP_SERVICE_ID, FALSE, FALSE);
+ g_free(pending_auth_address);
+ pending_auth_address = NULL;
+ if (res != OAL_STATUS_SUCCESS) {
+ BT_ERR("device_reply_auth_request failed");
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.
- *
- */
-
-#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
-
-#define BT_FILE_VISIBLE_TIME "file/private/libug-setting-bluetooth-efl/visibility_time"
-
-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;
-
-
-//needed
-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_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 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
#endif
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 enum {
BT_OBEX_AGENT_ERROR_REJECT,
BT_OBEX_AGENT_ERROR_CANCEL,
BT_OBEX_AGENT_ERROR_TIMEOUT,
void _bt_obex_server_reply_accept(void);
+void _bt_obex_server_set_pending_conn_auth_device_addr(const char *address);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */