Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Grzegorz Kolodziejczyk and committed by
Marcel Holtmann
836a061b bf8b9a9c

+15 -4
+3
net/bluetooth/bnep/bnep.h
··· 113 113 #define BNEPGETCONNINFO _IOR('B', 211, int) 114 114 #define BNEPGETSUPPFEAT _IOR('B', 212, int) 115 115 116 + #define BNEP_SETUP_RESPONSE 0 117 + #define BNEP_SETUP_RSP_SENT 10 118 + 116 119 struct bnep_connadd_req { 117 120 int sock; /* Connected socket */ 118 121 __u32 flags;
+11 -3
net/bluetooth/bnep/core.c
··· 231 231 break; 232 232 233 233 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); 235 242 break; 236 243 237 244 default: { ··· 558 551 559 552 int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock) 560 553 { 561 - u32 valid_flags = 0; 554 + u32 valid_flags = BIT(BNEP_SETUP_RESPONSE); 562 555 struct net_device *dev; 563 556 struct bnep_session *s, *ss; 564 557 u8 dst[ETH_ALEN], src[ETH_ALEN]; ··· 603 596 s->sock = sock; 604 597 s->role = req->role; 605 598 s->state = BT_CONNECTED; 599 + s->flags = req->flags; 606 600 607 601 s->msg.msg_flags = MSG_NOSIGNAL; 608 602 ··· 673 665 674 666 static void __bnep_copy_ci(struct bnep_conninfo *ci, struct bnep_session *s) 675 667 { 676 - u32 valid_flags = 0; 668 + u32 valid_flags = BIT(BNEP_SETUP_RESPONSE); 677 669 678 670 memset(ci, 0, sizeof(*ci)); 679 671 memcpy(ci->dst, s->eh.h_source, ETH_ALEN);
+1 -1
net/bluetooth/bnep/sock.c
··· 57 57 struct bnep_conninfo ci; 58 58 struct socket *nsock; 59 59 void __user *argp = (void __user *)arg; 60 - __u32 supp_feat = 0; 60 + __u32 supp_feat = BIT(BNEP_SETUP_RESPONSE); 61 61 int err; 62 62 63 63 BT_DBG("cmd %x arg %lx", cmd, arg);