Skip to content

Commit

Permalink
Bluetooth: bnep: Handle BNEP connection setup request
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Marcel Holtmann <[email protected]>
  • Loading branch information
kolodgrz authored and holtmann committed Apr 3, 2015
1 parent bf8b9a9 commit 836a061
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions net/bluetooth/bnep/bnep.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ struct bnep_ext_hdr {
#define BNEPGETCONNINFO _IOR('B', 211, int)
#define BNEPGETSUPPFEAT _IOR('B', 212, int)

#define BNEP_SETUP_RESPONSE 0
#define BNEP_SETUP_RSP_SENT 10

struct bnep_connadd_req {
int sock; /* Connected socket */
__u32 flags;
Expand Down
14 changes: 11 additions & 3 deletions net/bluetooth/bnep/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,14 @@ static int bnep_rx_control(struct bnep_session *s, void *data, int len)
break;

case BNEP_SETUP_CONN_REQ:
err = bnep_send_rsp(s, BNEP_SETUP_CONN_RSP, BNEP_CONN_NOT_ALLOWED);
/* Successful response should be sent only once */
if (test_bit(BNEP_SETUP_RESPONSE, &s->flags) &&
!test_and_set_bit(BNEP_SETUP_RSP_SENT, &s->flags))
err = bnep_send_rsp(s, BNEP_SETUP_CONN_RSP,
BNEP_SUCCESS);
else
err = bnep_send_rsp(s, BNEP_SETUP_CONN_RSP,
BNEP_CONN_NOT_ALLOWED);
break;

default: {
Expand Down Expand Up @@ -551,7 +558,7 @@ static struct device_type bnep_type = {

int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
{
u32 valid_flags = 0;
u32 valid_flags = BIT(BNEP_SETUP_RESPONSE);
struct net_device *dev;
struct bnep_session *s, *ss;
u8 dst[ETH_ALEN], src[ETH_ALEN];
Expand Down Expand Up @@ -596,6 +603,7 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
s->sock = sock;
s->role = req->role;
s->state = BT_CONNECTED;
s->flags = req->flags;

s->msg.msg_flags = MSG_NOSIGNAL;

Expand Down Expand Up @@ -665,7 +673,7 @@ int bnep_del_connection(struct bnep_conndel_req *req)

static void __bnep_copy_ci(struct bnep_conninfo *ci, struct bnep_session *s)
{
u32 valid_flags = 0;
u32 valid_flags = BIT(BNEP_SETUP_RESPONSE);

memset(ci, 0, sizeof(*ci));
memcpy(ci->dst, s->eh.h_source, ETH_ALEN);
Expand Down
2 changes: 1 addition & 1 deletion net/bluetooth/bnep/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static int bnep_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
struct bnep_conninfo ci;
struct socket *nsock;
void __user *argp = (void __user *)arg;
__u32 supp_feat = 0;
__u32 supp_feat = BIT(BNEP_SETUP_RESPONSE);
int err;

BT_DBG("cmd %x arg %lx", cmd, arg);
Expand Down

0 comments on commit 836a061

Please sign in to comment.