Skip to content

Commit dfe6d5c

Browse files
committed
Bluetooth: hci_core: Introduce hci_recv_event_data
This introduces hci_recv_event_data to make it simpler to access the contents of last received event rather than having to pass its contents to the likes of *_ind/*_cfm callbacks. Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 0ef0831 commit dfe6d5c

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ struct hci_dev {
525525
struct sk_buff_head cmd_q;
526526

527527
struct sk_buff *sent_cmd;
528+
struct sk_buff *recv_event;
528529

529530
struct mutex req_lock;
530531
wait_queue_head_t req_wait_q;
@@ -1747,6 +1748,7 @@ void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
17471748
void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
17481749

17491750
void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
1751+
void *hci_recv_event_data(struct hci_dev *hdev, __u8 event);
17501752

17511753
u32 hci_conn_get_phy(struct hci_conn *conn);
17521754

net/bluetooth/hci_core.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,6 +2712,7 @@ void hci_release_dev(struct hci_dev *hdev)
27122712

27132713
ida_simple_remove(&hci_index_ida, hdev->id);
27142714
kfree_skb(hdev->sent_cmd);
2715+
kfree_skb(hdev->recv_event);
27152716
kfree(hdev);
27162717
}
27172718
EXPORT_SYMBOL(hci_release_dev);
@@ -3018,6 +3019,37 @@ void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode)
30183019
return hdev->sent_cmd->data + HCI_COMMAND_HDR_SIZE;
30193020
}
30203021

3022+
/* Get data from last received event */
3023+
void *hci_recv_event_data(struct hci_dev *hdev, __u8 event)
3024+
{
3025+
struct hci_event_hdr *hdr;
3026+
int offset;
3027+
3028+
if (!hdev->recv_event)
3029+
return NULL;
3030+
3031+
hdr = (void *)hdev->recv_event->data;
3032+
offset = sizeof(*hdr);
3033+
3034+
if (hdr->evt != event) {
3035+
/* In case of LE metaevent check the subevent match */
3036+
if (hdr->evt == HCI_EV_LE_META) {
3037+
struct hci_ev_le_meta *ev;
3038+
3039+
ev = (void *)hdev->recv_event->data + offset;
3040+
offset += sizeof(*ev);
3041+
if (ev->subevent == event)
3042+
goto found;
3043+
}
3044+
return NULL;
3045+
}
3046+
3047+
found:
3048+
bt_dev_dbg(hdev, "event 0x%2.2x", event);
3049+
3050+
return hdev->recv_event->data + offset;
3051+
}
3052+
30213053
/* Send ACL data */
30223054
static void hci_add_acl_hdr(struct sk_buff *skb, __u16 handle, __u16 flags)
30233055
{

net/bluetooth/hci_event.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6936,6 +6936,9 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
69366936
goto done;
69376937
}
69386938

6939+
kfree_skb(hdev->recv_event);
6940+
hdev->recv_event = skb_clone(skb, GFP_KERNEL);
6941+
69396942
event = hdr->evt;
69406943
if (!event) {
69416944
bt_dev_warn(hdev, "Received unexpected HCI Event 0x%2.2x",

0 commit comments

Comments
 (0)