Skip to content

Commit 791d60f

Browse files
Johan Hedbergholtmann
authored andcommitted
Bluetooth: Refactor L2CAP connect rejection to its own function
We'll need to have a separate code path for LE based connection rejection so it's cleaner to move out the response construction code into its own function (and later a second one for LE). Signed-off-by: Johan Hedberg <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent ad32a2f commit 791d60f

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

net/bluetooth/l2cap_core.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,27 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err)
617617
return;
618618
}
619619

620+
static void l2cap_chan_connect_reject(struct l2cap_chan *chan)
621+
{
622+
struct l2cap_conn *conn = chan->conn;
623+
struct l2cap_conn_rsp rsp;
624+
u16 result;
625+
626+
if (test_bit(FLAG_DEFER_SETUP, &chan->flags))
627+
result = L2CAP_CR_SEC_BLOCK;
628+
else
629+
result = L2CAP_CR_BAD_PSM;
630+
631+
l2cap_state_change(chan, BT_DISCONN);
632+
633+
rsp.scid = cpu_to_le16(chan->dcid);
634+
rsp.dcid = cpu_to_le16(chan->scid);
635+
rsp.result = cpu_to_le16(result);
636+
rsp.status = __constant_cpu_to_le16(L2CAP_CS_NO_INFO);
637+
638+
l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP, sizeof(rsp), &rsp);
639+
}
640+
620641
void l2cap_chan_close(struct l2cap_chan *chan, int reason)
621642
{
622643
struct l2cap_conn *conn = chan->conn;
@@ -639,24 +660,9 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
639660
break;
640661

641662
case BT_CONNECT2:
642-
if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED &&
643-
conn->hcon->type == ACL_LINK) {
644-
struct l2cap_conn_rsp rsp;
645-
__u16 result;
646-
647-
if (test_bit(FLAG_DEFER_SETUP, &chan->flags))
648-
result = L2CAP_CR_SEC_BLOCK;
649-
else
650-
result = L2CAP_CR_BAD_PSM;
651-
652-
l2cap_state_change(chan, BT_DISCONN);
653-
654-
rsp.scid = cpu_to_le16(chan->dcid);
655-
rsp.dcid = cpu_to_le16(chan->scid);
656-
rsp.result = cpu_to_le16(result);
657-
rsp.status = __constant_cpu_to_le16(L2CAP_CS_NO_INFO);
658-
l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP,
659-
sizeof(rsp), &rsp);
663+
if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED) {
664+
if (conn->hcon->type == ACL_LINK)
665+
l2cap_chan_connect_reject(chan);
660666
}
661667

662668
l2cap_chan_del(chan, reason);

0 commit comments

Comments
 (0)