Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4096039rdb; Mon, 11 Dec 2023 08:42:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVDYi4HjtHb7jOsufS1kbx3q8PnMLo/7znxLKMe/riJFa3xOiE9pMAQS3p0WEeewi9T9X7 X-Received: by 2002:a05:620a:26a4:b0:77f:29e5:3906 with SMTP id c36-20020a05620a26a400b0077f29e53906mr8065102qkp.52.1702312978355; Mon, 11 Dec 2023 08:42:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702312978; cv=none; d=google.com; s=arc-20160816; b=SnfCExjZLvfiUPDNeup2fbPN0S8cqplqKnZBEkMOKf1F1JQkmV+8v3eY/9gTJYFyJ/ ELlvLHuLhiOPRlfIQaZO8dncS0hZnhSh921Qfh9/F36zWMFPL3gl8MJvEloNdewD2jeA mPUP9gb9J0b2LuvmMaizmFcG6VoeGKq1QRzPkMJPm+nBIzK2igsMdcYjWImkjkS6zs1/ eZLP1MbGfWcQgJYDilAhYAfNCAB+qN1aeKQRlDYxaOfuly3m535GfLAcMzFTrWb6OR8d LZWXBeWZrjqlZGcfPWHg+wxZnnJA7MgUmUAi9ZgYL8X2PU1GI6rU1ShDp9/ipE3yZkhE Gl1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=EgMX7aJ5wP++AIAgtJNtqNEPrWFEsm33mKMW+rFekDA=; fh=V55vXmYu0kw5gQpdQ5dNb3kOR3FRKUEawX2qLN3J/TI=; b=KSyy4B2nFjiTW4u9YUFfnPYRdd6ZtzhV5hemut/D/DW986CX40pW2k95+QECOi4hk7 HaYKW3ZYyuzPGnOlOyk2ah6AntSuUvQJWn3s/uwIYrRCfI61YENPNV+iUOTa8uUaJFQ3 K/H0YxfnbjYxoSF7QnFun6WmT6b5QAhcL4nfQjfhbRnc31IOwhgpuNjQVBfb1y93Pj8+ Bqs/16+3N3yebKxuBv9bBRhhveSlqRfHfMN6xNGL1tCvpJmi7/6g/WrO2zGwc/fCPTZJ GaJERgwTaZ9Xc8gi5niRAL9GJflLNouvgCzD2lOgqMgh7TeDcLvOP4q4g58Rvm1w3V+F Htmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@126.com header.s=s110527 header.b=HlOGJ+JA; spf=pass (google.com: domain of linux-bluetooth+bounces-523-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-523-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=126.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u4-20020a05620a120400b0077d7be192f6si8314238qkj.708.2023.12.11.08.42.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 08:42:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-523-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@126.com header.s=s110527 header.b=HlOGJ+JA; spf=pass (google.com: domain of linux-bluetooth+bounces-523-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-523-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=126.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1EF9F1C213CC for ; Mon, 11 Dec 2023 16:42:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1515321A3; Mon, 11 Dec 2023 16:42:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b="HlOGJ+JA" X-Original-To: linux-bluetooth@vger.kernel.org Received: from m15.mail.126.com (m15.mail.126.com [45.254.50.223]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 29A5CC2 for ; Mon, 11 Dec 2023 08:42:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=EgMX7 aJ5wP++AIAgtJNtqNEPrWFEsm33mKMW+rFekDA=; b=HlOGJ+JA2mFqbm4MwDlUO yaNFL5LT9l246jhKHC9TkckKaS8sB7ppn3PrUxaWvIoasKtotGaxgaDLB18YFu6e JFXb+TabGyTUmp+rOOhoQR+BwNnJV8PBiTa1egtfE4p4+8yyfT6Ohzcon0Buio9c MvjbI4JbFyBa+jqp7lGK8I= Received: from localhost.localdomain (unknown [58.22.7.114]) by zwqz-smtp-mta-g1-0 (Coremail) with SMTP id _____wDnT5NyOHdllbAiDw--.21285S2; Tue, 12 Dec 2023 00:27:31 +0800 (CST) From: Xiao Yao To: linux-bluetooth@vger.kernel.org Cc: Xiao Yao Subject: [PATCH 1/2] adapter: Fix addr_type for smp_irk/ltk_info/link_key Date: Tue, 12 Dec 2023 00:27:28 +0800 Message-Id: <20231211162729.1183207-1-xiaokeqinhealth@126.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wDnT5NyOHdllbAiDw--.21285S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxZr4rGr47uryxWry5Cw4rXwb_yoW5WFykpr W3GFy3GrW8Xr1Igr43JrWY93Wavw4vkry2qr92934SkF4UXrWkZr45KrWS9rW5urykXrna qF4kXa4UWa17GrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zEJKs5UUUUU= X-CM-SenderInfo: 50ld0yhhtl0xhhdo3xa6rslhhfrp/1tbiEBZD1WVLY0IMQQAAsS From: Xiao Yao According to BLUETOOTH CORE SPECIFICATION Version 5.4 | Vol 3, Part H, 2.4.24/2.4.25, The LE LTK and BR/EDR link keys can be converted between each other, so the addr type can be either BREDR or LE, so fix it. Signed-off-by: Xiao Yao --- src/adapter.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 86fff72bc..ee70b00d2 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -170,6 +170,7 @@ static GSList *conn_fail_list = NULL; struct link_key_info { bdaddr_t bdaddr; + uint8_t bdaddr_type; unsigned char key[16]; uint8_t type; uint8_t pin_len; @@ -3964,7 +3965,9 @@ static bool is_blocked_key(uint8_t key_type, uint8_t *key_value) return false; } -static struct link_key_info *get_key_info(GKeyFile *key_file, const char *peer) +static struct link_key_info *get_key_info(GKeyFile *key_file, const char *peer, + uint8_t bdaddr_type) + { struct link_key_info *info = NULL; char *str; @@ -3976,6 +3979,7 @@ static struct link_key_info *get_key_info(GKeyFile *key_file, const char *peer) info = g_new0(struct link_key_info, 1); str2ba(peer, &info->bdaddr); + info->bdaddr_type = bdaddr_type; if (!strncmp(str, "0x", 2)) str2buf(&str[2], info->key, sizeof(info->key)); @@ -4343,7 +4347,7 @@ static void load_link_keys(struct btd_adapter *adapter, GSList *keys, struct link_key_info *info = l->data; bacpy(&key->addr.bdaddr, &info->bdaddr); - key->addr.type = BDADDR_BREDR; + key->addr.type = info->bdaddr_type; key->type = info->type; memcpy(key->val, info->key, 16); key->pin_len = info->pin_len; @@ -4598,14 +4602,18 @@ static void load_conn_params(struct btd_adapter *adapter, GSList *params) btd_error(adapter->dev_id, "Load connection parameters failed"); } -static uint8_t get_le_addr_type(GKeyFile *keyfile) +static uint8_t get_addr_type(GKeyFile *keyfile) { uint8_t addr_type; char *type; + /* The AddressType is written to file only When dev->le is + * set to true, as referenced in the update_technologies(). + * Therefore, When type is NULL, it default to BDADDR_BREDR. + */ type = g_key_file_get_string(keyfile, "General", "AddressType", NULL); if (!type) - return BDADDR_LE_PUBLIC; + return BDADDR_BREDR; if (g_str_equal(type, "public")) addr_type = BDADDR_LE_PUBLIC; @@ -4914,9 +4922,9 @@ static void load_devices(struct btd_adapter *adapter) g_clear_error(&gerr); } - key_info = get_key_info(key_file, entry->d_name); + bdaddr_type = get_addr_type(key_file); - bdaddr_type = get_le_addr_type(key_file); + key_info = get_key_info(key_file, entry->d_name, bdaddr_type); ltk_info = get_ltk_info(key_file, entry->d_name, bdaddr_type); -- 2.34.1