Skip to content

Commit

Permalink
Bluetooth: Send control open and close only when cookie is present
Browse files Browse the repository at this point in the history
Only when the cookie has been assigned, then send the open and close
monitor messages. Also if the socket is bound to a device, then include
the index into the message.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
  • Loading branch information
Marcel Holtmann committed Sep 19, 2016
1 parent 9e8305b commit 0ef2c42
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ static struct sk_buff *create_monitor_ctrl_open(struct sock *sk)
u8 ver[3];
u32 flags;

/* No message needed when cookie is not present */
if (!hci_pi(sk)->cookie)
return NULL;

skb = bt_skb_alloc(14 + TASK_COMM_LEN , GFP_ATOMIC);
if (!skb)
return NULL;
Expand All @@ -501,7 +505,10 @@ static struct sk_buff *create_monitor_ctrl_open(struct sock *sk)

hdr = (void *)skb_push(skb, HCI_MON_HDR_SIZE);
hdr->opcode = cpu_to_le16(HCI_MON_CTRL_OPEN);
hdr->index = cpu_to_le16(HCI_DEV_NONE);
if (hci_pi(sk)->hdev)
hdr->index = cpu_to_le16(hci_pi(sk)->hdev->id);
else
hdr->index = cpu_to_le16(HCI_DEV_NONE);
hdr->len = cpu_to_le16(skb->len - HCI_MON_HDR_SIZE);

return skb;
Expand All @@ -512,6 +519,10 @@ static struct sk_buff *create_monitor_ctrl_close(struct sock *sk)
struct hci_mon_hdr *hdr;
struct sk_buff *skb;

/* No message needed when cookie is not present */
if (!hci_pi(sk)->cookie)
return NULL;

skb = bt_skb_alloc(4, GFP_ATOMIC);
if (!skb)
return NULL;
Expand All @@ -522,7 +533,10 @@ static struct sk_buff *create_monitor_ctrl_close(struct sock *sk)

hdr = (void *)skb_push(skb, HCI_MON_HDR_SIZE);
hdr->opcode = cpu_to_le16(HCI_MON_CTRL_CLOSE);
hdr->index = cpu_to_le16(HCI_DEV_NONE);
if (hci_pi(sk)->hdev)
hdr->index = cpu_to_le16(hci_pi(sk)->hdev->id);
else
hdr->index = cpu_to_le16(HCI_DEV_NONE);
hdr->len = cpu_to_le16(skb->len - HCI_MON_HDR_SIZE);

return skb;
Expand Down

0 comments on commit 0ef2c42

Please sign in to comment.