Skip to content

Commit 836a061

Browse files
kolodgrzholtmann
authored andcommitted
Bluetooth: bnep: Handle BNEP connection setup request
With this patch kernel will be able to handle setup request. This is needed if we would like to handle control mesages with extension headers. User space will be only resposible for reading setup data and checking if scenario is conformance to specification (dst and src device bnep role). In case of new user space, setup data must be leaved(peek msg) on queue. New bnep session will be responsible for handling this data. Signed-off-by: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@tieto.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent bf8b9a9 commit 836a061

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎net/bluetooth/bnep/bnep.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ struct bnep_ext_hdr {
113113
#define BNEPGETCONNINFO _IOR('B', 211, int)
114114
#define BNEPGETSUPPFEAT _IOR('B', 212, int)
115115

116+
#define BNEP_SETUP_RESPONSE 0
117+
#define BNEP_SETUP_RSP_SENT 10
118+
116119
struct bnep_connadd_req {
117120
int sock; /* Connected socket */
118121
__u32 flags;

‎net/bluetooth/bnep/core.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,14 @@ static int bnep_rx_control(struct bnep_session *s, void *data, int len)
231231
break;
232232

233233
case BNEP_SETUP_CONN_REQ:
234-
err = bnep_send_rsp(s, BNEP_SETUP_CONN_RSP, BNEP_CONN_NOT_ALLOWED);
234+
/* Successful response should be sent only once */
235+
if (test_bit(BNEP_SETUP_RESPONSE, &s->flags) &&
236+
!test_and_set_bit(BNEP_SETUP_RSP_SENT, &s->flags))
237+
err = bnep_send_rsp(s, BNEP_SETUP_CONN_RSP,
238+
BNEP_SUCCESS);
239+
else
240+
err = bnep_send_rsp(s, BNEP_SETUP_CONN_RSP,
241+
BNEP_CONN_NOT_ALLOWED);
235242
break;
236243

237244
default: {
@@ -551,7 +558,7 @@ static struct device_type bnep_type = {
551558

552559
int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
553560
{
554-
u32 valid_flags = 0;
561+
u32 valid_flags = BIT(BNEP_SETUP_RESPONSE);
555562
struct net_device *dev;
556563
struct bnep_session *s, *ss;
557564
u8 dst[ETH_ALEN], src[ETH_ALEN];
@@ -596,6 +603,7 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
596603
s->sock = sock;
597604
s->role = req->role;
598605
s->state = BT_CONNECTED;
606+
s->flags = req->flags;
599607

600608
s->msg.msg_flags = MSG_NOSIGNAL;
601609

@@ -665,7 +673,7 @@ int bnep_del_connection(struct bnep_conndel_req *req)
665673

666674
static void __bnep_copy_ci(struct bnep_conninfo *ci, struct bnep_session *s)
667675
{
668-
u32 valid_flags = 0;
676+
u32 valid_flags = BIT(BNEP_SETUP_RESPONSE);
669677

670678
memset(ci, 0, sizeof(*ci));
671679
memcpy(ci->dst, s->eh.h_source, ETH_ALEN);

‎net/bluetooth/bnep/sock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static int bnep_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
5757
struct bnep_conninfo ci;
5858
struct socket *nsock;
5959
void __user *argp = (void __user *)arg;
60-
__u32 supp_feat = 0;
60+
__u32 supp_feat = BIT(BNEP_SETUP_RESPONSE);
6161
int err;
6262

6363
BT_DBG("cmd %x arg %lx", cmd, arg);

0 commit comments

Comments
 (0)