Commit c08b1a1d authored by Marcel Holtmann's avatar Marcel Holtmann Committed by Johan Hedberg

Bluetooth: Consolidate socket channel sending function back into one

With the introduction of trusted socket flag for control and monitor
channels, it is now possible to use a single function for sending
packets to these sockets. And with that consolidate the handling.
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent 50ebc055
...@@ -1284,9 +1284,7 @@ void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); ...@@ -1284,9 +1284,7 @@ void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
/* ----- HCI Sockets ----- */ /* ----- HCI Sockets ----- */
void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb); void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
void hci_send_to_channel(unsigned short channel, struct sk_buff *skb, void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
struct sock *skip_sk); int flag, struct sock *skip_sk);
void hci_send_to_flagged_channel(unsigned short channel, struct sk_buff *skb,
int flag);
void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb); void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
void hci_sock_dev_event(struct hci_dev *hdev, int event); void hci_sock_dev_event(struct hci_dev *hdev, int event);
......
...@@ -199,7 +199,7 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -199,7 +199,7 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
/* Send frame to sockets with specific channel */ /* Send frame to sockets with specific channel */
void hci_send_to_channel(unsigned short channel, struct sk_buff *skb, void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
struct sock *skip_sk) int flag, struct sock *skip_sk)
{ {
struct sock *sk; struct sock *sk;
...@@ -210,41 +210,12 @@ void hci_send_to_channel(unsigned short channel, struct sk_buff *skb, ...@@ -210,41 +210,12 @@ void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
sk_for_each(sk, &hci_sk_list.head) { sk_for_each(sk, &hci_sk_list.head) {
struct sk_buff *nskb; struct sk_buff *nskb;
/* Skip the original socket */ /* Ignore socket without the flag set */
if (sk == skip_sk) if (!test_bit(flag, &hci_pi(sk)->flags))
continue;
if (sk->sk_state != BT_BOUND)
continue;
if (hci_pi(sk)->channel != channel)
continue;
nskb = skb_clone(skb, GFP_ATOMIC);
if (!nskb)
continue; continue;
if (sock_queue_rcv_skb(sk, nskb)) /* Skip the original socket */
kfree_skb(nskb); if (sk == skip_sk)
}
read_unlock(&hci_sk_list.lock);
}
/* Send frame to sockets with specific channel flag set */
void hci_send_to_flagged_channel(unsigned short channel, struct sk_buff *skb,
int flag)
{
struct sock *sk;
BT_DBG("channel %u len %d", channel, skb->len);
read_lock(&hci_sk_list.lock);
sk_for_each(sk, &hci_sk_list.head) {
struct sk_buff *nskb;
if (!test_bit(flag, &hci_pi(sk)->flags))
continue; continue;
if (sk->sk_state != BT_BOUND) if (sk->sk_state != BT_BOUND)
...@@ -310,7 +281,8 @@ void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -310,7 +281,8 @@ void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb)
hdr->index = cpu_to_le16(hdev->id); hdr->index = cpu_to_le16(hdev->id);
hdr->len = cpu_to_le16(skb->len); hdr->len = cpu_to_le16(skb->len);
hci_send_to_channel(HCI_CHANNEL_MONITOR, skb_copy, NULL); hci_send_to_channel(HCI_CHANNEL_MONITOR, skb_copy,
HCI_SOCK_TRUSTED, NULL);
kfree_skb(skb_copy); kfree_skb(skb_copy);
} }
...@@ -417,7 +389,8 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event) ...@@ -417,7 +389,8 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event)
skb = create_monitor_event(hdev, event); skb = create_monitor_event(hdev, event);
if (skb) { if (skb) {
hci_send_to_channel(HCI_CHANNEL_MONITOR, skb, NULL); hci_send_to_channel(HCI_CHANNEL_MONITOR, skb,
HCI_SOCK_TRUSTED, NULL);
kfree_skb(skb); kfree_skb(skb);
} }
} }
......
...@@ -224,7 +224,7 @@ static u8 mgmt_status(u8 hci_status) ...@@ -224,7 +224,7 @@ static u8 mgmt_status(u8 hci_status)
static int mgmt_send_event(u16 event, struct hci_dev *hdev, static int mgmt_send_event(u16 event, struct hci_dev *hdev,
unsigned short channel, void *data, u16 data_len, unsigned short channel, void *data, u16 data_len,
struct sock *skip_sk) int flag, struct sock *skip_sk)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct mgmt_hdr *hdr; struct mgmt_hdr *hdr;
...@@ -247,44 +247,24 @@ static int mgmt_send_event(u16 event, struct hci_dev *hdev, ...@@ -247,44 +247,24 @@ static int mgmt_send_event(u16 event, struct hci_dev *hdev,
/* Time stamp */ /* Time stamp */
__net_timestamp(skb); __net_timestamp(skb);
hci_send_to_channel(channel, skb, skip_sk); hci_send_to_channel(channel, skb, flag, skip_sk);
kfree_skb(skb); kfree_skb(skb);
return 0; return 0;
} }
static int mgmt_index_event(u16 event, struct hci_dev *hdev, static int mgmt_index_event(u16 event, struct hci_dev *hdev, void *data,
void *data, u16 data_len, int flag) u16 len, int flag)
{ {
struct sk_buff *skb; return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len,
struct mgmt_hdr *hdr; flag, NULL);
skb = alloc_skb(sizeof(*hdr) + data_len, GFP_KERNEL);
if (!skb)
return -ENOMEM;
hdr = (void *) skb_put(skb, sizeof(*hdr));
hdr->opcode = cpu_to_le16(event);
hdr->index = cpu_to_le16(hdev->id);
hdr->len = cpu_to_le16(data_len);
if (data)
memcpy(skb_put(skb, data_len), data, data_len);
/* Time stamp */
__net_timestamp(skb);
hci_send_to_flagged_channel(HCI_CHANNEL_CONTROL, skb, flag);
kfree_skb(skb);
return 0;
} }
static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, u16 len, static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, u16 len,
struct sock *skip_sk) struct sock *skip_sk)
{ {
return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len, return mgmt_send_event(event, hdev, HCI_CHANNEL_CONTROL, data, len,
skip_sk); HCI_SOCK_TRUSTED, skip_sk);
} }
static int mgmt_cmd_status(struct sock *sk, u16 index, u16 cmd, u8 status) static int mgmt_cmd_status(struct sock *sk, u16 index, u16 cmd, u8 status)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment