Skip to contentSkip to conversation

settings: Add btd_settings_gatt_db_{store,load}

PATCH In review Luiz Augusto von Dentz 3 participants 9 messages May 20, 2022

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/7 settings: Add btd_settings_gatt_db_{store,load}

From: Luiz Augusto von Dentz <[email protected]>

This adds helper functions to store and load from/to file so they can get reused by the likes of gatt-database.c and btmon.

---
 Makefile.am    |   3 +-
 src/device.c   | 499 ++---------------------------------------------
 src/settings.c | 510 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/settings.h |  11 ++
 4 files changed, 534 insertions(+), 489 deletions(-)
 create mode 100644 src/settings.c
 create mode 100644 src/settings.h
Makefile.am +2 -1
index 82125c482..0074ea3ac 100644
@@ -322,7 +322,8 @@ src_bluetoothd_SOURCES = $(builtin_sources) \
 			src/dbus-common.c src/dbus-common.h \
 			src/eir.h src/eir.c \
 			src/adv_monitor.h src/adv_monitor.c \
-			src/battery.h src/battery.c
+			src/battery.h src/battery.c \
+			src/settings.h src/settings.c
 src_bluetoothd_LDADD = lib/libbluetooth-internal.la \
 			gdbus/libgdbus-internal.la \
 			src/libshared-glib.la \
src/device.c +11 -488

545 lines not on this page · raw message

src/settings.c new file +510 -0

510 lines not on this page · raw message

src/settings.h new file +11 -0
new file mode 100644
index 000000000..675f643a6
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2022  Intel Corporation.
+ *
+ */
+
+int btd_settings_gatt_db_load(struct gatt_db *db, const char *filename);
+void btd_settings_gatt_db_store(struct gatt_db *db, const char *filename);
Signature · 1 line
2.35.1
author maintainer
#1 lore raw

PATCH v2 2/7 gatt: Store local GATT database

From: Luiz Augusto von Dentz <[email protected]>

This enables storing the local (adapter) GATT database which later will be used by btmon to decode GATT handles.

---
 src/gatt-database.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
src/gatt-database.c +15 -0
index d32f616a9..cf651b5f5 100644
@@ -38,6 +38,8 @@
 #include "dbus-common.h"
 #include "profile.h"
 #include "service.h"
+#include "textfile.h"
+#include "settings.h"
 
 #define GATT_MANAGER_IFACE	"org.bluez.GattManager1"
 #define GATT_PROFILE_IFACE	"org.bluez.GattProfile1"
@@ -1528,6 +1530,17 @@ static void send_service_changed(struct btd_gatt_database *database,
 		error("Failed to notify Service Changed");
 }
 
+static void database_store(struct btd_gatt_database *database)
+{
+	char filename[PATH_MAX];
+
+	create_filename(filename, PATH_MAX, "/%s/attributes",
+				btd_adapter_get_storage_dir(database->adapter));
+	create_file(filename, 0600);
+
+	btd_settings_gatt_db_store(database->db, filename);
+}
+
 static void gatt_db_service_added(struct gatt_db_attribute *attrib,
 								void *user_data)
 {
@@ -1538,6 +1551,8 @@ static void gatt_db_service_added(struct gatt_db_attribute *attrib,
 	database_add_record(database, attrib);
 
 	send_service_changed(database, attrib);
+
+	database_store(database);
 }
 
 static bool ccc_match_service(const void *data, const void *match_data)
Signature · 1 line
2.35.1
author maintainer
#2 lore raw

PATCH v2 3/7 monitor: Move print_hex_field to display.h

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This moves print_hex_field to display.h and removes the duplicated code from packet.c and l2cap.c.

---
 monitor/display.h | 14 ++++++++++++++
 monitor/l2cap.c   | 14 --------------
 monitor/packet.c  | 14 --------------
 3 files changed, 14 insertions(+), 28 deletions(-)
monitor/display.h +14 -0
index be5739833..5a82f8e6f 100644
@@ -76,6 +76,20 @@ static inline uint64_t print_bitfield(int indent, uint64_t val,
 	return mask;
 }
 
+static inline void print_hex_field(const char *label, const uint8_t *data,
+								uint8_t len)
+{
+	char str[len * 2 + 1];
+	uint8_t i;
+
+	str[0] = '\0';
+
+	for (i = 0; i < len; i++)
+		sprintf(str + (i * 2), "%2.2x", data[i]);
+
+	print_field("%s: %s", label, str);
+}
+
 void set_default_pager_num_columns(int num_columns);
 int num_columns(void);
 
monitor/l2cap.c +0 -14
index 01825ce0a..192b6c920 100644
@@ -2123,20 +2123,6 @@ static void amp_packet(uint16_t index, bool in, uint16_t handle,
 	opcode_data->func(&frame);
 }
 
-static void print_hex_field(const char *label, const uint8_t *data,
-								uint8_t len)
-{
-	char str[len * 2 + 1];
-	uint8_t i;
-
-	str[0] = '\0';
-
-	for (i = 0; i < len; i++)
-		sprintf(str + (i * 2), "%2.2x", data[i]);
-
-	print_field("%s: %s", label, str);
-}
-
 static void print_uuid(const char *label, const void *data, uint16_t size)
 {
 	const char *str;
monitor/packet.c +0 -14
index d80735a06..2e02b3923 100644
@@ -1755,20 +1755,6 @@ static void print_key_size(uint8_t key_size)
 	print_field("Key size: %d", key_size);
 }
 
-static void print_hex_field(const char *label, const uint8_t *data,
-								uint8_t len)
-{
-	char str[len * 2 + 1];
-	uint8_t i;
-
-	str[0] = '\0';
-
-	for (i = 0; i < len; i++)
-		sprintf(str + (i * 2), "%2.2x", data[i]);
-
-	print_field("%s: %s", label, str);
-}
-
 static void print_key(const char *label, const uint8_t *link_key)
 {
 	print_hex_field(label, link_key, 16);
Signature · 1 line
2.35.1
author maintainer
#3 lore raw

PATCH v2 4/7 monitor: Move ATT decoding function into its own file

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This moves ATT decoding function from l2cap.c to att.c.

---
 Makefile.tools  |   6 +-
 monitor/att.c   | 642 ++++++++++++++++++++++++++++++++++++++++++++++++
 monitor/att.h   |  16 ++
 monitor/l2cap.c | 616 +---------------------------------------------
 monitor/l2cap.h |   5 +
 5 files changed, 669 insertions(+), 616 deletions(-)
 create mode 100644 monitor/att.c
 create mode 100644 monitor/att.h
Makefile.tools +4 -2
index b7d893248..a152dad6f 100644
@@ -48,9 +48,11 @@ monitor_btmon_SOURCES = monitor/main.c monitor/bt.h \
 				monitor/broadcom.h monitor/broadcom.c \
 				monitor/msft.h monitor/msft.c \
 				monitor/jlink.h monitor/jlink.c \
-				monitor/tty.h monitor/emulator.h
+				monitor/tty.h monitor/emulator.h \
+				monitor/att.h monitor/att.c
 monitor_btmon_LDADD = lib/libbluetooth-internal.la \
-				src/libshared-mainloop.la $(UDEV_LIBS) -ldl
+				src/libshared-mainloop.la \
+				$(GLIB_LIBS) $(UDEV_LIBS) -ldl
 
 if MANPAGES
 man_MANS += monitor/btmon.1
monitor/att.c new file +642 -0

642 lines not on this page · raw message

monitor/att.h new file +16 -0
new file mode 100644
index 000000000..07951b200
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2011-2014  Intel Corporation
+ *  Copyright (C) 2002-2010  Marcel Holtmann <[email protected]>
+ *
+ *
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+
+void att_packet(uint16_t index, bool in, uint16_t handle, uint16_t cid,
+					const void *data, uint16_t size);
monitor/l2cap.c +2 -614

634 lines not on this page · raw message

monitor/l2cap.h +5 -0
index e46042db4..951b411e0 100644
@@ -26,6 +26,11 @@ struct l2cap_frame {
 	uint16_t size;
 };
 
+void l2cap_frame_init(struct l2cap_frame *frame, uint16_t index, bool in,
+				uint16_t handle, uint8_t ident,
+				uint16_t cid, uint16_t psm,
+				const void *data, uint16_t size);
+
 static inline void l2cap_frame_pull(struct l2cap_frame *frame,
 				const struct l2cap_frame *source, uint16_t len)
 {
Signature · 1 line
2.35.1
author maintainer
#4 lore raw

PATCH v2 5/7 monitor: Cache connection information

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This caches connection information including the device addres so it can be printed alongside the handle:

Quoted 1 line

HCI Event: Disconnect Complete (0x05) plen 4

        Status: Success (0x00)
        Handle: 3585 Address: 68:79:12:XX:XX:XX (OUI 68-79-12)
        Reason: Connection Terminated By Local Host (0x16)
---
 monitor/broadcom.c |   60 ++-
 monitor/intel.c    |   79 +--
 monitor/msft.c     |    6 +-
 monitor/packet.c   | 1288 ++++++++++++++++++++++++++++----------------
 monitor/packet.h   |   12 +
 monitor/vendor.h   |    6 +-
 6 files changed, 918 insertions(+), 533 deletions(-)
monitor/broadcom.c +36 -24
index 21a86461b..72da56da2 100644
@@ -220,23 +220,24 @@ static void print_clock_setting(uint8_t clock)
 	print_field("UART clock: %s (0x%2.2x)", str, clock);
 }
 
-static void null_cmd(const void *data, uint8_t size)
+static void null_cmd(uint16_t index, const void *data, uint8_t size)
 {
 }
 
-static void status_rsp(const void *data, uint8_t size)
+static void status_rsp(uint16_t index, const void *data, uint8_t size)
 {
 	uint8_t status = get_u8(data);
 
 	print_status(status);
 }
 
-static void write_bd_addr_cmd(const void *data, uint8_t size)
+static void write_bd_addr_cmd(uint16_t index, const void *data, uint8_t size)
 {
 	packet_print_addr("Address", data, 0x00);
 }
 
-static void update_uart_baud_rate_cmd(const void *data, uint8_t size)
+static void update_uart_baud_rate_cmd(uint16_t index, const void *data,
+							uint8_t size)
 {
 	uint16_t enc_rate = get_le16(data);
 	uint32_t exp_rate = get_le32(data + 2);
@@ -249,7 +250,8 @@ static void update_uart_baud_rate_cmd(const void *data, uint8_t size)
 	print_field("Explicit baud rate: %u Mbps", exp_rate);
 }
 
-static void write_sco_pcm_int_param_cmd(const void *data, uint8_t size)
+static void write_sco_pcm_int_param_cmd(uint16_t index, const void *data,
+							uint8_t size)
 {
 	uint8_t routing = get_u8(data);
 	uint8_t rate = get_u8(data + 1);
@@ -264,7 +266,8 @@ static void write_sco_pcm_int_param_cmd(const void *data, uint8_t size)
 	print_clock_mode(clock_mode);
 }
 
-static void read_sco_pcm_int_param_rsp(const void *data, uint8_t size)
+static void read_sco_pcm_int_param_rsp(uint16_t index, const void *data,
+							uint8_t size)
 {
 	uint8_t status = get_u8(data);
 	uint8_t routing = get_u8(data + 1);
@@ -281,7 +284,8 @@ static void read_sco_pcm_int_param_rsp(const void *data, uint8_t size)
 	print_clock_mode(clock_mode);
 }
 
-static void set_sleepmode_param_cmd(const void *data, uint8_t size)
+static void set_sleepmode_param_cmd(uint16_t index, const void *data,
+							uint8_t size)
 {
 	uint8_t mode = get_u8(data);
 
@@ -290,7 +294,8 @@ static void set_sleepmode_param_cmd(const void *data, uint8_t size)
 	packet_hexdump(data + 1, size - 1);
 }
 
-static void read_sleepmode_param_rsp(const void *data, uint8_t size)
+static void read_sleepmode_param_rsp(uint16_t index, const void *data,
+							uint8_t size)
 {
 	uint8_t status = get_u8(data);
 	uint8_t mode = get_u8(data + 1);
@@ -301,7 +306,8 @@ static void read_sleepmode_param_rsp(const void *data, uint8_t size)
 	packet_hexdump(data + 2, size - 2);
 }
 
-static void enable_radio_cmd(const void *data, uint8_t size)
+static void enable_radio_cmd(uint16_t index, const void *data,
+							uint8_t size)
 {
 	uint8_t mode = get_u8(data);
 	const char *str;
@@ -321,7 +327,8 @@ static void enable_radio_cmd(const void *data, uint8_t size)
 	print_field("Mode: %s (0x%2.2x)", str, mode);
 }
 
-static void enable_usb_hid_emulation_cmd(const void *data, uint8_t size)
+static void enable_usb_hid_emulation_cmd(uint16_t index, const void *data,
+							uint8_t size)
 {
 	uint8_t enable = get_u8(data);
 	const char *str;
@@ -341,7 +348,8 @@ static void enable_usb_hid_emulation_cmd(const void *data, uint8_t size)
 	print_field("Enable: %s (0x%2.2x)", str, enable);
 }
 
-static void read_uart_clock_setting_rsp(const void *data, uint8_t size)
+static void read_uart_clock_setting_rsp(uint16_t index, const void *data,
+							uint8_t size)
 {
 	uint8_t status = get_u8(data);
 	uint8_t clock = get_u8(data + 1);
@@ -350,21 +358,22 @@ static void read_uart_clock_setting_rsp(const void *data, uint8_t size)
 	print_clock_setting(clock);
 }
 
-static void write_uart_clock_setting_cmd(const void *data, uint8_t size)
+static void write_uart_clock_setting_cmd(uint16_t index, const void *data,
+							uint8_t size)
 {
 	uint8_t clock = get_u8(data);
 
 	print_clock_setting(clock);
 }
 
-static void read_raw_rssi_cmd(const void *data, uint8_t size)
+static void read_raw_rssi_cmd(uint16_t index, const void *data, uint8_t size)
 {
 	uint16_t handle = get_le16(data);
 
 	print_handle(handle);
 }
 
-static void read_raw_rssi_rsp(const void *data, uint8_t size)
+static void read_raw_rssi_rsp(uint16_t index, const void *data, uint8_t size)
 {
 	uint8_t status = get_u8(data);
 	uint16_t handle = get_le16(data + 1);
@@ -375,7 +384,7 @@ static void read_raw_rssi_rsp(const void *data, uint8_t size)
 	print_rssi(rssi);
 }
 
-static void write_ram_cmd(const void *data, uint8_t size)
+static void write_ram_cmd(uint16_t index, const void *data, uint8_t size)
 {
 	uint32_t addr = get_le32(data);
 
@@ -384,7 +393,7 @@ static void write_ram_cmd(const void *data, uint8_t size)
 	packet_hexdump(data + 4, size - 4);
 }
 
-static void read_ram_cmd(const void *data, uint8_t size)
+static void read_ram_cmd(uint16_t index, const void *data, uint8_t size)
 {
 	uint32_t addr = get_le32(data);
 	uint8_t length = get_u8(data + 4);
@@ -393,7 +402,7 @@ static void read_ram_cmd(const void *data, uint8_t size)
 	print_field("Length: %u", length);
 }
 
-static void read_ram_rsp(const void *data, uint8_t size)
+static void read_ram_rsp(uint16_t index, const void *data, uint8_t size)
 {
 	uint8_t status = get_u8(data);
 
@@ -402,14 +411,14 @@ static void read_ram_rsp(const void *data, uint8_t size)
 	packet_hexdump(data + 1, size - 1);
 }
 
-static void launch_ram_cmd(const void *data, uint8_t size)
+static void launch_ram_cmd(uint16_t index, const void *data, uint8_t size)
 {
 	uint32_t addr = get_le32(data);
 
 	print_field("Address: 0x%8.8x", addr);
 }
 
-static void read_vid_pid_rsp(const void *data, uint8_t size)
+static void read_vid_pid_rsp(uint16_t index, const void *data, uint8_t size)
 {
 	uint8_t status = get_u8(data);
 	uint16_t vid = get_le16(data + 1);
@@ -419,7 +428,8 @@ static void read_vid_pid_rsp(const void *data, uint8_t size)
 	print_field("Product: %4.4x:%4.4x", vid, pid);
 }
 
-static void write_high_priority_connection_cmd(const void *data, uint8_t size)
+static void write_high_priority_connection_cmd(uint16_t index, const void *data,
+							uint8_t size)
 {
 	uint16_t handle = get_le16(data);
 	uint8_t priority = get_u8(data + 2);
@@ -480,7 +490,8 @@ static void print_features(const uint8_t *features_array)
 						"(0x%16.16" PRIx64 ")", mask);
 }
 
-static void read_controller_features_rsp(const void *data, uint8_t size)
+static void read_controller_features_rsp(uint16_t index, const void *data,
+							uint8_t size)
 {
 	uint8_t status = get_u8(data);
 
@@ -488,7 +499,8 @@ static void read_controller_features_rsp(const void *data, uint8_t size)
 	print_features(data + 1);
 }
 
-static void read_verbose_version_info_rsp(const void *data, uint8_t size)
+static void read_verbose_version_info_rsp(uint16_t index, const void *data,
+							uint8_t size)
 {
 	uint8_t status = get_u8(data);
 	uint8_t chip_id = get_u8(data + 1);
@@ -517,7 +529,7 @@ static void read_verbose_version_info_rsp(const void *data, uint8_t size)
 	print_field("Build number: %u (0x%4.4x)", build_num, build_num);
 }
 
-static void enable_wbs_cmd(const void *data, uint8_t size)
+static void enable_wbs_cmd(uint16_t index, const void *data, uint8_t size)
 {
 	uint8_t mode = get_u8(data);
 	uint16_t codec = get_le16(data + 1);
@@ -694,7 +706,7 @@ void broadcom_lm_diag(const void *data, uint8_t size)
 	}
 }
 
-static void lm_diag_evt(const void *data, uint8_t size)
+static void lm_diag_evt(uint16_t index, const void *data, uint8_t size)
 {
 	broadcom_lm_diag(data, 63);
 }
monitor/intel.c +45 -34

275 lines not on this page · raw message

monitor/msft.c +3 -3
index 6de03f3f5..38af6722e 100644
@@ -219,7 +219,7 @@ static const struct {
 	{ }
 };
 
-static void msft_cmd(const void *data, uint8_t size)
+static void msft_cmd(uint16_t index, const void *data, uint8_t size)
 {
 	uint8_t code = get_u8(data);
 	const char *code_color, *code_str = NULL;
@@ -253,7 +253,7 @@ static void msft_cmd(const void *data, uint8_t size)
 		packet_hexdump(data + 1, size - 1);
 }
 
-static void msft_rsp(const void *data, uint8_t size)
+static void msft_rsp(uint16_t index, const void *data, uint8_t size)
 {
 	uint8_t status = get_u8(data);
 	uint8_t code = get_u8(data + 1);
@@ -299,7 +299,7 @@ const struct vendor_ocf *msft_vendor_ocf(void)
 	return &vendor_ocf_entry;
 }
 
-static void msft_evt(const void *data, uint8_t size)
+static void msft_evt(uint16_t index, const void *data, uint8_t size)
 {
 	packet_hexdump(data, size);
 }
monitor/packet.c +819 -469

2,502 lines not on this page · raw message

monitor/packet.h +12 -0
index 8a11bc714..a00975eb3 100644

Lines of this file are not shown. View the raw message.

monitor/vendor.h +3 -3
index c70552b66..9430f3736 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.35.1

Part of the diff is not shown here. View the raw message.

author maintainer
#5 lore raw

PATCH v2 6/7 monitor/att: Decode attribute type

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This attempt to decode the attribute type if its gatt_db can be loaded:

< ACL Data TX: Handle 3585 flags 0x00 dlen 9

      ATT: Write Request (0x12) len 4
        Handle: 0x000b Type: Client Characteristic Configuration (0x2902)
          Data: 0200
---
 Makefile.tools   |   5 +-
 monitor/att.c    | 145 +++++++++++++++++++++++++++++++++++++++++++----
 monitor/packet.c |   2 +-
 3 files changed, 138 insertions(+), 14 deletions(-)
Makefile.tools +4 -1
index a152dad6f..4b513366f 100644
@@ -49,7 +49,10 @@ monitor_btmon_SOURCES = monitor/main.c monitor/bt.h \
 				monitor/msft.h monitor/msft.c \
 				monitor/jlink.h monitor/jlink.c \
 				monitor/tty.h monitor/emulator.h \
-				monitor/att.h monitor/att.c
+				monitor/att.h monitor/att.c \
+				src/log.h src/log.c \
+				src/textfile.h src/textfile.c \
+				src/settings.h src/settings.c
 monitor_btmon_LDADD = lib/libbluetooth-internal.la \
 				src/libshared-mainloop.la \
 				$(GLIB_LIBS) $(UDEV_LIBS) -ldl
monitor/att.c +133 -12

225 lines not on this page · raw message

monitor/packet.c +1 -1
index 8608cf2ef..e854c1a8e 100644
@@ -765,7 +765,7 @@ static void print_handle_native(uint16_t handle)
 	}
 
 	sprintf(label, "Handle: %d Address", handle);
-	print_addr("  Address", conn->dst, conn->dst_type);
+	print_addr(label, conn->dst, conn->dst_type);
 }
 
 static void print_handle(uint16_t handle)
Signature · 1 line
2.35.1
author maintainer
#6 lore raw

PATCH v2 7/7 monitor/att: Add decoding support for CCC

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This adds decoding support for CCC so its value can be decoded:

< ACL Data TX: Handle 3585 flags 0x00 dlen 7

      ATT: Read Request (0x0a) len 2
        Handle: 0x002c Type: Client Characteristic Configuration (0x2902)
Quoted 1 line

ACL Data RX: Handle 3585 flags 0x02 dlen 6

      ATT: Read Response (0x0b) len 1
        Value: 01
            Notification (0x01)
< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Write Request (0x12) len 4
        Handle: 0x002c Type: Client Characteristic Configuration (0x2902)
          Data: 0100
            Notification (0x01)
---
 monitor/att.c | 241 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 223 insertions(+), 18 deletions(-)
monitor/att.c +223 -18
index 304c37319..f1af420ba 100644
@@ -215,6 +215,82 @@ static void att_error_response(const struct l2cap_frame *frame)
 	print_field("Error: %s (0x%2.2x)", str, pdu->error);
 }
 
+static const struct bitfield_data ccc_value_table[] = {
+	{  0, "Notification (0x01)"		},
+	{  1, "Indication (0x02)"		},
+	{ }
+};
+
+static void print_ccc_value(uint8_t value)
+{
+	uint8_t mask = value;
+
+	mask = print_bitfield(4, value, ccc_value_table);
+	if (mask)
+		print_text(COLOR_WHITE_BG, "    Unknown fields (0x%2.2x)",
+								mask);
+}
+
+static void gatt_ccc_read(const struct l2cap_frame *frame)
+{
+	uint8_t value;
+
+	if (!l2cap_frame_get_u8((void *)frame, &value)) {
+		print_text(COLOR_ERROR, "invalid size");
+		return;
+	}
+
+	print_ccc_value(value);
+}
+
+static void gatt_ccc_write(const struct l2cap_frame *frame)
+{
+	uint8_t value;
+
+	if (!l2cap_frame_get_u8((void *)frame, &value)) {
+		print_text(COLOR_ERROR, "invalid size");
+		return;
+	}
+
+	print_ccc_value(value);
+}
+
+#define GATT_HANDLER(_uuid, _read, _write, _notify) \
+{ \
+	.uuid = { \
+		.type = BT_UUID16, \
+		.value.u16 = _uuid, \
+	}, \
+	.read = _read, \
+	.write = _write, \
+	.notify = _notify \
+}
+
+struct gatt_handler {
+	bt_uuid_t uuid;
+	void (*read)(const struct l2cap_frame *frame);
+	void (*write)(const struct l2cap_frame *frame);
+	void (*notify)(const struct l2cap_frame *frame);
+} gatt_handlers[] = {
+	GATT_HANDLER(GATT_CLIENT_CHARAC_CFG_UUID, gatt_ccc_read,
+					gatt_ccc_write, NULL)
+};
+
+static struct gatt_handler *get_handler(struct gatt_db_attribute *attr)
+{
+	const bt_uuid_t *uuid = gatt_db_attribute_get_type(attr);
+	size_t i;
+
+	for (i = 0; i < ARRAY_SIZE(gatt_handlers); i++) {
+		struct gatt_handler *handler = &gatt_handlers[i];
+
+		if (!bt_uuid_cmp(&handler->uuid, uuid))
+			return handler;
+	}
+
+	return NULL;
+}
+
 static void att_exchange_mtu_req(const struct l2cap_frame *frame)
 {
 	const struct bt_l2cap_att_exchange_mtu_req *pdu = frame->data;
@@ -326,9 +402,16 @@ static void att_read_type_rsp(const struct l2cap_frame *frame)
 					frame->data + 1, frame->size - 1);
 }
 
+struct att_read {
+	struct gatt_db_attribute *attr;
+	uint16_t cid;
+	void (*func)(const struct l2cap_frame *frame);
+};
+
 struct att_conn_data {
 	struct gatt_db *ldb;
 	struct gatt_db *rdb;
+	struct queue *reads;
 };
 
 static void att_conn_data_free(void *data)
@@ -337,6 +420,7 @@ static void att_conn_data_free(void *data)
 
 	gatt_db_unref(att_data->rdb);
 	gatt_db_unref(att_data->ldb);
+	queue_destroy(att_data->reads, free);
 	free(att_data);
 }
 
@@ -441,13 +525,67 @@ done:
 static void att_read_req(const struct l2cap_frame *frame)
 {
 	const struct bt_l2cap_att_read_req *pdu = frame->data;
+	uint16_t handle;
+	struct packet_conn_data *conn;
+	struct att_conn_data *data;
+	struct att_read *read;
+	struct gatt_db_attribute *attr;
+	struct gatt_handler *handler;
 
-	print_handle(frame, le16_to_cpu(pdu->handle), false);
+	l2cap_frame_pull((void *)frame, frame, sizeof(*pdu));
+
+	handle = le16_to_cpu(pdu->handle);
+	print_handle(frame, handle, false);
+
+	attr = get_attribute(frame, handle, false);
+	if (!attr)
+		return;
+
+	handler = get_handler(attr);
+	if (!handler)
+		return;
+
+	conn = packet_get_conn_data(frame->handle);
+	data = conn->data;
+
+	if (!data->reads)
+		data->reads = queue_new();
+
+	read = new0(struct att_read, 1);
+	read->attr = attr;
+	read->cid = frame->cid;
+	read->func = handler->read;
+
+	queue_push_tail(data->reads, read);
+}
+
+static bool match_read_frame(const void *data, const void *match_data)
+{
+	const struct att_read *read = data;
+	const struct l2cap_frame *frame = match_data;
+
+	return read->cid == frame->cid;
 }
 
 static void att_read_rsp(const struct l2cap_frame *frame)
 {
+	struct packet_conn_data *conn;
+	struct att_conn_data *data;
+	struct att_read *read;
+
 	print_hex_field("Value", frame->data, frame->size);
+
+	conn = packet_get_conn_data(frame->handle);
+	if (!conn)
+		return;
+
+	data = conn->data;
+
+	read = queue_find(data->reads, match_read_frame, frame);
+	if (!read)
+		return;
+
+	read->func(frame);
 }
 
 static void att_read_blob_req(const struct l2cap_frame *frame)
@@ -509,10 +647,41 @@ static void att_read_group_type_rsp(const struct l2cap_frame *frame)
 					frame->data + 1, frame->size - 1);
 }
 
+static void print_write(const struct l2cap_frame *frame, uint16_t handle,
+							size_t len)
+{
+	struct gatt_db_attribute *attr;
+	struct gatt_handler *handler;
+
+	print_handle(frame, handle, false);
+	print_hex_field("  Data", frame->data, frame->size);
+
+	if (len > frame->size) {
+		print_text(COLOR_ERROR, "invalid size");
+		return;
+	}
+
+	attr = get_attribute(frame, handle, false);
+	if (!attr)
+		return;
+
+	handler = get_handler(attr);
+	if (!handler)
+		return;
+
+	handler->write(frame);
+}
+
 static void att_write_req(const struct l2cap_frame *frame)
 {
-	print_handle(frame, get_le16(frame->data), false);
-	print_hex_field("  Data", frame->data + 2, frame->size - 2);
+	uint16_t handle;
+
+	if (!l2cap_frame_get_le16((void *)frame, &handle)) {
+		print_text(COLOR_ERROR, "invalid size");
+		return;
+	}
+
+	print_write(frame, handle, frame->size);
 }
 
 static void att_write_rsp(const struct l2cap_frame *frame)
@@ -553,20 +722,49 @@ static void att_execute_write_req(const struct l2cap_frame *frame)
 	print_field("Flags: %s (0x%02x)", flags_str, flags);
 }
 
+static void print_notify(const struct l2cap_frame *frame, uint16_t handle,
+								size_t len)
+{
+	struct gatt_db_attribute *attr;
+	struct gatt_handler *handler;
+
+	print_handle(frame, handle, true);
+	print_hex_field("  Data", frame->data, len);
+
+	if (len > frame->size) {
+		print_text(COLOR_ERROR, "invalid size");
+		return;
+	}
+
+	attr = get_attribute(frame, handle, true);
+	if (!attr)
+		return;
+
+	handler = get_handler(attr);
+	if (!handler)
+		return;
+
+	handler->notify(frame);
+}
+
 static void att_handle_value_notify(const struct l2cap_frame *frame)
 {
+	uint16_t handle;
 	const struct bt_l2cap_att_handle_value_notify *pdu = frame->data;
 
-	print_handle(frame, le16_to_cpu(pdu->handle), true);
-	print_hex_field("  Data", frame->data + 2, frame->size - 2);
+	l2cap_frame_pull((void *)frame, frame, sizeof(*pdu));
+
+	handle = le16_to_cpu(pdu->handle);
+	print_notify(frame, handle, frame->size);
 }
 
 static void att_handle_value_ind(const struct l2cap_frame *frame)
 {
 	const struct bt_l2cap_att_handle_value_ind *pdu = frame->data;
 
-	print_handle(frame, le16_to_cpu(pdu->handle), true);
-	print_hex_field("  Data", frame->data + 2, frame->size - 2);
+	l2cap_frame_pull((void *)frame, frame, sizeof(*pdu));
+
+	print_notify(frame, le16_to_cpu(pdu->handle), frame->size);
 }
 
 static void att_handle_value_conf(const struct l2cap_frame *frame)
@@ -591,13 +789,7 @@ static void att_multiple_vl_rsp(const struct l2cap_frame *frame)
 
 		print_field("Length: 0x%4.4x", len);
 
-		print_hex_field("  Data", f->data,
-				len < f->size ? len : f->size);
-
-		if (len > f->size) {
-			print_text(COLOR_ERROR, "invalid size");
-			return;
-		}
+		print_notify(frame, handle, len);
 
 		l2cap_frame_pull(f, f, len);
 	}
@@ -605,14 +797,27 @@ static void att_multiple_vl_rsp(const struct l2cap_frame *frame)
 
 static void att_write_command(const struct l2cap_frame *frame)
 {
-	print_handle(frame, get_le16(frame->data), false);
-	print_hex_field("  Data", frame->data + 2, frame->size - 2);
+	uint16_t handle;
+
+	if (!l2cap_frame_get_le16((void *)frame, &handle)) {
+		print_text(COLOR_ERROR, "invalid size");
+		return;
+	}
+
+	print_write(frame, handle, frame->size);
 }
 
 static void att_signed_write_command(const struct l2cap_frame *frame)
 {
-	print_handle(frame, get_le16(frame->data), false);
-	print_hex_field("  Data", frame->data + 2, frame->size - 2 - 12);
+	uint16_t handle;
+
+	if (!l2cap_frame_get_le16((void *)frame, &handle)) {
+		print_text(COLOR_ERROR, "invalid size");
+		return;
+	}
+
+	print_write(frame, handle, frame->size - 12);
+	print_hex_field("  Data", frame->data, frame->size - 12);
 	print_hex_field("  Signature", frame->data + frame->size - 12, 12);
 }
 
Signature · 1 line
2.35.1
#7 lore raw
In reply to Luiz Augusto von Dentz

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=643418

---Test result---

Test Summary:

CheckPatch                    FAIL      14.34 seconds
GitLint                       PASS      7.50 seconds
Prep - Setup ELL              PASS      46.58 seconds
Build - Prep                  PASS      0.69 seconds
Build - Configure             PASS      9.56 seconds
Build - Make                  PASS      1349.39 seconds
Make Check                    PASS      11.92 seconds
Make Check w/Valgrind         PASS      475.43 seconds
Make Distcheck                PASS      249.97 seconds
Build w/ext ELL - Configure   PASS      9.27 seconds
Build w/ext ELL - Make        PASS      1329.54 seconds
Incremental Build with patchesPASS      9974.05 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script with rule in .checkpatch.conf Output:
[v2,4/7] monitor: Move ATT decoding function into its own file WARNING:SPACING: Unnecessary space before function pointer arguments #618: FILE: monitor/att.c:501:
+ void (*func) (const struct l2cap_frame *frame);

ERROR:SPACING: space prohibited before that ',' (ctx:WxE) #657: FILE: monitor/att.c:540:
+ { 0x12, "Write Request" ,
^

/github/workspace/src/12856291.patch total: 1 errors, 1 warnings, 1316 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/12856291.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

[v2,5/7] monitor: Cache connection information WARNING:TYPO_SPELLING: 'addres' may be misspelled - perhaps 'address'? #83:
This caches connection information including the device addres so it can

                                                        ^^^^^^

WARNING:SPACING: Unnecessary space before function pointer arguments #3959: FILE: monitor/packet.c:8833:
+ void (*cmd_func) (uint16_t index, const void *data, uint8_t size);

WARNING:SPACING: Unnecessary space before function pointer arguments #3963: FILE: monitor/packet.c:8836:
+ void (*rsp_func) (uint16_t index, const void *data, uint8_t size);

WARNING:SPACING: Unnecessary space before function pointer arguments #4944: FILE: monitor/packet.c:11433:
+ void (*func) (uint16_t index, const void *data, uint8_t size);

WARNING:SPACING: Unnecessary space before function pointer arguments #5002: FILE: monitor/packet.c:11617:
+ void (*func) (uint16_t index, const void *data, uint8_t size);

WARNING:SPACING: Unnecessary space before function pointer arguments #5056: FILE: monitor/vendor.h:17:
+ void (*cmd_func) (uint16_t index, const void *data, uint8_t size);

WARNING:SPACING: Unnecessary space before function pointer arguments #5060: FILE: monitor/vendor.h:20:
+ void (*rsp_func) (uint16_t index, const void *data, uint8_t size);

WARNING:SPACING: Unnecessary space before function pointer arguments #5069: FILE: monitor/vendor.h:28:
+ void (*evt_func) (uint16_t index, const void *data, uint8_t size);

/github/workspace/src/12856290.patch total: 0 errors, 8 warnings, 4552 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/12856290.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

---
Regards,
Linux Bluetooth

#8 lore raw
In reply to Luiz Augusto von Dentz
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 4 lines · On Thu, 19 May 2022 21:16:55 -0700 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

This adds helper functions to store and load from/to file so they can get reused by the likes of gatt-database.c and btmon.

Quoted 8 lines
---
 Makefile.am    |   3 +-
 src/device.c   | 499 ++---------------------------------------------
 src/settings.c | 510 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/settings.h |  11 ++
 4 files changed, 534 insertions(+), 489 deletions(-)
 create mode 100644 src/settings.c
 create mode 100644 src/settings.h

Here is the summary with links:
- [v2,1/7] settings: Add btd_settings_gatt_db_{store,load} (no matching commit)
- [v2,2/7] gatt: Store local GATT database

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f66673878a9f
  - [v2,3/7] monitor: Move print_hex_field to display.h
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=0247ed333ea9
  - [v2,4/7] monitor: Move ATT decoding function into its own file
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5efc737f49d4
  - [v2,5/7] monitor: Cache connection information
    (no matching commit)
  - [v2,6/7] monitor/att: Decode attribute type
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=0bd5350459c3

- [v2,7/7] monitor/att: Add decoding support for CCC (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