Skip to content

Commit c4f912e

Browse files
committed
Bluetooth: Add global deferred socket parameter
The L2CAP and RFCOMM applications require support for authorization and the ability of rejecting incoming connection requests. The socket interface is not really able to support this. This patch does the ground work for a socket option to defer connection setup. Setting this option allows calling of accept() and then the first read() will trigger the final connection setup. Calling close() would reject the connection. Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent d58daf4 commit c4f912e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

include/net/bluetooth/bluetooth.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#define SOL_SCO 17
5454
#define SOL_RFCOMM 18
5555

56+
#define BT_DEFER_SETUP 7
57+
5658
#define BT_INFO(fmt, arg...) printk(KERN_INFO "Bluetooth: " fmt "\n" , ## arg)
5759
#define BT_ERR(fmt, arg...) printk(KERN_ERR "%s: " fmt "\n" , __func__ , ## arg)
5860
#define BT_DBG(fmt, arg...) pr_debug("%s: " fmt "\n" , __func__ , ## arg)
@@ -108,6 +110,7 @@ struct bt_sock {
108110
bdaddr_t dst;
109111
struct list_head accept_q;
110112
struct sock *parent;
113+
u32 defer_setup;
111114
};
112115

113116
struct bt_sock_list {

net/bluetooth/af_bluetooth.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock)
217217
continue;
218218
}
219219

220-
if (sk->sk_state == BT_CONNECTED || !newsock) {
220+
if (sk->sk_state == BT_CONNECTED || !newsock ||
221+
bt_sk(parent)->defer_setup) {
221222
bt_accept_unlink(sk);
222223
if (newsock)
223224
sock_graft(sk, newsock);
@@ -232,7 +233,7 @@ struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock)
232233
EXPORT_SYMBOL(bt_accept_dequeue);
233234

234235
int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
235-
struct msghdr *msg, size_t len, int flags)
236+
struct msghdr *msg, size_t len, int flags)
236237
{
237238
int noblock = flags & MSG_DONTWAIT;
238239
struct sock *sk = sock->sk;
@@ -275,6 +276,9 @@ static inline unsigned int bt_accept_poll(struct sock *parent)
275276
struct list_head *p, *n;
276277
struct sock *sk;
277278

279+
if (bt_sk(parent)->defer_setup)
280+
return POLLIN | POLLRDNORM;
281+
278282
list_for_each_safe(p, n, &bt_sk(parent)->accept_q) {
279283
sk = (struct sock *) list_entry(p, struct bt_sock, accept_q);
280284
if (sk->sk_state == BT_CONNECTED)

0 commit comments

Comments
 (0)