shared/gatt-db: Make gatt_db_attribute_get_value public
Luiz Augusto von Dentz
maintainerPATCH 1/4 shared/gatt-db: Make gatt_db_attribute_get_value public
From: Luiz Augusto von Dentz <[email protected]>
This makes gatt_db_attribute_get_value public so it can be used by the likes of btmon.
--- src/shared/gatt-db.c | 12 ++++++------ src/shared/gatt-db.h | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-)
src/shared/gatt-db.c +6 -6
@@ -1549,7 +1549,7 @@ static int gatt_db_attribute_get_index(const struct gatt_db_attribute *attrib)return -1 ; } -static struct gatt_db_attribute * +struct gatt_db_attribute *gatt_db_attribute_get_value (struct gatt_db_attribute *attrib) {struct gatt_db_service *service;
@@ -1559,18 +1559,18 @@ gatt_db_attribute_get_value(struct gatt_db_attribute *attrib)return NULL ; index =gatt_db_attribute_get_index (attrib); -if (index <0 ) +if (index <=0 )return NULL ; service = attrib->service;if (!bt_uuid_cmp (&characteristic_uuid, &attrib->uuid)) - index++; -else if (bt_uuid_cmp (&characteristic_uuid, +return service->attributes[index +1 ]; +else if (!bt_uuid_cmp (&characteristic_uuid, &service->attributes[index -1 ]->uuid)) -return NULL ; +return service->attributes[index]; -return service->attributes[index]; +return gatt_db_attribute_get_value (service->attributes[index -1 ]); } void gatt_db_service_foreach_desc(struct gatt_db_attribute *attrib,
src/shared/gatt-db.h +2 -0
@@ -284,6 +284,8 @@ bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset,bool gatt_db_attribute_write_result (struct gatt_db_attribute *attrib,unsigned int id,int err); +struct gatt_db_attribute * +gatt_db_attribute_get_value (struct gatt_db_attribute *attrib);struct gatt_db_attribute *gatt_db_attribute_get_ccc (struct gatt_db_attribute *attrib);
Signature · 1 line
2.39.2
Luiz Augusto von Dentz
maintainerPATCH 2/4 monitor/att: Print value when printing descriptors
From: Luiz Augusto von Dentz <[email protected]>
This prints the value attribute information when print attribute descriptors:
< ACL Data TX: Handle 3585 flags 0x00 dlen 9
ATT: Write Request (0x12) len 4
Handle: 0x002c Type: Client Characteristic Configuration (0x2902)
Value Handle: 0x002b Type: Battery Level (0x2a19)
Data: 0100
Notification (0x01)
---
monitor/att.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)monitor/att.c +52 -0
@@ -122,6 +122,56 @@ static struct att_read *att_get_read(const struct l2cap_frame *frame)return queue_remove_if (data->reads, match_read_frame, (void *)frame); } +static void print_value (struct gatt_db_attribute *attr) +{ +uint16_t handle; +struct gatt_db_attribute *val; +const bt_uuid_t *uuid; +bt_uuid_t chrc = { + .type =BT_UUID16 , + .value.u16 =0x2803 , + }; +char label[27 ]; + + uuid =gatt_db_attribute_get_type (attr); +if (!uuid) +return ; + +/* Skip in case of characteristic declaration since it already prints +* the value handle and properties. +*/ +if (!bt_uuid_cmp (uuid, &chrc)) +return ; + + val =gatt_db_attribute_get_value (attr); +if (!val || val == attr) +return ; + + uuid =gatt_db_attribute_get_type (val); +if (!uuid) +return ; + + handle =gatt_db_attribute_get_handle (val); +if (!handle) +return ; + +switch (uuid->type) { +case BT_UUID16 : +sprintf (label,"Value Handle: 0x%4.4x Type" , handle); +print_field ("%s: %s (0x%4.4x)" , label, +bt_uuid16_to_str (uuid->value.u16), + uuid->value.u16); +return ; +case BT_UUID128 : +sprintf (label,"Value Handle: 0x%4.4x Type" , handle); +print_uuid (label, &uuid->value.u128,16 ); +return ; +case BT_UUID_UNSPEC : +case BT_UUID32 : +break ; + } +} +static void print_attribute (struct gatt_db_attribute *attr) {uint16_t handle;
@@ -142,10 +192,12 @@ static void print_attribute(struct gatt_db_attribute *attr)print_field ("%s: %s (0x%4.4x)" , label,bt_uuid16_to_str (uuid->value.u16), uuid->value.u16); +print_value (attr);return ;case BT_UUID128 :sprintf (label,"Handle: 0x%4.4x Type" , handle);print_uuid (label, &uuid->value.u128,16 ); +print_value (attr);return ;case BT_UUID_UNSPEC :case BT_UUID32 :
Signature · 1 line
2.39.2
Luiz Augusto von Dentz
maintainerPATCH 3/4 monitor/att: Fix not loading gatt_db for devices using RPA
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Device using RPA have its storage using its identity address so this uses keys_resolve_identity to attempt to resolve the destination address instead of always using the connection address.
--- monitor/att.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
monitor/att.c +7 -1
@@ -42,6 +42,7 @@#include "display.h" #include "l2cap.h" #include "att.h" +#include "keys.h" struct att_read {struct gatt_db_attribute *attr;
@@ -2885,9 +2886,14 @@ static void load_gatt_db(struct packet_conn_data *conn)char filename[PATH_MAX ];char local[18 ];char peer[18 ]; +uint8_t id[6 ], id_type;ba2str ((bdaddr_t *)conn->src, local); -ba2str ((bdaddr_t *)conn->dst, peer); + +if (keys_resolve_identity (conn->dst, id, &id_type)) +ba2str ((bdaddr_t *)id, peer); +else +ba2str ((bdaddr_t *)conn->dst, peer);create_filename (filename,PATH_MAX ,"/%s/attributes" , local);gatt_load_db (data->ldb, filename, &data->ldb_mtim);
Signature · 1 line
2.39.2
Luiz Augusto von Dentz
maintainerPATCH 4/4 monitor: Cache IRK being parsed
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This caches any IRK being parsed so they can be used to resolve addresses later which fixes the problem of only being able to resolve addresses if the monitor happens to be active while SMP exchange the keys.
--- monitor/keys.c | 26 ++++++++++++++++++++++++++ monitor/keys.h | 2 ++ monitor/packet.c | 1 + 3 files changed, 29 insertions(+)
monitor/keys.c +26 -0
@@ -112,3 +112,29 @@ bool keys_resolve_identity(const uint8_t addr[6], uint8_t ident[6],return false; } + +static bool match_key (const void *data,const void *match_data) +{ +const struct irk_data *irk = data; +const uint8_t *key = match_data; + +return !memcmp (irk->key, key,16 ); +} + +bool keys_add_identity (const uint8_t addr[6 ],uint8_t addr_type, +const uint8_t key[16 ]) +{ +struct irk_data *irk; + + irk =queue_find (irk_list, match_key, key); +if (!irk) { + irk = new0(struct irk_data, 1); +memcpy (irk->key, key,16 ); +queue_push_tail (irk_list, irk); + } + +memcpy (irk->addr, addr,6 ); + irk->addr_type = addr_type; + +return true; +}
monitor/keys.h +2 -0
@@ -20,3 +20,5 @@ void keys_update_identity_addr(const uint8_t addr[6], uint8_t addr_type);bool keys_resolve_identity (const uint8_t addr[6 ],uint8_t ident[6 ],uint8_t *ident_type); +bool keys_add_identity (const uint8_t addr[6 ],uint8_t addr_type, +const uint8_t key[16 ]);
monitor/packet.c +1 -0
@@ -12870,6 +12870,7 @@ static void mgmt_print_identity_resolving_key(const void *data)mgmt_print_address (data, address_type);print_hex_field ("Key" , data +7 ,16 ); +keys_add_identity (data, address_type, data +7 ); }static void mgmt_print_signature_resolving_key (const void *data)
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=733736
---Test result---
Test Summary:
CheckPatch PASS 2.00 seconds GitLint PASS 1.35 seconds BuildEll PASS 26.61 seconds BluezMake PASS 775.64 seconds MakeCheck PASS 11.40 seconds MakeDistcheck PASS 150.29 seconds CheckValgrind PASS 242.80 seconds CheckSmatch WARNING 324.85 seconds bluezmakeextell PASS 98.44 seconds IncrementalBuild PASS 2446.98 seconds ScanBuild PASS 960.47 seconds
Details
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:monitor/att.c: note: in included file:monitor/display.h:82:26: warning: Variable length array is used.monitor/att.c: note: in included file:monitor/display.h:82:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/display.h:82:26: warning: Variable length array is used.monitor/packet.c:1799:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3551:52: warning: array of flexible structuresmonitor/bt.h:3539:40: warning: array of flexible structures
---
Regards,
Linux Bluetooth
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 8 lines · On Fri, 24 Mar 2023 16:38:53 -0700 you wrote:
From: Luiz Augusto von Dentz <[email protected]>
This makes
gatt_db_attribute_get_valuepublic so it can be used by the likes of btmon.--- src/shared/gatt-db.c | 12 ++++++------ src/shared/gatt-db.h | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-)
Here is the summary with links:
- [BlueZ,1/4] shared/gatt-db: Make gatt_db_attribute_get_value public
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7610b9264147 - [BlueZ,2/4] monitor/att: Print value when printing descriptors https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=cf7242815668 - [BlueZ,3/4] monitor/att: Fix not loading gatt_db for devices using RPA https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=2719bb5aaf6d - [BlueZ,4/4] monitor: Cache IRK being parsed https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=011e562a98a8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html