From patchwork Fri Mar 24 23:38:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 666672 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C868C76195 for ; Fri, 24 Mar 2023 23:39:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231922AbjCXXjB (ORCPT ); Fri, 24 Mar 2023 19:39:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231929AbjCXXjA (ORCPT ); Fri, 24 Mar 2023 19:39:00 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DEB9158AB for ; Fri, 24 Mar 2023 16:38:59 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id mp3-20020a17090b190300b0023fcc8ce113so6536937pjb.4 for ; Fri, 24 Mar 2023 16:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679701138; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=t80pHO+36rMIEHfz7QCiKbhx6ropjLKoecM2a23jtnk=; b=UCfO7MSR56AWTRTK+rh/Y/Opw49BVmDJXxNBPR6L6sAoCjS2tMcgB1hjs0seG8jorm oWnM7UzsjkoNI6imVQiFElEJkIcSLx9hCazuU6pa1J6oIQ6ssakOQEYtH3fP4PhOsip3 1QNjZ07ahTq9frP8Y+W0K8+veSwao0xF7WVIO+eG2vrQt6tXaCjz5bmURA2J1wa3RYgp WfASRDfq7oC3f9+SVY1pRrm9r//h3t2B38uuOIbttTnJ8nqVR2+hA6OlBUkWJg1Qoq7w +IH775gW6ukPL3pu3H6SL+HNRZNX6DJJoHTUwUe7cspp+dl4BKpaeCjuBprKlnUb9HSn eWoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679701138; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t80pHO+36rMIEHfz7QCiKbhx6ropjLKoecM2a23jtnk=; b=voeLm4k/oUAkcD6INy4kkLpBDsMisEdbt3BvQvRnFRF1InVoS7+KfKyYgZ78xtsP4N O+EzR4wWt1JZGwmos49k/nmadU88+AwGrTJzmL53A4JakAOAUcJgC5/mX2X5DGy/jzAt oVBrHPaMKlYyEH5aleSug8K5KOxv1xtQj/ez9psXK/6Bx2p/UBfkLFstbix7HueAoyq2 PhhBnq0pJ8q6fPU5cdpiQYX8PJqcGrHfv5gkEm7jPbw6GkR0d1B7xem2VMMK9L3ShrNv 2RItRSNRV0/nk2HxrpXRDecyku6AyCncPemS6xxwzGXLvf6jb0GAbXRVf7KQaLkV/lVH 9d5g== X-Gm-Message-State: AAQBX9fPKLs1nUYDqXcUGMggpaFGiKiO6jf57teljw6NQLceCLA1ry7n XnPbm0QTjc+U+FBO/gz2sroic5O53CQ= X-Google-Smtp-Source: AKy350Z2+/sDvSHwYbUa84jbJyZjx9I/HGzLjZCn3Q29EEQyNVJcL7BRZnn15o/eZL2EYHReSeHurw== X-Received: by 2002:a17:902:c941:b0:19c:e405:4446 with SMTP id i1-20020a170902c94100b0019ce4054446mr4385078pla.30.1679701138365; Fri, 24 Mar 2023 16:38:58 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id d18-20020a170902aa9200b001a1add0d616sm13666771plr.161.2023.03.24.16.38.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 16:38:57 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/4] shared/gatt-db: Make gatt_db_attribute_get_value public Date: Fri, 24 Mar 2023 16:38:53 -0700 Message-Id: <20230324233856.3693370-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz 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(-) diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index b696fe33da93..676f963eca94 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -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, diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h index 163a981df233..fb939e40d40e 100644 --- a/src/shared/gatt-db.h +++ b/src/shared/gatt-db.h @@ -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); From patchwork Fri Mar 24 23:38:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 667015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CED1C77B60 for ; Fri, 24 Mar 2023 23:39:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231966AbjCXXjD (ORCPT ); Fri, 24 Mar 2023 19:39:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231963AbjCXXjB (ORCPT ); Fri, 24 Mar 2023 19:39:01 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5F6F15176 for ; Fri, 24 Mar 2023 16:39:00 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id o11so3295137ple.1 for ; Fri, 24 Mar 2023 16:39:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679701140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=stLHl7pCDH1RyBPiBGqBzug135qk6M/LhP5L5oUD+CA=; b=B9cdJMyo5vrrxyVK1Hbr9v5ZsUFBg6wNDYHgYcN1WFoXXk3C0pRCgz/4y6On7q/Bw0 UlU87NrCJSuLVtIqnL/3l8bvbEXVv4p4X2n3JocvKJRRDBrj9ANqTDkeD0K+8Lxhj8zo oEI3mIDjsenfiUWoe/QnlrA/JCWLClSKvPIq08/mGToNgaEisG7HdTH02mJ54YQFQYGE p83/K4caPgR383dvBVVlEjaTICkND153EhfrIE+kcSC5I1kmTjXcqitKM3saNkO/FJa0 z3nSbiPqBni/y3QuZYU8aCQ9KmDeR28PTJkIGhS8SJLItgCOph/LRe3zEAf+kmLeo6xB zSyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679701140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=stLHl7pCDH1RyBPiBGqBzug135qk6M/LhP5L5oUD+CA=; b=0Q5MhV9wH9KZPBecJK2F1r52BzTjjAnHZ5zIRxcMwr7ef8wkN0LUeubh9EFKsuFm+h yt6AL2TEBbxmnezsvWosNdXthJ+4lYU7jBXKFH2klRQ8akM23PcdJvwC0t6TPSC5nHSj 57e/HC72Bd4kpeNLVIt5galyC+zb5Zt3JjERa7b41+cyaj/zsfZrx92hwoDPtYWANgud J034wdjxwAwd0Rac6KyIHXZCwHnoF4qshghqMri4JXlry+ffnPn0eUZY3o0RXXhWSrry 4cg6s1GMAgv/RtyPCubY8/pXWNQmN9z1sQc6frpf6qPRqwVEOAiu1yVbbvffzXCxj3wN 8hQg== X-Gm-Message-State: AAQBX9dF27AuGnvoObQZHxoIFj+cTa1UFniWdiXRSZA0ZuLHsveGOX5j t/zNIaA0gYlgRD2jqWt7TmCwGCvBj6w= X-Google-Smtp-Source: AKy350ZF9xr0ZknptnwYGZgVBn7fw1tY0VoPqVPuZ9HCLMbf7WpEAy/PWhAxxtYUxgQ2Wl0qIORpow== X-Received: by 2002:a17:903:6cd:b0:1a1:9787:505a with SMTP id kj13-20020a17090306cd00b001a19787505amr3763298plb.58.1679701139602; Fri, 24 Mar 2023 16:38:59 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id d18-20020a170902aa9200b001a1add0d616sm13666771plr.161.2023.03.24.16.38.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 16:38:58 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/4] monitor/att: Print value when printing descriptors Date: Fri, 24 Mar 2023 16:38:54 -0700 Message-Id: <20230324233856.3693370-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230324233856.3693370-1-luiz.dentz@gmail.com> References: <20230324233856.3693370-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz 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(+) diff --git a/monitor/att.c b/monitor/att.c index 9f329370d698..42d1afe701a1 100644 --- a/monitor/att.c +++ b/monitor/att.c @@ -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: From patchwork Fri Mar 24 23:38:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 666671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CD83C76195 for ; Fri, 24 Mar 2023 23:39:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232032AbjCXXjI (ORCPT ); Fri, 24 Mar 2023 19:39:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231928AbjCXXjD (ORCPT ); Fri, 24 Mar 2023 19:39:03 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99A7915176 for ; Fri, 24 Mar 2023 16:39:02 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id lr16-20020a17090b4b9000b0023f187954acso3109385pjb.2 for ; Fri, 24 Mar 2023 16:39:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679701141; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=FrPCOvhSTHSd3T8ChT3FS2w8tFsJgg8u3qBbteprq3k=; b=NP4n2Y4icX7rm7Unnbg9/H4sAww/9qmEf8rLhx89m7Kza/WrOZBkUofSERDwpW8026 SWyim7gOTG8GJkxX4/ONWW4xbAxMh3c3IvX9fJr9vZzCJ3Q1VpmYwWgiWZ+zp4VMm7hJ RwpfWj7npjmAxeSfB5oZkPOPnT5bzc3Iqcwgml/2CxH9s4/F5LcRMet76HyfOwGTJgVK h5cFBDUtV+yYoQQffMOKzbF2EW4K0Xk4MYtesCD9dKNazqCEhME8HTr0CVi39YuB0vUZ esjY1ZS0hJMaZ46EDhHiSDyxUBWfhmRnpYP0QHbB20bRj7XpGCWKL3NXsnCl7Lt0tbQp EYOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679701141; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FrPCOvhSTHSd3T8ChT3FS2w8tFsJgg8u3qBbteprq3k=; b=oIvlSo9Q+m/B85nn1JZOtnD0c//xSyS51iAFoysdN34N0SEjwSGIk4yM9J4eUFM17X +hRSZyCfxXYaTfv1DEgPLW9acGAva/yrURv6uPBfLir6fyapshzxFA0Ie/00JvSnZ/1e KB8xibuItf3Cmj/YtId75rw3+4ieAXlzsYM08P+Dmz1OuN/y/FB9gEDhUTADfB24KzFA q5Y/O/yeohdDlNjTHMLT7hHebonzxZo9edT17NjBLeqKovMkdz51yDJWrRdR0OgzoZBl LYR9r1yi3wBRA4wfBQhSlDu+hRU/Uq0G7+uzgpqCyDq1VdwXIa+HLX1lRmJDfkWWbZuQ uokg== X-Gm-Message-State: AAQBX9dCJD5962TEP6h2QNAlzzHlK/WF3wz0WIh4b1JBfszu7ZVdsVLU LjSGaPOyi/DJIC/+Y4MMtn6fs2ROKTA= X-Google-Smtp-Source: AKy350ZAvkVkR7G0cNIzd2QZwAHUm9fAR+uVM+29UT4xytg0FhI0HQSYW4h9kZhy0CHpqyMsbDVPnw== X-Received: by 2002:a17:902:d4c7:b0:19e:82d5:634c with SMTP id o7-20020a170902d4c700b0019e82d5634cmr4162879plg.53.1679701141573; Fri, 24 Mar 2023 16:39:01 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id d18-20020a170902aa9200b001a1add0d616sm13666771plr.161.2023.03.24.16.38.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 16:39:00 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 3/4] monitor/att: Fix not loading gatt_db for devices using RPA Date: Fri, 24 Mar 2023 16:38:55 -0700 Message-Id: <20230324233856.3693370-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230324233856.3693370-1-luiz.dentz@gmail.com> References: <20230324233856.3693370-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz 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(-) diff --git a/monitor/att.c b/monitor/att.c index 42d1afe701a1..cf440c6844c0 100644 --- a/monitor/att.c +++ b/monitor/att.c @@ -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); From patchwork Fri Mar 24 23:38:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 667014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CD2CC76196 for ; Fri, 24 Mar 2023 23:39:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232066AbjCXXjK (ORCPT ); Fri, 24 Mar 2023 19:39:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231985AbjCXXjH (ORCPT ); Fri, 24 Mar 2023 19:39:07 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17E601E1E1 for ; Fri, 24 Mar 2023 16:39:04 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id kq3so3243279plb.13 for ; Fri, 24 Mar 2023 16:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679701143; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=f+cQEHrmQWsCeZ3GOeOx+fTEZktLd6o7sz8WB+r/j/U=; b=FBfgbLRDgWfi3vly0rp0Ly++WOMz/SRgzRrLbBFgpfe3Iu2aebTmUpxd3QUBp8LXG0 yv8LxbSiGwBK8stE9v25MELGfnD6TGhEpCOS+mU+KeoR2mLBzKqBH++xZn/YM8qvuPyt KAW2MhI5qhRIUJmM5mrfxeAzJfzywkXPuZAmUQBZa0BjLI6uog8nXCwh3MJ1kp2T5elp UTlXMrrYyeMf7ATl89/QXE+LQlFmyHOxcSavr+iQkZaxvx+8eQWMxuQlkjs4E1ZZH4LO mOvr8j/uDWdmvkX+q0w+C3r4qxw8sRJ9yeP+Ku/F3cBQxH6iDL5CC8cbWh2I0RXeeMop ErfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679701143; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f+cQEHrmQWsCeZ3GOeOx+fTEZktLd6o7sz8WB+r/j/U=; b=PMWCS92L+TQxKLovvbZT35+RvYvq3igtr139U8ZCmfZjERsJbZhorzF82UwtpzJO79 36gcbW8xO2lBeiB0tD83DSwOH4vrOClaqcJcqMWf0rDI0p84VYGZt79ICur0GVKzEzPI 40PBrbAJwObi/uRx7yT7q7CIDBp1x5WSt+fikuCA9obeYB9L38dIt6348lwJzbhBrQBO l87Qnv8BE2/J3TU2/IDL74wdBYaamUDKEUrZl5WL/yJ5zgqVuSsAr4ACxVvv36BE7zwI 0Md90yk0xrw8xKvuce35EQ/j3V5aXsufXJWfQivVs9pxUITJjmTUaMNSh9uFFZM5DI83 0Tuw== X-Gm-Message-State: AAQBX9dsKAtLVV3V155LdQ0CESOhSnMbDlE8TkjmCkH4j8dKY9sc/IIA EZpCm9pC/8eu86GmKJm/KRDMRGeAzzo= X-Google-Smtp-Source: AKy350Z45oym3W04DAkMZsITUAAgbLFHV03KJ8DsPYWSq65Qx/a8xFHihYhQmBo1lki6bOFRnHi0ag== X-Received: by 2002:a17:903:2291:b0:1a0:549d:3996 with SMTP id b17-20020a170903229100b001a0549d3996mr4538353plh.25.1679701143056; Fri, 24 Mar 2023 16:39:03 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id d18-20020a170902aa9200b001a1add0d616sm13666771plr.161.2023.03.24.16.39.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 16:39:02 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 4/4] monitor: Cache IRK being parsed Date: Fri, 24 Mar 2023 16:38:56 -0700 Message-Id: <20230324233856.3693370-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230324233856.3693370-1-luiz.dentz@gmail.com> References: <20230324233856.3693370-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz 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(+) diff --git a/monitor/keys.c b/monitor/keys.c index d2fa3b23ffec..c1eebae82ac2 100644 --- a/monitor/keys.c +++ b/monitor/keys.c @@ -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; +} diff --git a/monitor/keys.h b/monitor/keys.h index e40c90fa9c72..f44d33295269 100644 --- a/monitor/keys.h +++ b/monitor/keys.h @@ -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]); diff --git a/monitor/packet.c b/monitor/packet.c index d9e8abf41fed..c6ff16eda9cf 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -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)