avdtp: Fix always destroying session immediatelly
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 21 Jan 2019 11:29:09 +0000 (13:29 +0200)
committerhimanshu <h.himanshu@samsung.com>
Wed, 22 Jan 2020 09:07:09 +0000 (14:37 +0530)
In case the remote device sent a close/abort the session shall not be
free immediatelly as the remote may want to reconfigure the stream.

Change-Id: I7934f4a837c910ee80df64f24face6980dc476ad
Signed-off-by: himanshu <h.himanshu@samsung.com>
profiles/audio/avdtp.c

index 60d9253..15ed696 100644 (file)
@@ -441,6 +441,7 @@ struct avdtp {
        struct pending_req *req;
 
        guint dc_timer;
+       int dc_timeout;
 
        /* Attempt stream setup instead of disconnecting */
        gboolean stream_setup;
@@ -1576,10 +1577,11 @@ static void set_disconnect_timer(struct avdtp *session)
                                session);
        }
 #else
-       if (!session->stream_setup && !session->streams)
+       DBG("timeout %d", session->dc_timeout);
+       if (!session->dc_timeout)
                session->dc_timer = g_idle_add(disconnect_timeout, session);
        else
-               session->dc_timer = g_timeout_add_seconds(DISCONNECT_TIMEOUT,
+               session->dc_timer = g_timeout_add_seconds(session->dc_timeout,
                                                        disconnect_timeout,
                                                        session);
 #endif
@@ -2243,6 +2245,8 @@ static gboolean avdtp_close_cmd(struct avdtp *session, uint8_t transaction,
 
        avdtp_sep_set_state(session, sep, AVDTP_STATE_CLOSING);
 
+       session->dc_timeout = DISCONNECT_TIMEOUT;
+
        if (!avdtp_send(session, transaction, AVDTP_MSG_TYPE_ACCEPT,
                                                AVDTP_CLOSE, NULL, 0))
                return FALSE;
@@ -2347,8 +2351,10 @@ static gboolean avdtp_abort_cmd(struct avdtp *session, uint8_t transaction,
 
        ret = avdtp_send(session, transaction, AVDTP_MSG_TYPE_ACCEPT,
                                                AVDTP_ABORT, NULL, 0);
-       if (ret)
+       if (ret) {
                avdtp_sep_set_state(session, sep, AVDTP_STATE_ABORTING);
+               session->dc_timeout = DISCONNECT_TIMEOUT;
+       }
 
        return ret;
 }
@@ -2858,6 +2864,8 @@ struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
         * with respect to the disconnect timer */
        session->stream_setup = TRUE;
 
+       session->dc_timeout = DISCONNECT_TIMEOUT;
+
        avdtp_connect_cb(chan, NULL, session);
 
        return session;
@@ -4017,8 +4025,10 @@ int avdtp_close(struct avdtp *session, struct avdtp_stream *stream,
 
        ret = send_request(session, FALSE, stream, AVDTP_CLOSE,
                                                        &req, sizeof(req));
-       if (ret == 0)
+       if (ret == 0) {
                stream->close_int = TRUE;
+               session->dc_timeout = 0;
+       }
 
        return ret;
 }
@@ -4066,8 +4076,10 @@ int avdtp_abort(struct avdtp *session, struct avdtp_stream *stream)
 
        ret = send_request(session, TRUE, stream, AVDTP_ABORT,
                                                        &req, sizeof(req));
-       if (ret == 0)
+       if (ret == 0) {
                stream->abort_int = TRUE;
+               session->dc_timeout = 0;
+       }
 
        return ret;
 }