Disconnect rfcomm connections 92/97492/2
authorSeungyoun Ju <sy39.ju@samsung.com>
Thu, 13 Oct 2016 11:59:02 +0000 (20:59 +0900)
committerSudha Bheemanna <b.sudha@samsung.com>
Mon, 14 Nov 2016 09:50:06 +0000 (01:50 -0800)
[Model] COMMON
[BinType] AP
[Customer] OPEN

[Issue#] P161013-00685
[Request] PLM
[Occurrence Version] R735AUCU2CPJ3

Since MDM is not used in Tizen 3.0, only the disconnect all connections
function is retained in this patch while merging from SLP.

[Problem] sapd is not working when SPP MDM policy is changed
 from "disallow" to "allow"
[Cause & Measure] sapd doesn't consider this scenario and it just blocks
 the communication once socket API's return error code. But our policy is also
 not consistent (Only Tx is disallowed when SPP policy is restricted.
 But the connection is alive and Rx is possible).
 So it is better to disconnect the SPP when it is restricted.
 And in this case, BT_ERROR_OPERATION_FAILED is returned to service daemon
 so it is hard to decide whether this failure is caused by MDM or not.
 So disconnection is implemented in bt-api when SPP MDM policy is restricted.
[Checking Method] Make SPP connection -> Change SPP policy to restricted

[Team] Basic connection
[Developer] Seungyoun Ju
[Solution company] Samsung
[Change Type] Specification change

Change-Id: Iaaa18b7f786477123ae485dc4564c0189e730642
Signed-off-by: Sudha Bheemanna <b.sudha@samsung.com>
Change-Id: Iaaa18b7f786477123ae485dc4564c0189e730642

bt-api/bt-rfcomm-client.c
bt-api/bt-rfcomm-server.c
bt-api/include/bt-common.h

index 93f5ea6..aec1dca 100644 (file)
@@ -429,6 +429,39 @@ static void __client_connected_cb(rfcomm_cb_data_t *cb_data, char *dev_address,
        BT_DBG("-");
 }
 
+void _bt_rfcomm_client_disconnect_all(void)
+{
+       GSList *client;
+       GSList *conn;
+
+       BT_INFO_C("### Disconnect all RFCOMM client connections");
+
+       for (client = rfcomm_clients; client; ) {
+               rfcomm_cb_data_t *info = client->data;
+
+               for (conn = info->rfcomm_conns; conn; conn = conn->next) {
+                       rfcomm_conn_info_t *conn_info = conn->data;
+
+                       if (conn_info == NULL)
+                               continue;
+
+                       if (conn_info->watch_id == 0 || conn_info->disconnected)
+                               continue;
+
+                       close(conn_info->fd);
+                       conn_info->disconnected = TRUE;
+
+                       _bt_disconnect_profile(conn_info->bt_addr, info->uuid,
+                                       NULL,NULL);
+
+               }
+
+               client = client->next;
+               __rfcomm_client_disconnect(info);
+       }
+
+       return;
+}
 #endif
 
 int new_connection(const char *path, int fd, bluetooth_device_address_t *addr)
@@ -834,10 +867,6 @@ BT_EXPORT_API int bluetooth_rfcomm_disconnect(int socket_fd)
        BT_INFO("conn_info %s", conn_info->bt_addr);
        _bt_disconnect_profile(conn_info->bt_addr, info->uuid, NULL, NULL);
 
-       /*
-        * ToDo : If idle_id is not zero, it means disconnect request is
-        * going on. Such a case, in-progress error should be returned.
-        */
        if (info->idle_id == 0)
                info->idle_id = g_idle_add(__rfcomm_client_disconnect, info);
 
index a2794de..8304108 100644 (file)
@@ -454,13 +454,48 @@ void free_rfcomm_info(rfcomm_info_t *info)
        g_free(info);
 }
 
-void _bt_rfcomm_server_free_all()
+void _bt_rfcomm_server_free_all(void)
 {
        BT_DBG("Free all the servers");
 
        g_slist_free_full(rfcomm_nodes, (GDestroyNotify)free_rfcomm_info);
        rfcomm_nodes = NULL;
 }
+
+void _bt_rfcomm_server_disconnect_all(void)
+{
+       GSList *server;
+       GSList *conn;
+       char addr[20];
+
+       BT_INFO("### Disconnect all RFCOMM server connections");
+
+       for (server = rfcomm_nodes; server; ) {
+               rfcomm_info_t *info = server->data;
+
+               for (conn = info->rfcomm_conns; conn; conn = conn->next) {
+                       rfcomm_conn_t *conn_info = conn->data;
+
+                       if (conn_info == NULL)
+                               continue;
+
+                       if (conn_info->watch_id == 0 || conn_info->disconnected)
+                               continue;
+
+                       close(conn_info->fd);
+                       conn_info->disconnected = TRUE;
+
+                       _bt_convert_addr_type_to_string(addr,
+                                                       conn_info->addr.addr);
+                       _bt_disconnect_profile(addr, info->uuid, NULL,NULL);
+               }
+
+               server = server->next;
+               __rfcomm_server_disconnect(info);
+       }
+
+       return;
+}
 #endif
 
 BT_EXPORT_API int bluetooth_rfcomm_create_socket(const char *uuid)
index dfce86a..c60c459 100644 (file)
@@ -364,13 +364,18 @@ void _bt_convert_device_path_to_address(const char *device_path,
                                char *device_address);
 
 #ifdef RFCOMM_DIRECT
-void _bt_rfcomm_server_free_all();
+void _bt_rfcomm_server_free_all(void);
+
+void _bt_rfcomm_server_disconnect_all(void);
+
+void _bt_rfcomm_client_disconnect_all(void);
 
 gboolean _check_uuid_path(char *path, char *uuid);
 #endif
 
 void _bluetooth_hid_free_hid_info(void);
 
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */