Skip to content

Commit

Permalink
Bluetooth: Create generic queue_monitor_skb helper function
Browse files Browse the repository at this point in the history
The hci_send_to_monitor function contains generic code for queueing the
packet into the receive queue of every monitor client. To avoid code
duplication, create a generic queue_monitor_skb function to interate
over all monitor sockets.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
  • Loading branch information
Marcel Holtmann authored and Johan Hedberg committed Jan 12, 2015
1 parent 2b53129 commit d7f72f6
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,37 @@ void hci_send_to_control(struct sk_buff *skb, struct sock *skip_sk)
read_unlock(&hci_sk_list.lock);
}

static void queue_monitor_skb(struct sk_buff *skb)
{
struct sock *sk;

BT_DBG("len %d", skb->len);

read_lock(&hci_sk_list.lock);

sk_for_each(sk, &hci_sk_list.head) {
struct sk_buff *nskb;

if (sk->sk_state != BT_BOUND)
continue;

if (hci_pi(sk)->channel != HCI_CHANNEL_MONITOR)
continue;

nskb = skb_clone(skb, GFP_ATOMIC);
if (!nskb)
continue;

if (sock_queue_rcv_skb(sk, nskb))
kfree_skb(nskb);
}

read_unlock(&hci_sk_list.lock);
}

/* Send frame to monitor socket */
void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb)
{
struct sock *sk;
struct sk_buff *skb_copy = NULL;
struct hci_mon_hdr *hdr;
__le16 opcode;
Expand Down Expand Up @@ -263,27 +290,7 @@ void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb)
hdr->index = cpu_to_le16(hdev->id);
hdr->len = cpu_to_le16(skb->len);

read_lock(&hci_sk_list.lock);

sk_for_each(sk, &hci_sk_list.head) {
struct sk_buff *nskb;

if (sk->sk_state != BT_BOUND)
continue;

if (hci_pi(sk)->channel != HCI_CHANNEL_MONITOR)
continue;

nskb = skb_clone(skb_copy, GFP_ATOMIC);
if (!nskb)
continue;

if (sock_queue_rcv_skb(sk, nskb))
kfree_skb(nskb);
}

read_unlock(&hci_sk_list.lock);

queue_monitor_skb(skb_copy);
kfree_skb(skb_copy);
}

Expand Down

0 comments on commit d7f72f6

Please sign in to comment.