Disconnect PBAP when Phone log access is disabled 05/143605/1
authorAnurag Biradar <biradar.a@samsung.com>
Wed, 26 Jul 2017 11:34:31 +0000 (17:04 +0530)
committerBiman Paul <biman.paul@samsung.com>
Thu, 10 Aug 2017 12:10:21 +0000 (17:40 +0530)
[Model]N/A
[BinType] AP
[Customer]N/A

[Issue#]N/A
[Request]N/A
[Occurrence Version]N/A

[Problem] Remote device is able to get contact when phone log access is
disabled
[Cause & Measure] If pbap connection is already established and phonelog
access is disabled remote device can still get phone logs and contact details
Measure: When a Profile is blocked and if profile is connected we need to
disconnect the profile.
[Checking Method]connect Pbap (using mecapp) -> Goto Profile View (on DUT) ->
disable Phone log access -> Check if remote is disconnected or not.

[Team]Basic connection
[Developer] Anurag B
[Solution company] Samsung
[Change Type]N/A

Change-Id: Icf513cea5384c5fac88ddb0e3cab82a9c910e103

gobex/gobex.c
gobex/gobex.h
obexd/plugins/bluetooth.c
obexd/src/obex.c
src/device.c

index 61ddc66..d0b1e01 100644 (file)
@@ -1552,7 +1552,14 @@ void g_obex_unref(GObex *obex)
 }
 
 /* Higher level functions */
-
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+void g_obex_io_shutdown(GObex *obex)
+{
+       GError *err = NULL;
+       if (obex->io != NULL)
+               g_io_channel_shutdown(obex->io, FALSE, &err);
+}
+#endif
 guint g_obex_connect(GObex *obex, GObexResponseFunc func, gpointer user_data,
                                        GError **err, guint8 first_hdr_id, ...)
 {
index 5bc9103..827dc3b 100644 (file)
@@ -134,5 +134,8 @@ gboolean g_obex_cancel_transfer(guint id, GObexFunc complete_func,
 
 const char *g_obex_strerror(guint8 err_code);
 guint8 g_obex_errno_to_rsp(int err);
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+void g_obex_io_shutdown(GObex *obex);
+#endif
 
 #endif /* __GOBEX_H */
index d8b872a..2261630 100644 (file)
@@ -162,6 +162,18 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 static DBusMessage *profile_request_disconnection(DBusConnection *conn,
                                                DBusMessage *msg, void *data)
 {
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       const char *device;
+       const char *path;
+       path = dbus_message_get_path(msg);
+       DBG("Path %s", path);
+
+       dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &device,
+                                                       DBUS_TYPE_INVALID);
+       DBG("Device %s", device);
+
+       obex_session_disconnect(path, device);
+#endif
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
index fee2461..b81dfd9 100644 (file)
 
 #include <glib.h>
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+#include "lib/uuid.h"
+#endif
+
 #include "gobex/gobex.h"
 
 #include "btio/btio.h"
@@ -1026,6 +1030,87 @@ static void disconn_func(GObex *obex, GError *err, gpointer user_data)
        obex_session_destroy(os);
 }
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+#define BLUETOOTH_MAC_ADDRESS_LEN      18
+void obex_convert_device_path_to_address(const char *device_path,
+                                               char *device_address)
+{
+       char address[BLUETOOTH_MAC_ADDRESS_LEN] = { 0 };
+       char *dev_addr;
+
+       if (device_path == NULL || device_address == NULL)
+               return;
+
+       dev_addr = strstr(device_path, "dev_");
+       if (dev_addr != NULL) {
+               char *pos = NULL;
+               dev_addr += 4;
+               g_strlcpy(address, dev_addr, sizeof(address));
+
+               while ((pos = strchr(address, '_')) != NULL)
+                       *pos = ':';
+
+               g_strlcpy(device_address, address, BLUETOOTH_MAC_ADDRESS_LEN);
+       }
+}
+
+int obex_object_path_to_uuid(const char *path)
+{
+       char uuid[MAX_LEN_UUID_STR] = { 0 };
+       const char *uuidptr;
+
+       if (path == NULL)
+               return -1;
+       /* /org/bluez/obex/0000112f_0000_1000_8000_00805f9b34fb */
+       uuidptr = path;
+
+       char *pos = NULL;
+       uuidptr += 16;
+       g_strlcpy(uuid, uuidptr, sizeof(uuid));
+
+       while ((pos = strchr(uuid, '_')) != NULL)
+               *pos = '-';
+
+       if (g_strcmp0(uuid, OBEX_PSE_UUID) == 0)
+               return OBEX_PBAP;
+       else if (g_strcmp0(uuid, OBEX_FTP_UUID) == 0)
+               return OBEX_FTP;
+       else if (g_strcmp0(uuid, OBEX_OPP_UUID) == 0)
+               return OBEX_OPP;
+       else if (g_strcmp0(uuid, OBEX_MAS_UUID) == 0)
+               return OBEX_MAS;
+       else if (g_strcmp0(uuid, OBEX_MNS_UUID) == 0)
+               return OBEX_MNS;
+       else
+               return -1;
+}
+
+void obex_session_disconnect(const char *uuid_path, const char *device_path)
+{
+       GSList *l = sessions;
+       char device_address[BLUETOOTH_MAC_ADDRESS_LEN];
+       int service;
+
+       obex_convert_device_path_to_address(device_path, device_address);
+       service = obex_object_path_to_uuid(uuid_path);
+
+       if (service == -1)
+               return;
+
+       while (l) {
+               struct obex_session *os = l->data;
+               if (g_strcmp0(os->dst, device_address) == 0 &&
+                       os->service->service == service) {
+                       /* Need to check for address? */
+                       g_obex_io_shutdown(os->obex);
+                       obex_session_destroy(os);
+                       break;
+               }
+               l = l->next;
+       }
+}
+#endif
+
 int obex_session_start(GIOChannel *io, uint16_t tx_mtu, uint16_t rx_mtu,
                                gboolean stream, struct obex_server *server)
 {
index 321218d..85f1b39 100644 (file)
@@ -7259,6 +7259,7 @@ void btd_device_set_trusted(struct btd_device *device, gboolean trusted)
 void btd_device_set_trusted_profiles(struct btd_device *device,
                uint32_t pbap, uint32_t map, uint32_t sap)
 {
+       char *uuid = NULL;
        if (!device)
                return;
        DBG("TrustedProfiles Parameters: [PBAP %d] [MAP %d] [SAP %d]", pbap, map, sap);
@@ -7268,12 +7269,40 @@ void btd_device_set_trusted_profiles(struct btd_device *device,
                        device->trusted_profiles.sap == sap)
                return;
 
-       device->trusted_profiles.pbap = pbap;
-       device->trusted_profiles.map = map;
-       device->trusted_profiles.sap = sap;
+       /* If any of the profile is Blocked than only assign uuid */
+       if (device->trusted_profiles.pbap != pbap) {
+               device->trusted_profiles.pbap = pbap;
+               if (pbap == SUPPORTED_BLOCKED)
+                       uuid = OBEX_PSE_UUID;
+       } else if (device->trusted_profiles.map != map) {
+               device->trusted_profiles.map = map;
+               if (map == SUPPORTED_BLOCKED)
+                       uuid = OBEX_MAP_UUID;
+       } else {
+               device->trusted_profiles.sap = sap;
+               if (sap == SUPPORTED_BLOCKED)
+                       uuid = SAP_UUID;
+       }
 
        store_device_info(device);
 
+       /* If uuid is set than only disconnect */
+       if (uuid) {
+               GSList *l;
+               l = find_service_with_uuid(device->services, uuid);
+               if (l == NULL)
+                       goto emit;
+               struct btd_service *service = l->data;
+               if (btd_service_get_state(service) ==
+                       BTD_SERVICE_STATE_CONNECTED) {
+                       int err;
+                       err = btd_service_disconnect(service);
+                       if (err)
+                               error("error: %s", strerror(-err));
+               }
+       }
+emit:
+
        g_dbus_emit_property_changed(dbus_conn, device->path,
                                        DEVICE_INTERFACE, "TrustedProfiles");
 }