Skip to content

Commit 9e726b1

Browse files
Luiz Augusto von Dentzholtmann
authored andcommitted
Bluetooth: Fix rejected connection not disconnecting ACL link
When using DEFER_SETUP on a RFCOMM socket, a SABM frame triggers authorization which when rejected send a DM response. This is fine according to the RFCOMM spec: the responding implementation may replace the "proper" response on the Multiplexer Control channel with a DM frame, sent on the referenced DLCI to indicate that the DLCI is not open, and that the responder would not grant a request to open it later either. But some stacks doesn't seems to cope with this leaving DLCI 0 open after receiving DM frame. To fix it properly a timer was introduced to rfcomm_session which is used to set a timeout when the last active DLC of a session is unlinked, this will give the remote stack some time to reply with a proper DISC frame on DLCI 0 avoiding both sides sending DISC to each other on stacks that follow the specification and taking care of those who don't by taking down DLCI 0. Signed-off-by: Luiz Augusto von Dentz <luiz.dentz@openbossa.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent ef54fd9 commit 9e726b1

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎include/net/bluetooth/rfcomm.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define RFCOMM_CONN_TIMEOUT (HZ * 30)
3030
#define RFCOMM_DISC_TIMEOUT (HZ * 20)
3131
#define RFCOMM_AUTH_TIMEOUT (HZ * 25)
32+
#define RFCOMM_IDLE_TIMEOUT (HZ * 2)
3233

3334
#define RFCOMM_DEFAULT_MTU 127
3435
#define RFCOMM_DEFAULT_CREDITS 7
@@ -154,6 +155,7 @@ struct rfcomm_msc {
154155
struct rfcomm_session {
155156
struct list_head list;
156157
struct socket *sock;
158+
struct timer_list timer;
157159
unsigned long state;
158160
unsigned long flags;
159161
atomic_t refcnt;

‎net/bluetooth/rfcomm/core.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,33 @@ static inline int rfcomm_check_security(struct rfcomm_dlc *d)
244244
auth_type);
245245
}
246246

247+
static void rfcomm_session_timeout(unsigned long arg)
248+
{
249+
struct rfcomm_session *s = (void *) arg;
250+
251+
BT_DBG("session %p state %ld", s, s->state);
252+
253+
set_bit(RFCOMM_TIMED_OUT, &s->flags);
254+
rfcomm_session_put(s);
255+
rfcomm_schedule(RFCOMM_SCHED_TIMEO);
256+
}
257+
258+
static void rfcomm_session_set_timer(struct rfcomm_session *s, long timeout)
259+
{
260+
BT_DBG("session %p state %ld timeout %ld", s, s->state, timeout);
261+
262+
if (!mod_timer(&s->timer, jiffies + timeout))
263+
rfcomm_session_hold(s);
264+
}
265+
266+
static void rfcomm_session_clear_timer(struct rfcomm_session *s)
267+
{
268+
BT_DBG("session %p state %ld", s, s->state);
269+
270+
if (timer_pending(&s->timer) && del_timer(&s->timer))
271+
rfcomm_session_put(s);
272+
}
273+
247274
/* ---- RFCOMM DLCs ---- */
248275
static void rfcomm_dlc_timeout(unsigned long arg)
249276
{
@@ -320,6 +347,7 @@ static void rfcomm_dlc_link(struct rfcomm_session *s, struct rfcomm_dlc *d)
320347

321348
rfcomm_session_hold(s);
322349

350+
rfcomm_session_clear_timer(s);
323351
rfcomm_dlc_hold(d);
324352
list_add(&d->list, &s->dlcs);
325353
d->session = s;
@@ -335,6 +363,9 @@ static void rfcomm_dlc_unlink(struct rfcomm_dlc *d)
335363
d->session = NULL;
336364
rfcomm_dlc_put(d);
337365

366+
if (list_empty(&s->dlcs))
367+
rfcomm_session_set_timer(s, RFCOMM_IDLE_TIMEOUT);
368+
338369
rfcomm_session_put(s);
339370
}
340371

@@ -567,6 +598,8 @@ static struct rfcomm_session *rfcomm_session_add(struct socket *sock, int state)
567598

568599
BT_DBG("session %p sock %p", s, sock);
569600

601+
setup_timer(&s->timer, rfcomm_session_timeout, (unsigned long) s);
602+
570603
INIT_LIST_HEAD(&s->dlcs);
571604
s->state = state;
572605
s->sock = sock;
@@ -598,6 +631,7 @@ static void rfcomm_session_del(struct rfcomm_session *s)
598631
if (state == BT_CONNECTED)
599632
rfcomm_send_disc(s, 0);
600633

634+
rfcomm_session_clear_timer(s);
601635
sock_release(s->sock);
602636
kfree(s);
603637

@@ -639,6 +673,7 @@ static void rfcomm_session_close(struct rfcomm_session *s, int err)
639673
__rfcomm_dlc_close(d, err);
640674
}
641675

676+
rfcomm_session_clear_timer(s);
642677
rfcomm_session_put(s);
643678
}
644679

@@ -1879,6 +1914,12 @@ static inline void rfcomm_process_sessions(void)
18791914
struct rfcomm_session *s;
18801915
s = list_entry(p, struct rfcomm_session, list);
18811916

1917+
if (test_and_clear_bit(RFCOMM_TIMED_OUT, &s->flags)) {
1918+
s->state = BT_DISCONN;
1919+
rfcomm_send_disc(s, 0);
1920+
continue;
1921+
}
1922+
18821923
if (s->state == BT_LISTEN) {
18831924
rfcomm_accept_connection(s);
18841925
continue;

0 commit comments

Comments
 (0)