Skip to content

Commit 2dc4e51

Browse files
author
Gustavo Padovan
committed
Bluetooth: Add chan->ops->defer()
When DEFER_SETUP is set defer() will trigger an authorization request to the userspace. l2cap_chan_no_defer() is meant to be used when one does not want to support DEFER_SETUP (A2MP for example). Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
1 parent 644912e commit 2dc4e51

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎include/net/bluetooth/l2cap.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ struct l2cap_ops {
541541
void (*state_change) (struct l2cap_chan *chan,
542542
int state);
543543
void (*ready) (struct l2cap_chan *chan);
544+
void (*defer) (struct l2cap_chan *chan);
544545
struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
545546
unsigned long len, int nb);
546547
};
@@ -748,6 +749,10 @@ static inline void l2cap_chan_no_ready(struct l2cap_chan *chan)
748749
{
749750
}
750751

752+
static inline void l2cap_chan_no_defer(struct l2cap_chan *chan)
753+
{
754+
}
755+
751756
extern bool disable_ertm;
752757

753758
int l2cap_init_sockets(void);

‎net/bluetooth/a2mp.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ static struct l2cap_ops a2mp_chan_ops = {
699699
.new_connection = l2cap_chan_no_new_connection,
700700
.teardown = l2cap_chan_no_teardown,
701701
.ready = l2cap_chan_no_ready,
702+
.defer = l2cap_chan_no_defer,
702703
};
703704

704705
static struct l2cap_chan *a2mp_chan_open(struct l2cap_conn *conn, bool locked)

‎net/bluetooth/l2cap_core.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,11 +1120,9 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
11201120
lock_sock(sk);
11211121
if (test_bit(BT_SK_DEFER_SETUP,
11221122
&bt_sk(sk)->flags)) {
1123-
struct sock *parent = bt_sk(sk)->parent;
11241123
rsp.result = __constant_cpu_to_le16(L2CAP_CR_PEND);
11251124
rsp.status = __constant_cpu_to_le16(L2CAP_CS_AUTHOR_PEND);
1126-
if (parent)
1127-
parent->sk_data_ready(parent, 0);
1125+
chan->ops->defer(chan);
11281126

11291127
} else {
11301128
__l2cap_state_change(chan, BT_CONFIG);
@@ -3460,7 +3458,7 @@ static void __l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd,
34603458
__l2cap_state_change(chan, BT_CONNECT2);
34613459
result = L2CAP_CR_PEND;
34623460
status = L2CAP_CS_AUTHOR_PEND;
3463-
parent->sk_data_ready(parent, 0);
3461+
chan->ops->defer(chan);
34643462
} else {
34653463
__l2cap_state_change(chan, BT_CONFIG);
34663464
result = L2CAP_CR_SUCCESS;
@@ -5523,11 +5521,9 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
55235521
if (!status) {
55245522
if (test_bit(BT_SK_DEFER_SETUP,
55255523
&bt_sk(sk)->flags)) {
5526-
struct sock *parent = bt_sk(sk)->parent;
55275524
res = L2CAP_CR_PEND;
55285525
stat = L2CAP_CS_AUTHOR_PEND;
5529-
if (parent)
5530-
parent->sk_data_ready(parent, 0);
5526+
chan->ops->defer(chan);
55315527
} else {
55325528
__l2cap_state_change(chan, BT_CONFIG);
55335529
res = L2CAP_CR_SUCCESS;

‎net/bluetooth/l2cap_sock.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,15 @@ static void l2cap_sock_ready_cb(struct l2cap_chan *chan)
10811081
release_sock(sk);
10821082
}
10831083

1084+
static void l2cap_sock_defer_cb(struct l2cap_chan *chan)
1085+
{
1086+
struct sock *sk = chan->data;
1087+
struct sock *parent = bt_sk(sk)->parent;
1088+
1089+
if (parent)
1090+
parent->sk_data_ready(parent, 0);
1091+
}
1092+
10841093
static struct l2cap_ops l2cap_chan_ops = {
10851094
.name = "L2CAP Socket Interface",
10861095
.new_connection = l2cap_sock_new_connection_cb,
@@ -1089,6 +1098,7 @@ static struct l2cap_ops l2cap_chan_ops = {
10891098
.teardown = l2cap_sock_teardown_cb,
10901099
.state_change = l2cap_sock_state_change_cb,
10911100
.ready = l2cap_sock_ready_cb,
1101+
.defer = l2cap_sock_defer_cb,
10921102
.alloc_skb = l2cap_sock_alloc_skb_cb,
10931103
};
10941104

0 commit comments

Comments
 (0)