Bluetooth: ISO: Miscellaneous fixes
Subsystems (2)
cover Bluetooth: ISO: Miscellaneous fixes
Currently, slave bis hcons and pa sync hcons are marked with the same flags, so they are handled the same at cleanup.
The first commit makes it so that closing all bis hcons will trigger BIG Terminate Sync, while closing all bises and the pa sync hcon will also trigger PA Terminate Sync.
The second commit fixes the way broadcast events are handled by the ISO layer: A new slave BIS hcon is notified after the Command Complete for LE Setup ISO Data Path is received, not after BIG Sync Established.
The iso_match_pa_sync_flag function has also been replaced with more specific matching functions, depending on the event being handled.
Iulia Tanasescu (2):
Bluetooth: ISO: Fix bcast listener cleanup
Bluetoth: ISO: Fix broadcast event handling
include/net/bluetooth/hci_core.h | 46 +++++++------- net/bluetooth/hci_conn.c | 38 +++++++++--- net/bluetooth/hci_core.c | 50 ++++++++++----- net/bluetooth/hci_event.c | 10 --- net/bluetooth/iso.c | 101 +++++++++++++++++++++++++------ 5 files changed, 169 insertions(+), 76 deletions(-)
base-commit: b8ba8e65e84b99d58e278900b4261ef17a20eb27
Signature · 1 line
2.39.2
PATCH 1/2 Bluetooth: ISO: Fix bcast listener cleanup
This fixes the cleanup callback for slave bis and pa sync hcons.
Closing all bis hcons will trigger BIG Terminate Sync, while closing all bises and the pa sync hcon will also trigger PA Terminate Sync.
--- include/net/bluetooth/hci_core.h | 43 +++++++++++++++----------------- net/bluetooth/hci_conn.c | 38 ++++++++++++++++++++++------ net/bluetooth/hci_event.c | 10 -------- 3 files changed, 50 insertions(+), 41 deletions(-)
include/net/bluetooth/hci_core.h +20 -23
@@ -1290,29 +1290,6 @@ static inline struct hci_conn *hci_conn_hash_lookup_big(struct hci_dev *hdev,return NULL ; } -static inline struct hci_conn *hci_conn_hash_lookup_big_any_dst (struct hci_dev *hdev, -__u8 handle) -{ -struct hci_conn_hash *h = &hdev->conn_hash; -struct hci_conn *c; - -rcu_read_lock (); - -list_for_each_entry_rcu (c, &h->list, list) { -if (c->type !=ISO_LINK ) -continue ; - -if (handle !=BT_ISO_QOS_BIG_UNSET && handle == c->iso_qos.bcast.big) { -rcu_read_unlock (); -return c; - } - } - -rcu_read_unlock (); - -return NULL ; -} -static inline struct hci_conn *hci_conn_hash_lookup_pa_sync_big_handle (struct hci_dev *hdev,__u8 big) {
@@ -1400,6 +1377,26 @@ static inline void hci_conn_hash_list_state(struct hci_dev *hdev,rcu_read_unlock (); } +static inline void hci_conn_hash_list_flag (struct hci_dev *hdev, +hci_conn_func_t func,__u8 type, +__u8 flag,void *data) +{ +struct hci_conn_hash *h = &hdev->conn_hash; +struct hci_conn *c; + +if (!func) +return ; + +rcu_read_lock (); + +list_for_each_entry_rcu (c, &h->list, list) { +if (c->type == type &&test_bit (flag, &c->flags)) +func (c, data); + } + +rcu_read_unlock (); +} +static inline struct hci_conn *hci_lookup_le_connect (struct hci_dev *hdev) {struct hci_conn_hash *h = &hdev->conn_hash;
net/bluetooth/hci_conn.c +30 -8
@@ -815,6 +815,17 @@ static int big_terminate_sync(struct hci_dev *hdev, void *data)return 0 ; } +static void find_bis (struct hci_conn *conn,void *data) +{ +struct iso_list_data *d = data; + +/* Ignore if BIG doesn't match */ +if (d->big != conn->iso_qos.bcast.big) +return ; + + d->count++; +} +static int hci_le_big_terminate (struct hci_dev *hdev,u8 big,struct hci_conn *conn) {struct iso_list_data *d;
@@ -826,10 +837,27 @@ static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, struct hci_conn *cif (!d)return -ENOMEM ; +memset (d,0 ,sizeof (*d)); d->big = big; d->sync_handle = conn->sync_handle; - d->pa_sync_term =test_and_clear_bit (HCI_CONN_PA_SYNC , &conn->flags); - d->big_sync_term =test_and_clear_bit (HCI_CONN_BIG_SYNC , &conn->flags); + +if (test_and_clear_bit (HCI_CONN_PA_SYNC , &conn->flags)) { +hci_conn_hash_list_flag (hdev, find_bis,ISO_LINK , +HCI_CONN_PA_SYNC , d); + +if (!d->count) + d->pa_sync_term = true; + + d->count =0 ; + } + +if (test_and_clear_bit (HCI_CONN_BIG_SYNC , &conn->flags)) { +hci_conn_hash_list_flag (hdev, find_bis,ISO_LINK , +HCI_CONN_BIG_SYNC , d); + +if (!d->count) + d->big_sync_term = true; + } ret =hci_cmd_sync_queue (hdev, big_terminate_sync, d, terminate_big_destroy);
@@ -865,12 +893,6 @@ static void bis_cleanup(struct hci_conn *conn)hci_le_terminate_big (hdev, conn); }else { - bis =hci_conn_hash_lookup_big_any_dst (hdev, - conn->iso_qos.bcast.big); - -if (bis) -return ; -hci_le_big_terminate (hdev, conn->iso_qos.bcast.big, conn); }
net/bluetooth/hci_event.c +0 -10
@@ -7112,7 +7112,6 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data, {struct hci_evt_le_big_sync_estabilished *ev = data;struct hci_conn *bis; -struct hci_conn *pa_sync;int i;bt_dev_dbg (hdev,"status 0x%2.2x" , ev->status);
@@ -7123,15 +7122,6 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,hci_dev_lock (hdev); -if (!ev->status) { - pa_sync =hci_conn_hash_lookup_pa_sync_big_handle (hdev, ev->handle); -if (pa_sync) -/* Also mark the BIG sync established event on the -* associated PA sync hcon -*/ -set_bit (HCI_CONN_BIG_SYNC , &pa_sync->flags); - } -for (i =0 ; i < ev->num_bis; i++) {u16 handle =le16_to_cpu (ev->bis[i]);__le32 interval;
Signature · 1 line
2.39.2
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=792216
---Test result---
Test Summary:
CheckPatch PASS 2.30 seconds GitLint PASS 0.69 seconds SubjectPrefix FAIL 0.52 seconds BuildKernel PASS 35.13 seconds CheckAllWarning PASS 37.87 seconds CheckSparse WARNING 43.98 seconds CheckSmatch WARNING 117.50 seconds BuildKernel32 PASS 33.37 seconds TestRunnerSetup PASS 527.59 seconds TestRunner_l2cap-tester PASS 31.69 seconds TestRunner_iso-tester PASS 53.51 seconds TestRunner_bnep-tester PASS 10.76 seconds TestRunner_mgmt-tester PASS 225.36 seconds TestRunner_rfcomm-tester PASS 16.41 seconds TestRunner_sco-tester PASS 19.81 seconds TestRunner_ioctl-tester PASS 18.60 seconds TestRunner_mesh-tester PASS 13.77 seconds TestRunner_smp-tester PASS 14.66 seconds TestRunner_userchan-tester PASS 11.51 seconds IncrementalBuild PASS 61.87 seconds
Details
##############################
Test: SubjectPrefix - FAIL
Desc: Check subject contains "Bluetooth" prefix
Output:
"Bluetooth: " prefix is not specified in the subject
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
---
Regards,
Linux Bluetooth
PATCH 2/2 Bluetoth: ISO: Fix broadcast event handling
In reply to Iulia TanasescuThis fixes the way broadcast events are handled by the ISO layer:
A new slave BIS hcon is notified after the Command Complete for LE Setup ISO Data Path is received, not after BIG Sync Established.
The iso_match_pa_sync_flag function has been replaced with more specific matching functions, depending on the event being handled.
--- include/net/bluetooth/hci_core.h | 3 +- net/bluetooth/hci_core.c | 50 ++++++++++----- net/bluetooth/iso.c | 101 +++++++++++++++++++++++++------ 3 files changed, 119 insertions(+), 35 deletions(-)
include/net/bluetooth/hci_core.h +2 -1
@@ -2127,7 +2127,8 @@ void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);void hci_send_iso (struct hci_conn *conn,struct sk_buff *skb);void *hci_sent_cmd_data (struct hci_dev *hdev,__u16 opcode); -void *hci_recv_event_data (struct hci_dev *hdev,__u8 event); +void *hci_le_meta_evt_data (struct hci_dev *hdev,__u8 subevent); +void *hci_cmd_complete_data (struct hci_dev *hdev,__u16 opcode);u32 hci_conn_get_phy (struct hci_conn *conn);
net/bluetooth/hci_core.c +36 -14
67 lines not on this page · raw message
net/bluetooth/iso.c +81 -20
162 lines not on this page · raw message
Signature · 1 line
2.39.2
Luiz Augusto von Dentz
maintainerRe: [PATCH 2/2] Bluetoth: ISO: Fix broadcast event handling
Hi Iulia,
Quoted 215 lines · Iulia Tanasescu
This fixes the way broadcast events are handled by the ISO layer:
A new slave BIS hcon is notified after the Command Complete for LE Setup ISO Data Path is received, not after BIG Sync Established.The
iso_match_pa_sync_flagfunction has been replaced with more specific matching functions, depending on the event being handled.Signed-off-by Iulia Tanasescu <[email protected]>--- include/net/bluetooth/hci_core.h | 3 +- net/bluetooth/hci_core.c | 50 ++++++++++----- net/bluetooth/iso.c | 101 +++++++++++++++++++++++++------ 3 files changed, 119 insertions(+), 35 deletions(-)include/net/bluetooth/hci_core.h +2
-1@@ -2127,7 +2127,8 @@ void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);void hci_send_iso (struct hci_conn *conn,struct sk_buff *skb);void *hci_sent_cmd_data (struct hci_dev *hdev,__u16 opcode); -void *hci_recv_event_data (struct hci_dev *hdev,__u8 event); +void *hci_le_meta_evt_data (struct hci_dev *hdev,__u8 subevent); +void *hci_cmd_complete_data (struct hci_dev *hdev,__u16 opcode);u32 hci_conn_get_phy (struct hci_conn *conn);net/bluetooth/hci_core.c +36
-14@@ -3120,10 +3120,11 @@ void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode)return hdev->sent_cmd->data +HCI_COMMAND_HDR_SIZE ; } -/* Get data from last received event */ -void *hci_recv_event_data (struct hci_dev *hdev,__u8 event) +/* Get data from last received LE Meta event */ +void *hci_le_meta_evt_data (struct hci_dev *hdev,__u8 subevent) {struct hci_event_hdr *hdr; +struct hci_ev_le_meta *ev;int offset;if (!hdev->recv_event)@@ -3132,21 +3133,42 @@ void *hci_recv_event_data(struct hci_dev *hdev, __u8 event) hdr = (void *)hdev->recv_event->data; offset =sizeof (*hdr); -if (hdr->evt != event) { -/* In case of LE metaevent check the subevent match */ -if (hdr->evt ==HCI_EV_LE_META ) { -struct hci_ev_le_meta *ev; +if (hdr->evt !=HCI_EV_LE_META ) +return NULL ; - ev = (void *)hdev->recv_event->data + offset; - offset +=sizeof (*ev); -if (ev->subevent == event) - goto found; - } + ev = (void *)hdev->recv_event->data + offset; + offset +=sizeof (*ev); +if (ev->subevent != subevent) +return NULL ; + +bt_dev_dbg (hdev,"subevent 0x%2.2x" , subevent); + +return hdev->recv_event->data + offset; +} + +/* Get data from last received Command Complete event */ +void *hci_cmd_complete_data (struct hci_dev *hdev,__u16 opcode) +{ +struct hci_event_hdr *hdr; +struct hci_ev_cmd_complete *ev; +int offset; + +if (!hdev->recv_event) +return NULL ; + + hdr = (void *)hdev->recv_event->data; + offset =sizeof (*hdr); + +if (hdr->evt !=HCI_EV_CMD_COMPLETE ) +return NULL ; + + ev = (void *)hdev->recv_event->data + offset; + offset +=sizeof (*ev); + +if (__le16_to_cpu (ev->opcode) != opcode)return NULL ; - } -found: -bt_dev_dbg (hdev,"event 0x%2.2x" , event); +bt_dev_dbg (hdev,"command complete event for 0x%4.4x" , opcode);return hdev->recv_event->data + offset; }net/bluetooth/iso.c +64
-14@@ -1560,6 +1560,16 @@ struct iso_list_data {int count; }; +static bool iso_match_big_flag (struct sock *sk,void *data) +{ +struct hci_evt_le_big_sync_estabilished *ev = data; + +if (!test_bit (BT_SK_PA_SYNC , &iso_pi (sk)->flags)) +return false; + +return ev->handle ==iso_pi (sk)->qos.bcast.big; +} +static bool iso_match_big (struct sock *sk,void *data) {struct hci_evt_le_big_sync_estabilished *ev = data;@@ -1567,15 +1577,28 @@ static bool iso_match_big(struct sock *sk, void *data)return ev->handle ==iso_pi (sk)->qos.bcast.big; } -static bool iso_match_pa_sync_flag (struct sock *sk,void *data) +static bool iso_match_conn_big_flag (struct sock *sk,void *data) +{ +struct hci_conn *hcon = data; + +if (!test_bit (BT_SK_PA_SYNC , &iso_pi (sk)->flags)) +return false; + +return hcon->iso_qos.bcast.big ==iso_pi (sk)->qos.bcast.big; +} + +static bool iso_match_conn_big (struct sock *sk,void *data) { -return test_bit (BT_SK_PA_SYNC , &iso_pi (sk)->flags); +struct hci_conn *hcon = data; + +return hcon->iso_qos.bcast.big ==iso_pi (sk)->qos.bcast.big; }static void iso_conn_ready (struct iso_conn *conn) {struct sock *parent =NULL ;struct sock *sk = conn->sk; +struct hci_rp_le_setup_iso_path *rp =NULL ;struct hci_ev_le_big_sync_estabilished *ev =NULL ;struct hci_ev_le_pa_sync_established *ev2 =NULL ;struct hci_evt_le_big_info_adv_report *ev3 =NULL ;@@ -1590,29 +1613,56 @@ static void iso_conn_ready(struct iso_conn *conn)if (!hcon)return ; -if (test_bit (HCI_CONN_BIG_SYNC , &hcon->flags) || -test_bit (HCI_CONN_BIG_SYNC_FAILED , &hcon->flags)) { - ev =hci_recv_event_data (hcon->hdev, -HCI_EVT_LE_BIG_SYNC_ESTABILISHED ); +if (test_bit (HCI_CONN_BIG_SYNC , &hcon->flags)) { + rp =hci_cmd_complete_data (hcon->hdev, +HCI_OP_LE_SETUP_ISO_PATH ); -/* Get reference to PA sync parent socket, if it exists */ - parent =iso_get_sock_listen (&hcon->src, - &hcon->dst, - iso_match_pa_sync_flag,NULL ); -if (!parent && ev) +if (rp) { +/* If defer setup was used to listen for this +* event, get reference to the socket marked +* with the BT_SK_PA_SYNC flag. +*/ parent =iso_get_sock_listen (&hcon->src, &hcon->dst, - iso_match_big, ev); + iso_match_conn_big_flag, + hcon); + +if (!parent) + parent =iso_get_sock_listen (&hcon->src, + &hcon->dst, + iso_match_conn_big, + hcon); + } + }else if (test_bit (HCI_CONN_BIG_SYNC_FAILED , &hcon->flags)) { + ev =hci_le_meta_evt_data (hcon->hdev, +HCI_EVT_LE_BIG_SYNC_ESTABILISHED ); + +if (ev) { +/* If defer setup was used to listen for this +* event, get reference to the socket marked +* with the BT_SK_PA_SYNC flag. +*/ + parent =iso_get_sock_listen (&hcon->src, + &hcon->dst, + iso_match_big_flag, + ev); + +if (!parent) + parent =iso_get_sock_listen (&hcon->src, + &hcon->dst, + iso_match_big, + ev); + } }else if (test_bit (HCI_CONN_PA_SYNC_FAILED , &hcon->flags)) { - ev2 =hci_recv_event_data (hcon->hdev, -HCI_EV_LE_PA_SYNC_ESTABLISHED ); + ev2 =hci_le_meta_evt_data (hcon->hdev, +HCI_EV_LE_PA_SYNC_ESTABLISHED );if (ev2) parent = iso_get_sock_listen(&hcon->src,
net/bluetooth/iso.c static void iso_conn_ready(struct iso_conn *conn) · line 1668
Quoted 10 lines
net/bluetooth/iso.c +2
-2&hcon->dst, iso_match_sid, ev2); }else if (test_bit (HCI_CONN_PA_SYNC , &hcon->flags)) { - ev3 =hci_recv_event_data (hcon->hdev, -HCI_EVT_LE_BIG_INFO_ADV_REPORT ); + ev3 =hci_le_meta_evt_data (hcon->hdev, +HCI_EVT_LE_BIG_INFO_ADV_REPORT );if (ev3) parent = iso_get_sock_listen(&hcon->src, &hcon->dst,
I really regret putting the handling of HCI in iso.c, it doesn't seem to be the right place to be processing HCI traffic and should be left to just handle socket related operations. The main problem with broadcast is that it requires multiples commands to setup but it should be possible to enclosure that into a cmd_sync function that properly serializes everything, we may need to do some cleanups first since he have been running cmd_sync callbacks in different files when that shall always be done hci_sync.c to make it simpler to reuse, then we can probably inline the sending of HCI_OP_LE_SETUP_ISO_PATH, etc, so we don't have to keep process them asynchronously via hci_event.c.
Quoted 53 lines
net/bluetooth/iso.c +15
-5@@ -1700,6 +1750,16 @@ static bool iso_match_sid(struct sock *sk, void *data)return ev->sid ==iso_pi (sk)->bc_sid; } +static bool iso_match_sync_handle_flag (struct sock *sk,void *data) +{ +struct hci_evt_le_big_info_adv_report *ev = data; + +if (!test_bit (BT_SK_PA_SYNC , &iso_pi (sk)->flags)) +return false; + +return le16_to_cpu (ev->sync_handle) ==iso_pi (sk)->sync_handle; +} +static bool iso_match_sync_handle (struct sock *sk,void *data) {struct hci_evt_le_big_info_adv_report *ev = data;@@ -1740,7 +1800,7 @@ int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)* in iso_pi(sk)->base so it can be passed up to user, in the case of a * broadcast sink. */ - ev1 =hci_recv_event_data (hdev,HCI_EV_LE_PA_SYNC_ESTABLISHED ); + ev1 =hci_le_meta_evt_data (hdev,HCI_EV_LE_PA_SYNC_ESTABLISHED );if (ev1) { sk =iso_get_sock_listen (&hdev->bdaddr, bdaddr, iso_match_sid, ev1);@@ -1750,11 +1810,12 @@ int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags) goto done; } - ev2 =hci_recv_event_data (hdev,HCI_EVT_LE_BIG_INFO_ADV_REPORT ); + ev2 =hci_le_meta_evt_data (hdev,HCI_EVT_LE_BIG_INFO_ADV_REPORT );if (ev2) {/* Try to get PA sync listening socket, if it exists */ sk =iso_get_sock_listen (&hdev->bdaddr, bdaddr, - iso_match_pa_sync_flag,NULL ); + iso_match_sync_handle_flag, + ev2);if (!sk) sk =iso_get_sock_listen (&hdev->bdaddr, bdaddr, iso_match_sync_handle, ev2);@@ -1780,7 +1841,7 @@ int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags) } } - ev3 =hci_recv_event_data (hdev,HCI_EV_LE_PER_ADV_REPORT ); + ev3 =hci_le_meta_evt_data (hdev,HCI_EV_LE_PER_ADV_REPORT );if (ev3) { sk =iso_get_sock_listen (&hdev->bdaddr, bdaddr, iso_match_sync_handle_pa_report, ev3); --2.39.2
Signature · 1 line
Luiz Augusto von Dentz
Re: [PATCH 2/2] Bluetoth: ISO: Fix broadcast event handling
Hi Luiz,
Quoted 249 lines
-----Original Message-----
From: Luiz Augusto von Dentz <[email protected]>
Sent: Wednesday, October 11, 2023 11:08 PM
To: Iulia Tanasescu <[email protected]>
Cc: [email protected]; Claudia Cristina Draghicescu <[email protected]>; Mihai-Octavian Urzica <mihai- [email protected]>; Silviu Florian Barbulescu <[email protected]>; Vlad Pruteanu <[email protected]>; Andrei Istodorescu <[email protected]>
Subject: Re: [PATCH 2/2] Bluetoth: ISO: Fix broadcast event handlingHi Iulia,
Quoted 8 lines · Iulia Tanasescu
This fixes the way broadcast events are handled by the ISO layer:
A new slave BIS hcon is notified after the Command Complete for LE Setup ISO Data Path is received, not after BIG Sync Established.The
iso_match_pa_sync_flagfunction has been replaced with more specific matching functions, depending on the event being handled.Review
Quoted 8 lines
Signed-off-by Iulia Tanasescu <[email protected]>--- include/net/bluetooth/hci_core.h | 3 +- net/bluetooth/hci_core.c | 50 ++++++++++----- net/bluetooth/iso.c | 101 +++++++++++++++++++++++++------ 3 files changed, 119 insertions(+), 35 deletions(-)(quoted diff) +0
-0
b/include/net/bluetooth/hci_core.hinclude/net/bluetooth/hci_core.h void hci_send_sco(struct hci_conn *conn, struct
Quoted 4 lines
index
99865c23e461..a85c47abd88d100644include/net/bluetooth/hci_core.h +0
-0@@ -2127,7 +2127,8 @@ void hci_send_sco(struct hci_conn *conn, struct
sk_buff*skb);net/bluetooth/hci_core.c void *hci_sent_cmd_data(struct hci_dev
Quoted 14 lines
include/net/bluetooth/hci_core.h +2
-1void hci_send_iso (struct hci_conn *conn,struct sk_buff *skb);void *hci_sent_cmd_data (struct hci_dev *hdev,__u16 opcode); -void *hci_recv_event_data (struct hci_dev *hdev,__u8 event); +void *hci_le_meta_evt_data (struct hci_dev *hdev,__u8 subevent); +void *hci_cmd_complete_data (struct hci_dev *hdev,__u16 opcode);u32 hci_conn_get_phy (struct hci_conn *conn);net/bluetooth/hci_core.c +0
-0@@ -3120,10 +3120,11 @@ void *hci_sent_cmd_data(struct hci_dev*hdev,
__u16opcode)net/bluetooth/hci_core.c void *hci_recv_event_data(struct hci_dev
Quoted 14 lines
net/bluetooth/hci_core.c +3
-2return hdev->sent_cmd->data +HCI_COMMAND_HDR_SIZE ; } -/* Get data from last received event */ -void *hci_recv_event_data (struct hci_dev *hdev,__u8 event) +/* Get data from last received LE Meta event */ +void *hci_le_meta_evt_data (struct hci_dev *hdev,__u8 subevent) {struct hci_event_hdr *hdr; +struct hci_ev_le_meta *ev;int offset;if (!hdev->recv_event)@@ -3132,21 +3133,42 @@ void *hci_recv_event_data(struct hci_dev*hdev,
__u8event)net/bluetooth/iso.c static bool iso_match_big(struct sock *sk, void
Quoted 76 lines
net/bluetooth/hci_core.c +33
-12hdr = (void *)hdev->recv_event->data; offset =sizeof (*hdr); -if (hdr->evt != event) { -/* In case of LE metaevent check the subevent match */ -if (hdr->evt ==HCI_EV_LE_META ) { -struct hci_ev_le_meta *ev; +if (hdr->evt !=HCI_EV_LE_META ) +return NULL ; - ev = (void *)hdev->recv_event->data + offset; - offset +=sizeof (*ev); -if (ev->subevent == event) - goto found; - } + ev = (void *)hdev->recv_event->data + offset; + offset +=sizeof (*ev); +if (ev->subevent != subevent) +return NULL ; + +bt_dev_dbg (hdev,"subevent 0x%2.2x" , subevent); + +return hdev->recv_event->data + offset; +} + +/* Get data from last received Command Complete event */ +void *hci_cmd_complete_data (struct hci_dev *hdev,__u16 opcode) +{ +struct hci_event_hdr *hdr; +struct hci_ev_cmd_complete *ev; +int offset; + +if (!hdev->recv_event) +return NULL ; + + hdr = (void *)hdev->recv_event->data; + offset =sizeof (*hdr); + +if (hdr->evt !=HCI_EV_CMD_COMPLETE ) +return NULL ; + + ev = (void *)hdev->recv_event->data + offset; + offset +=sizeof (*ev); + +if (__le16_to_cpu (ev->opcode) != opcode)return NULL ; - } -found: -bt_dev_dbg (hdev,"event 0x%2.2x" , event); +bt_dev_dbg (hdev,"command complete event for 0x%4.4x" , opcode);return hdev->recv_event->data + offset; }net/bluetooth/iso.c +10
-0@@ -1560,6 +1560,16 @@ struct iso_list_data {int count; }; +static bool iso_match_big_flag (struct sock *sk,void *data) +{ +struct hci_evt_le_big_sync_estabilished *ev = data; + +if (!test_bit (BT_SK_PA_SYNC , &iso_pi (sk)->flags)) +return false; + +return ev->handle ==iso_pi (sk)->qos.bcast.big; +} +static bool iso_match_big (struct sock *sk,void *data) {struct hci_evt_le_big_sync_estabilished *ev = data;@@ -1567,15 +1577,28 @@ static bool iso_match_big(struct sock *sk, void*data)
net/bluetooth/iso.c static void iso_conn_ready(struct iso_conn
Quoted 31 lines
net/bluetooth/iso.c +15
-2return ev->handle ==iso_pi (sk)->qos.bcast.big; } -static bool iso_match_pa_sync_flag (struct sock *sk,void *data) +static bool iso_match_conn_big_flag (struct sock *sk,void *data) +{ +struct hci_conn *hcon = data; + +if (!test_bit (BT_SK_PA_SYNC , &iso_pi (sk)->flags)) +return false; + +return hcon->iso_qos.bcast.big ==iso_pi (sk)->qos.bcast.big; +} + +static bool iso_match_conn_big (struct sock *sk,void *data) { -return test_bit (BT_SK_PA_SYNC , &iso_pi (sk)->flags); +struct hci_conn *hcon = data; + +return hcon->iso_qos.bcast.big ==iso_pi (sk)->qos.bcast.big; }static void iso_conn_ready (struct iso_conn *conn) {struct sock *parent =NULL ;struct sock *sk = conn->sk; +struct hci_rp_le_setup_iso_path *rp =NULL ;struct hci_ev_le_big_sync_estabilished *ev =NULL ;struct hci_ev_le_pa_sync_established *ev2 =NULL ;struct hci_evt_le_big_info_adv_report *ev3 =NULL ;@@ -1590,29 +1613,56 @@ static void iso_conn_ready(struct iso_conn*conn)
Quoted 60 lines
net/bluetooth/iso.c +39
-12if (!hcon)return ; -if (test_bit (HCI_CONN_BIG_SYNC , &hcon->flags) || -test_bit (HCI_CONN_BIG_SYNC_FAILED , &hcon->flags)) { - ev =hci_recv_event_data (hcon->hdev, -HCI_EVT_LE_BIG_SYNC_ESTABILISHED ); +if (test_bit (HCI_CONN_BIG_SYNC , &hcon->flags)) { + rp =hci_cmd_complete_data (hcon->hdev, +HCI_OP_LE_SETUP_ISO_PATH ); -/* Get reference to PA sync parent socket, if it exists */ - parent =iso_get_sock_listen (&hcon->src, - &hcon->dst, - iso_match_pa_sync_flag,NULL ); -if (!parent && ev) +if (rp) { +/* If defer setup was used to listen for this +* event, get reference to the socket marked +* with the BT_SK_PA_SYNC flag. +*/ parent =iso_get_sock_listen (&hcon->src, &hcon->dst, - iso_match_big, ev); + iso_match_conn_big_flag, + hcon); + +if (!parent) + parent =iso_get_sock_listen (&hcon->src, + &hcon->dst, + iso_match_conn_big, + hcon); + } + }else if (test_bit (HCI_CONN_BIG_SYNC_FAILED , &hcon->flags)) { + ev =hci_le_meta_evt_data (hcon->hdev, +HCI_EVT_LE_BIG_SYNC_ESTABILISHED ); + +if (ev) { +/* If defer setup was used to listen for this +* event, get reference to the socket marked +* with the BT_SK_PA_SYNC flag. +*/ + parent =iso_get_sock_listen (&hcon->src, + &hcon->dst, + iso_match_big_flag, + ev); + +if (!parent) + parent =iso_get_sock_listen (&hcon->src, + &hcon->dst, + iso_match_big, + ev); + } }else if (test_bit (HCI_CONN_PA_SYNC_FAILED , &hcon->flags)) { - ev2 =hci_recv_event_data (hcon->hdev, -HCI_EV_LE_PA_SYNC_ESTABLISHED ); + ev2 =hci_le_meta_evt_data (hcon->hdev, +HCI_EV_LE_PA_SYNC_ESTABLISHED );if (ev2) parent = iso_get_sock_listen(&hcon->src,net/bluetooth/iso.c static void iso_conn_ready(struct iso_conn *conn) · line 1668
Quoted 10 lines
net/bluetooth/iso.c +2
-2&hcon->dst, iso_match_sid, ev2); }else if (test_bit (HCI_CONN_PA_SYNC , &hcon->flags)) { - ev3 =hci_recv_event_data (hcon->hdev, -HCI_EVT_LE_BIG_INFO_ADV_REPORT ); + ev3 =hci_le_meta_evt_data (hcon->hdev, +HCI_EVT_LE_BIG_INFO_ADV_REPORT );if (ev3) parent = iso_get_sock_listen(&hcon->src, &hcon->dst,I really regret putting the handling of HCI in
iso.c, it doesn't seem to be the right place to be processing HCI traffic and should be left
Quoted 8 lines
to just handle socket related operations. The main problem with broadcast is that it requires multiples commands to setup but it should be possible to enclosure that into a
cmd_syncfunction that properly serializes everything, we may need to do some cleanups first since he have been runningcmd_synccallbacks in different files when that shall always be donehci_sync.cto make it simpler to reuse, then we can probably inline the sending ofHCI_OP_LE_SETUP_ISO_PATH, etc, so we don't have to keep process them asynchronously viahci_event.c.
In iso_conn_ready HCI events are processed just to create child socket and match with parent. Different events generate different socket types:HCI_OP_LE_SETUP_ISO_PATH creates a BIS socket, HCI_EVT_LE_BIG_INFO_ADV_REPORT creates a PA sync socket etc.
So the ISO layer needs to create new sockets and enqueue for accept depending on event. I don't think this part can be moved somewhere else, because it's related to socket handling.
The HCI state machine for setup is already enclosed in cmd_sync functions, like hci_pa_create_sync:
Quoted 63 lines
net/bluetooth/iso.c static bool iso_match_sid(struct sock *sk, void
Quoted 2 lines
net/bluetooth/iso.c +0
-0@@ -1700,6 +1750,16 @@ static bool iso_match_sid(struct sock *sk, void*data)
net/bluetooth/iso.c int iso_connect_ind(struct hci_dev *hdev,
Quoted 17 lines
net/bluetooth/iso.c +10
-0return ev->sid ==iso_pi (sk)->bc_sid; } +static bool iso_match_sync_handle_flag (struct sock *sk,void *data) +{ +struct hci_evt_le_big_info_adv_report *ev = data; + +if (!test_bit (BT_SK_PA_SYNC , &iso_pi (sk)->flags)) +return false; + +return le16_to_cpu (ev->sync_handle) ==iso_pi (sk)->sync_handle; +} +static bool iso_match_sync_handle (struct sock *sk,void *data) {struct hci_evt_le_big_info_adv_report *ev = data;@@ -1740,7 +1800,7 @@ int iso_connect_ind(struct hci_dev *hdev,
bdaddr_t*bdaddr,__u8*flags)net/bluetooth/iso.c int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)
Quoted 5 lines
net/bluetooth/iso.c +1
-1* in iso_pi(sk)->base so it can be passed up to user, in the case of a * broadcast sink. */ - ev1 =hci_recv_event_data (hdev,HCI_EV_LE_PA_SYNC_ESTABLISHED ); + ev1 = hci_le_meta_evt_data(hdev,
HCI_EV_LE_PA_SYNC_ESTABLISHED);net/bluetooth/iso.c int iso_connect_ind(struct hci_dev *hdev,
Quoted 4 lines
net/bluetooth/iso.c +0
-0if (ev1) { sk =iso_get_sock_listen (&hdev->bdaddr, bdaddr, iso_match_sid, ev1);@@ -1750,11 +1810,12 @@ int iso_connect_ind(struct hci_dev *hdev,
bdaddr_t*bdaddr,__u8*flags)net/bluetooth/iso.c int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)
Quoted 4 lines
net/bluetooth/iso.c +0
-1goto done; } - ev2 = hci_recv_event_data(hdev,
HCI_EVT_LE_BIG_INFO_ADV_REPORT);net/bluetooth/iso.c int iso_connect_ind(struct hci_dev *hdev, · line 1813
Quoted 1 line
net/bluetooth/iso.c +1
-0+ ev2 = hci_le_meta_evt_data(hdev,
HCI_EVT_LE_BIG_INFO_ADV_REPORT);net/bluetooth/iso.c int iso_connect_ind(struct hci_dev *hdev,
Quoted 10 lines
net/bluetooth/iso.c +2
-1if (ev2) {/* Try to get PA sync listening socket, if it exists */ sk =iso_get_sock_listen (&hdev->bdaddr, bdaddr, - iso_match_pa_sync_flag,NULL ); + iso_match_sync_handle_flag, + ev2);if (!sk) sk =iso_get_sock_listen (&hdev->bdaddr, bdaddr, iso_match_sync_handle, ev2);@@ -1780,7 +1841,7 @@ int iso_connect_ind(struct hci_dev *hdev,
bdaddr_t*bdaddr,__u8*flags)Quoted 11 lines
net/bluetooth/iso.c +1
-2} } - ev3 =hci_recv_event_data (hdev,HCI_EV_LE_PER_ADV_REPORT ); + ev3 =hci_le_meta_evt_data (hdev,HCI_EV_LE_PER_ADV_REPORT );if (ev3) { sk =iso_get_sock_listen (&hdev->bdaddr, bdaddr, iso_match_sync_handle_pa_report, ev3); --2.39.2
Quoted 2 lines
--
Luiz Augusto von Dentz
Regards,
Iulia
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 8 lines · On Wed, 11 Oct 2023 17:24:06 +0300 you wrote:
Currently, slave bis hcons and pa sync hcons are marked with the same flags, so they are handled the same at cleanup.
The first commit makes it so that closing all bis hcons will trigger BIG Terminate Sync, while closing all bises and the pa sync hcon will also trigger PA Terminate Sync.
[...]
Here is the summary with links:
- [1/2] Bluetooth: ISO: Fix bcast listener cleanup
https://git.kernel.org/bluetooth/bluetooth-next/c/5473a1017dd7
- [2/2] Bluetoth: ISO: Fix broadcast event handling (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html