diff mbox series

[BlueZ,2/4] monitor: Add decoding support for BIGInfo mgmt event

Message ID 20230824102407.25883-3-iulia.tanasescu@nxp.com (mailing list archive)
State New, archived
Headers show
Series Add mgmt event for BIGInfo report | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Iulia Tanasescu Aug. 24, 2023, 10:24 a.m. UTC
This adds btmon support for decoding BIGInfo MGMT events.

---
 monitor/control.c | 25 +++++++++++++++++++++++++
 monitor/packet.c  | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

Comments

Luiz Augusto von Dentz Aug. 25, 2023, 8:05 p.m. UTC | #1
Hi Iulia,

On Fri, Aug 25, 2023 at 12:41 AM Iulia Tanasescu
<iulia.tanasescu@nxp.com> wrote:
>
> This adds btmon support for decoding BIGInfo MGMT events.
>
> ---
>  monitor/control.c | 25 +++++++++++++++++++++++++
>  monitor/packet.c  | 33 +++++++++++++++++++++++++++++++++
>  2 files changed, 58 insertions(+)
>
> diff --git a/monitor/control.c b/monitor/control.c
> index 009cf1520..b843d076f 100644
> --- a/monitor/control.c
> +++ b/monitor/control.c
> @@ -5,6 +5,7 @@
>   *
>   *  Copyright (C) 2011-2014  Intel Corporation
>   *  Copyright (C) 2002-2010  Marcel Holtmann <marcel@holtmann.org>
> + *  Copyright 2023 NXP
>   *
>   *
>   */
> @@ -788,6 +789,27 @@ static void mgmt_advertising_removed(uint16_t len, const void *buf)
>         packet_hexdump(buf, len);
>  }
>
> +static void mgmt_big_info_adv_report(uint16_t len, const void *buf)
> +{
> +       const struct mgmt_ev_le_big_info_adv_report *ev = buf;
> +       uint16_t sync_handle;
> +
> +       if (len < sizeof(*ev)) {
> +               printf("* Malformed BIGInfo advertising report control\n");
> +               return;
> +       }
> +
> +       sync_handle = le16_to_cpu(ev->sync_handle);
> +
> +       printf("@ BIGInfo Advertising Report: sync_handle 0x%4.4x num_bis %u "
> +               "encryption %u\n", sync_handle, ev->num_bis, ev->encryption);
> +
> +       buf += sizeof(*ev);
> +       len -= sizeof(*ev);
> +
> +       packet_hexdump(buf, len);
> +}
> +
>  void control_message(uint16_t opcode, const void *data, uint16_t size)
>  {
>         if (!decode_control)
> @@ -893,6 +915,9 @@ void control_message(uint16_t opcode, const void *data, uint16_t size)
>         case MGMT_EV_ADVERTISING_REMOVED:
>                 mgmt_advertising_removed(size, data);
>                 break;
> +       case MGMT_EV_LE_BIG_INFO_ADV_REPORT:
> +               mgmt_big_info_adv_report(size, data);
> +               break;
>         default:
>                 printf("* Unknown control (code %d len %d)\n", opcode, size);
>                 packet_hexdump(data, size);
> diff --git a/monitor/packet.c b/monitor/packet.c
> index 8eae8c9ea..96fc2662e 100644
> --- a/monitor/packet.c
> +++ b/monitor/packet.c
> @@ -15396,6 +15396,37 @@ static void mgmt_mesh_device_found_evt(const void *data, uint16_t size)
>         print_hex_field("EIR Data", eir_data, size);
>  }
>
> +static void mgmt_big_info_adv_report(const void *data, uint16_t size)
> +{
> +       uint16_t sync_handle = get_le16(data);
> +       uint8_t num_bis = get_u8(data + 2);
> +       uint8_t nse = get_u8(data + 3);
> +       uint16_t iso_interval = get_le16(data + 4);
> +       uint8_t bn = get_u8(data + 6);
> +       uint8_t pto = get_u8(data + 7);
> +       uint8_t irc = get_u8(data + 8);
> +       uint16_t max_pdu = get_le16(data + 9);
> +       const uint8_t *sdu_interval = data + 11;
> +       uint16_t max_sdu = get_le16(data + 14);
> +       uint8_t phy = get_u8(data + 16);
> +       uint8_t framing = get_u8(data + 17);
> +       uint8_t encryption = get_u8(data + 18);
> +
> +       print_field("Sync Handle: 0x%4.4x", sync_handle);
> +       print_field("Number BIS: %u", num_bis);
> +       print_field("NSE: %u", nse);
> +       print_slot_125("ISO Interval", iso_interval);
> +       print_field("BN: %u", bn);
> +       print_field("PTO: %u", pto);
> +       print_field("IRC: %u", irc);
> +       print_field("Maximum PDU: %u", max_pdu);
> +       print_usec_interval("SDU Interval", sdu_interval);
> +       print_field("Maximum SDU: %u", max_sdu);
> +       print_le_phy("PHY", phy);
> +       print_framing(framing);
> +       print_field("Encryption: 0x%02x", encryption);
> +}
> +
>  static void mgmt_mesh_packet_cmplt_evt(const void *data, uint16_t size)
>  {
>         uint8_t handle = get_u8(data);
> @@ -15500,6 +15531,8 @@ static const struct mgmt_data mgmt_event_table[] = {
>                         mgmt_mesh_device_found_evt, 22, false },
>         { 0x0032, "Mesh Packet Complete",
>                         mgmt_mesh_packet_cmplt_evt, 1, true },
> +       { 0x0033, "BIGInfo advertising report",
> +                       mgmt_big_info_adv_report, 19, false },

This should got to the ISO socket not via mgmt interface, that said we
may need to do some changes to how we discover the broadcast, it seems
we will need to do short lived PA sync to enumerate the BASE, so I
think we are better of having the driver register with BAA UUID,
initially this can probably be done in userspace so once it detects
the device is advertising with BCAA it will attempt to fetch the BASE
automatically and merge it into the bt_ad.

Later on we may decide to move this into the kernel as part of general
discovery procedure and then merge the discovered BASE into Device
Found event, etc, but I think it is too early to evaluate if that is a
good idea or not before exploring if the short lived PA sync would
work reliably, or if we really need a dedicated API for discovering
Broadcasters.

>         { }
>  };
>
> --
> 2.34.1
>
Iulia Tanasescu Aug. 30, 2023, 3:13 p.m. UTC | #2
Hi Luiz,

> -----Original Message-----
> From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
> Sent: Friday, August 25, 2023 11:06 PM
> To: Iulia Tanasescu <iulia.tanasescu@nxp.com>
> Cc: linux-bluetooth@vger.kernel.org; Claudia Cristina Draghicescu
> <claudia.rosu@nxp.com>; Mihai-Octavian Urzica <mihai-
> octavian.urzica@nxp.com>; Silviu Florian Barbulescu
> <silviu.barbulescu@nxp.com>; Vlad Pruteanu <vlad.pruteanu@nxp.com>;
> Andrei Istodorescu <andrei.istodorescu@nxp.com>
> Subject: Re: [PATCH BlueZ 2/4] monitor: Add decoding support for
> BIGInfo mgmt event
> 
> Hi Iulia,
> 
> On Fri, Aug 25, 2023 at 12:41 AM Iulia Tanasescu <iulia.tanasescu@nxp.com>
> wrote:
> >
> > This adds btmon support for decoding BIGInfo MGMT events.
> >
> > ---
> >  monitor/control.c | 25 +++++++++++++++++++++++++  monitor/packet.c
> |
> > 33 +++++++++++++++++++++++++++++++++
> >  2 files changed, 58 insertions(+)
> >
> > diff --git a/monitor/control.c b/monitor/control.c index
> > 009cf1520..b843d076f 100644
> > --- a/monitor/control.c
> > +++ b/monitor/control.c
> > @@ -5,6 +5,7 @@
> >   *
> >   *  Copyright (C) 2011-2014  Intel Corporation
> >   *  Copyright (C) 2002-2010  Marcel Holtmann <marcel@holtmann.org>
> > + *  Copyright 2023 NXP
> >   *
> >   *
> >   */
> > @@ -788,6 +789,27 @@ static void mgmt_advertising_removed(uint16_t
> len, const void *buf)
> >         packet_hexdump(buf, len);
> >  }
> >
> > +static void mgmt_big_info_adv_report(uint16_t len, const void *buf) {
> > +       const struct mgmt_ev_le_big_info_adv_report *ev = buf;
> > +       uint16_t sync_handle;
> > +
> > +       if (len < sizeof(*ev)) {
> > +               printf("* Malformed BIGInfo advertising report control\n");
> > +               return;
> > +       }
> > +
> > +       sync_handle = le16_to_cpu(ev->sync_handle);
> > +
> > +       printf("@ BIGInfo Advertising Report: sync_handle 0x%4.4x
> num_bis %u "
> > +               "encryption %u\n", sync_handle, ev->num_bis,
> > + ev->encryption);
> > +
> > +       buf += sizeof(*ev);
> > +       len -= sizeof(*ev);
> > +
> > +       packet_hexdump(buf, len);
> > +}
> > +
> >  void control_message(uint16_t opcode, const void *data, uint16_t
> > size)  {
> >         if (!decode_control)
> > @@ -893,6 +915,9 @@ void control_message(uint16_t opcode, const void
> *data, uint16_t size)
> >         case MGMT_EV_ADVERTISING_REMOVED:
> >                 mgmt_advertising_removed(size, data);
> >                 break;
> > +       case MGMT_EV_LE_BIG_INFO_ADV_REPORT:
> > +               mgmt_big_info_adv_report(size, data);
> > +               break;
> >         default:
> >                 printf("* Unknown control (code %d len %d)\n", opcode, size);
> >                 packet_hexdump(data, size); diff --git
> > a/monitor/packet.c b/monitor/packet.c index 8eae8c9ea..96fc2662e
> > 100644
> > --- a/monitor/packet.c
> > +++ b/monitor/packet.c
> > @@ -15396,6 +15396,37 @@ static void
> mgmt_mesh_device_found_evt(const void *data, uint16_t size)
> >         print_hex_field("EIR Data", eir_data, size);  }
> >
> > +static void mgmt_big_info_adv_report(const void *data, uint16_t size)
> > +{
> > +       uint16_t sync_handle = get_le16(data);
> > +       uint8_t num_bis = get_u8(data + 2);
> > +       uint8_t nse = get_u8(data + 3);
> > +       uint16_t iso_interval = get_le16(data + 4);
> > +       uint8_t bn = get_u8(data + 6);
> > +       uint8_t pto = get_u8(data + 7);
> > +       uint8_t irc = get_u8(data + 8);
> > +       uint16_t max_pdu = get_le16(data + 9);
> > +       const uint8_t *sdu_interval = data + 11;
> > +       uint16_t max_sdu = get_le16(data + 14);
> > +       uint8_t phy = get_u8(data + 16);
> > +       uint8_t framing = get_u8(data + 17);
> > +       uint8_t encryption = get_u8(data + 18);
> > +
> > +       print_field("Sync Handle: 0x%4.4x", sync_handle);
> > +       print_field("Number BIS: %u", num_bis);
> > +       print_field("NSE: %u", nse);
> > +       print_slot_125("ISO Interval", iso_interval);
> > +       print_field("BN: %u", bn);
> > +       print_field("PTO: %u", pto);
> > +       print_field("IRC: %u", irc);
> > +       print_field("Maximum PDU: %u", max_pdu);
> > +       print_usec_interval("SDU Interval", sdu_interval);
> > +       print_field("Maximum SDU: %u", max_sdu);
> > +       print_le_phy("PHY", phy);
> > +       print_framing(framing);
> > +       print_field("Encryption: 0x%02x", encryption); }
> > +
> >  static void mgmt_mesh_packet_cmplt_evt(const void *data, uint16_t
> > size)  {
> >         uint8_t handle = get_u8(data); @@ -15500,6 +15531,8 @@ static
> > const struct mgmt_data mgmt_event_table[] = {
> >                         mgmt_mesh_device_found_evt, 22, false },
> >         { 0x0032, "Mesh Packet Complete",
> >                         mgmt_mesh_packet_cmplt_evt, 1, true },
> > +       { 0x0033, "BIGInfo advertising report",
> > +                       mgmt_big_info_adv_report, 19, false },
> 
> This should got to the ISO socket not via mgmt interface, that said we may
> need to do some changes to how we discover the broadcast, it seems we will
> need to do short lived PA sync to enumerate the BASE, so I think we are
> better of having the driver register with BAA UUID, initially this can probably
> be done in userspace so once it detects the device is advertising with BCAA it
> will attempt to fetch the BASE automatically and merge it into the bt_ad.
> 
> Later on we may decide to move this into the kernel as part of general
> discovery procedure and then merge the discovered BASE into Device Found
> event, etc, but I think it is too early to evaluate if that is a good idea or not
> before exploring if the short lived PA sync would work reliably, or if we really
> need a dedicated API for discovering Broadcasters.
> 

I submitted a new kernel patch, which enables a broadcast sink to discover
if the PA it has synced with is associated with an encrypted BIG, by looking
at the socket QoS.

> >         { }
> >  };
> >
> > --
> > 2.34.1
> >
> 
> 
> --
> Luiz Augusto von Dentz

Regards,
Iulia
diff mbox series

Patch

diff --git a/monitor/control.c b/monitor/control.c
index 009cf1520..b843d076f 100644
--- a/monitor/control.c
+++ b/monitor/control.c
@@ -5,6 +5,7 @@ 
  *
  *  Copyright (C) 2011-2014  Intel Corporation
  *  Copyright (C) 2002-2010  Marcel Holtmann <marcel@holtmann.org>
+ *  Copyright 2023 NXP
  *
  *
  */
@@ -788,6 +789,27 @@  static void mgmt_advertising_removed(uint16_t len, const void *buf)
 	packet_hexdump(buf, len);
 }
 
+static void mgmt_big_info_adv_report(uint16_t len, const void *buf)
+{
+	const struct mgmt_ev_le_big_info_adv_report *ev = buf;
+	uint16_t sync_handle;
+
+	if (len < sizeof(*ev)) {
+		printf("* Malformed BIGInfo advertising report control\n");
+		return;
+	}
+
+	sync_handle = le16_to_cpu(ev->sync_handle);
+
+	printf("@ BIGInfo Advertising Report: sync_handle 0x%4.4x num_bis %u "
+		"encryption %u\n", sync_handle, ev->num_bis, ev->encryption);
+
+	buf += sizeof(*ev);
+	len -= sizeof(*ev);
+
+	packet_hexdump(buf, len);
+}
+
 void control_message(uint16_t opcode, const void *data, uint16_t size)
 {
 	if (!decode_control)
@@ -893,6 +915,9 @@  void control_message(uint16_t opcode, const void *data, uint16_t size)
 	case MGMT_EV_ADVERTISING_REMOVED:
 		mgmt_advertising_removed(size, data);
 		break;
+	case MGMT_EV_LE_BIG_INFO_ADV_REPORT:
+		mgmt_big_info_adv_report(size, data);
+		break;
 	default:
 		printf("* Unknown control (code %d len %d)\n", opcode, size);
 		packet_hexdump(data, size);
diff --git a/monitor/packet.c b/monitor/packet.c
index 8eae8c9ea..96fc2662e 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -15396,6 +15396,37 @@  static void mgmt_mesh_device_found_evt(const void *data, uint16_t size)
 	print_hex_field("EIR Data", eir_data, size);
 }
 
+static void mgmt_big_info_adv_report(const void *data, uint16_t size)
+{
+	uint16_t sync_handle = get_le16(data);
+	uint8_t num_bis = get_u8(data + 2);
+	uint8_t nse = get_u8(data + 3);
+	uint16_t iso_interval = get_le16(data + 4);
+	uint8_t bn = get_u8(data + 6);
+	uint8_t pto = get_u8(data + 7);
+	uint8_t irc = get_u8(data + 8);
+	uint16_t max_pdu = get_le16(data + 9);
+	const uint8_t *sdu_interval = data + 11;
+	uint16_t max_sdu = get_le16(data + 14);
+	uint8_t phy = get_u8(data + 16);
+	uint8_t framing = get_u8(data + 17);
+	uint8_t encryption = get_u8(data + 18);
+
+	print_field("Sync Handle: 0x%4.4x", sync_handle);
+	print_field("Number BIS: %u", num_bis);
+	print_field("NSE: %u", nse);
+	print_slot_125("ISO Interval", iso_interval);
+	print_field("BN: %u", bn);
+	print_field("PTO: %u", pto);
+	print_field("IRC: %u", irc);
+	print_field("Maximum PDU: %u", max_pdu);
+	print_usec_interval("SDU Interval", sdu_interval);
+	print_field("Maximum SDU: %u", max_sdu);
+	print_le_phy("PHY", phy);
+	print_framing(framing);
+	print_field("Encryption: 0x%02x", encryption);
+}
+
 static void mgmt_mesh_packet_cmplt_evt(const void *data, uint16_t size)
 {
 	uint8_t handle = get_u8(data);
@@ -15500,6 +15531,8 @@  static const struct mgmt_data mgmt_event_table[] = {
 			mgmt_mesh_device_found_evt, 22, false },
 	{ 0x0032, "Mesh Packet Complete",
 			mgmt_mesh_packet_cmplt_evt, 1, true },
+	{ 0x0033, "BIGInfo advertising report",
+			mgmt_big_info_adv_report, 19, false },
 	{ }
 };