/*
- * 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>
+ * 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.
#include "bt-request-sender.h"
#include "bt-event-handler.h"
+#ifdef TIZEN_DPM_ENABLE
+#include "bt-dpm.h"
+#endif
+
#ifdef RFCOMM_DIRECT
#define BT_TIMEOUT_MESSAGE "Did not receive a reply. Possible causes include: " \
gint compare_fd(gpointer *a, gpointer *b)
{
rfcomm_conn_info_t *node = (rfcomm_conn_info_t *)a;
- int fd = (int )*b;
- if (node->fd == fd)
+ int *fd = (int *)b;
+ if (node->fd == *fd)
return 0;
+
return 1;
}
static void __bt_free_conn(rfcomm_conn_info_t *conn)
{
GSList *l;
rfcomm_conn_info_t *device_node = NULL;
- for(l = info->rfcomm_conns; l != NULL; l = l->next) {
- device_node = l->data;
- if ( device_node && device_node->fd == fd)
- return device_node;
- }
- return NULL;
-}
-
-static rfcomm_conn_info_t * __get_conn_info_for_disconnection(
- rfcomm_cb_data_t *info)
-{
- GSList *l;
- rfcomm_conn_info_t *device_node = NULL;
- for(l = info->rfcomm_conns; l != NULL; l = l->next) {
+ for (l = info->rfcomm_conns; l != NULL; l = l->next) {
device_node = l->data;
- if (device_node && device_node->disconnected == TRUE)
+ if (device_node && device_node->fd == fd)
return device_node;
}
return NULL;
static void _bt_rfcomm_disconnect_conn_info(rfcomm_conn_info_t *conn_info,
rfcomm_cb_data_t *info)
{
+ if (conn_info == NULL)
+ return;
+
bluetooth_rfcomm_disconnection_t disconn_info;
bt_event_info_t *event_info = NULL;
if (conn_info->disconnected == FALSE)
BLUETOOTH_ERROR_NONE, &disconn_info,
event_info->cb, event_info->user_data);
- if(conn_info) {
+ if (conn_info) {
BT_DBG("List is present deleting it");
__rfcomm_remove_conn_info_t(info, conn_info->bt_addr);
}
return;
}
conn_info.socket_fd = conn_list_info->fd;
-// conn_info.server_id = -1;
+ conn_info.server_id = -1;
BT_DBG("Connection Result[%d] BT_ADDRESS[%s] UUID[%s] FD[%d]",
result, conn_list_info->bt_addr, cb_data->uuid, conn_list_info->fd);
g_io_channel_unref(data_io);
- __client_connected_cb(info, address,BLUETOOTH_ERROR_NONE);
+ __client_connected_cb(info, address, BLUETOOTH_ERROR_NONE);
return 0;
}
-static void __bt_connect_response_cb(DBusGProxy *proxy, DBusGProxyCall *call,
+static void __bt_connect_response_cb(GDBusProxy *proxy, GAsyncResult *res,
gpointer user_data)
{
cb_data = user_data;
- if (!dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_INVALID)) {
+ if (!g_dbus_proxy_call_finish(proxy, res, &error)) {
int result;
-
+ g_dbus_error_strip_remote_error(error);
BT_ERR("Error : %s \n", error->message);
if (g_strcmp0(error->message, "In Progress") == 0)
result = BLUETOOTH_ERROR_DEVICE_BUSY;
else
result = BLUETOOTH_ERROR_INTERNAL;
- path = dbus_g_proxy_get_path(proxy);
+ path = g_dbus_proxy_get_object_path(proxy);
_bt_convert_device_path_to_address(path, dev_address);
__rfcomm_client_connected_cb(cb_data, dev_address, result);
g_error_free(error);
- g_object_unref(proxy);
}
+ if (proxy)
+ g_object_unref(proxy);
+
BT_DBG("-");
}
-static void __bt_discover_service_response_cb(DBusGProxy *proxy,
- DBusGProxyCall *call, gpointer user_data)
+static void __bt_discover_service_response_cb(GDBusProxy *proxy,
+ GAsyncResult *res, gpointer user_data)
{
rfcomm_cb_data_t *cb_data;
int ret = 0;
GError *err = NULL;
- GHashTable *hash = NULL;
bt_register_profile_info_t info = {0};
int result = BLUETOOTH_ERROR_NONE;
char dev_address[BT_ADDRESS_STRING_SIZE];
cb_data = user_data;
- path = dbus_g_proxy_get_path(proxy);
+ path = g_dbus_proxy_get_object_path(proxy);
+
_bt_convert_device_path_to_address(path, dev_address);
BT_DBG("Device Adress [%s]", dev_address);
- dbus_g_proxy_end_call(proxy, call, &err,
- dbus_g_type_get_map("GHashTable",
- G_TYPE_UINT, G_TYPE_STRING), &hash,
- G_TYPE_INVALID);
- g_object_unref(proxy);
+ g_dbus_proxy_call_finish(proxy, res, &err);
+ if (proxy)
+ g_object_unref(proxy);
+
if (err != NULL) {
+ g_dbus_error_strip_remote_error(err);
BT_ERR("Error occured in Proxy call [%s]\n", err->message);
if (!strcmp("Operation canceled", err->message)) {
result = BLUETOOTH_ERROR_CANCEL_BY_USER;
}
done:
if (err)
- g_error_free(err);
- if (hash)
- g_hash_table_destroy(hash);
+ g_clear_error(&err);
}
BT_EXPORT_API int bluetooth_rfcomm_connect(
BT_CHECK_PARAMETER(remote_uuid, return);
BT_CHECK_ENABLED(return);
+#ifdef TIZEN_DPM_ENABLE
+ if (_bt_check_dpm(BT_DPM_ADDRESS, (void *)remote_bt_address) == BT_DPM_RESTRICTED) {
+ BT_ERR("Blacklist device");
+ return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
+ }
+
+ if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED ||
+ _bt_check_dpm(BT_DPM_HF_ONLY, NULL) == BT_DPM_RESTRICTED) {
+ BT_ERR("Not allow to connect the RFCOMM service");
+ return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
+ }
+
+ if (_bt_check_dpm(BT_DPM_DESKTOP, NULL) == BT_DPM_RESTRICTED) {
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ bluetooth_device_class_t dev_class;
+
+ _bt_convert_addr_type_to_string(address, (unsigned char *)remote_bt_address->addr);
+ _bt_get_cod_by_address(address, &dev_class);
+
+ if (dev_class.major_class == BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
+ BT_ERR("Reject a authorization due to MDM Policy");
+ return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
+ }
+ }
+#endif
+
#ifdef RFCOMM_DIRECT
BT_INFO_C("<<<<<<<<< RFCOMM Connect request from app >>>>>>>>>>>");
int ret;
#endif
}
-BT_EXPORT_API int bluetooth_rfcomm_client_is_connected(bluetooth_device_address_t *device_address, gboolean *connected)
+BT_EXPORT_API int bluetooth_rfcomm_client_is_connected(const bluetooth_device_address_t *device_address, gboolean *connected)
{
GSList *l;
GSList *conn_list = NULL;
BT_CHECK_PARAMETER(device_address, return);
BT_CHECK_PARAMETER(connected, return);
- _bt_convert_addr_type_to_string(address, device_address->addr);
+ _bt_convert_addr_type_to_string(address, (unsigned char *)device_address->addr);
*connected = FALSE;
for (l = rfcomm_clients; l != NULL; l = l->next) {
client_info = l->data;
if (client_info == NULL)
continue;
- for(conn_list = client_info->rfcomm_conns;
+ for (conn_list = client_info->rfcomm_conns;
conn_list != NULL; conn_list = conn_list->next) {
conn_info = conn_list->data;
- if(conn_info == NULL)
+ if (conn_info == NULL)
continue;
if (g_strcmp0(address, conn_info->bt_addr) == 0) {
conn_info->disconnected = TRUE;
close(socket_fd);
BT_INFO("conn_info %s", conn_info->bt_addr);
- _bt_disconnect_profile(conn_info->bt_addr, info->uuid, NULL,NULL);
+ _bt_disconnect_profile(conn_info->bt_addr, info->uuid, NULL, NULL);
if (info->idle_id == 0)
info->idle_id = g_idle_add(__rfcomm_client_disconnect, info);
int result;
BT_CHECK_PARAMETER(buf, return);
+ if (fd < 0) {
+ BT_ERR("Invalid FD");
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+ }
+
+ BT_DBG("FD : %d", fd);
+
#ifndef RFCOMM_DIRECT
BT_CHECK_ENABLED(return);
#endif
retv_if(length <= 0, BLUETOOTH_ERROR_INVALID_PARAM);
+#ifdef TIZEN_DPM_ENABLE
+ if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED ||
+ _bt_check_dpm(BT_DPM_HF_ONLY, NULL) == BT_DPM_RESTRICTED) {
+ BT_ERR("Not allow to write RFCOMM data");
+ return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
+ }
+#endif
+
#ifdef RFCOMM_DIRECT
switch (privilege_token) {
case 0: