From patchwork Thu Jan 30 14:34:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Witowski X-Patchwork-Id: 11358141 X-Patchwork-Delegate: brian.gix@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15FB5112B for ; Thu, 30 Jan 2020 14:34:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E8563214D8 for ; Thu, 30 Jan 2020 14:34:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=silvair-com.20150623.gappssmtp.com header.i=@silvair-com.20150623.gappssmtp.com header.b="qfsf2+iZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727458AbgA3Oei (ORCPT ); Thu, 30 Jan 2020 09:34:38 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34954 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727139AbgA3Oeh (ORCPT ); Thu, 30 Jan 2020 09:34:37 -0500 Received: by mail-wm1-f65.google.com with SMTP id b17so4511342wmb.0 for ; Thu, 30 Jan 2020 06:34:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=+CcPEBgHGsNQE6ylPPKFriDFM9lo0brzFEEYjimckF4=; b=qfsf2+iZs9TnFVRJ3p52x7nh4i3haW9gjYcuBx0gPiV2r98f+NQjxOe/4BgLRBkzC2 ngB4UVwT0Op/BUu6tnuviW2xAoFirWzyp+lE2WwvtSYn6JBDhEFHsNtezSmuw5jKVKch 4SF9s+G7uBjBzPQkm5aSzqzpZDAsjMHQ1oteRmCuecOfis8twPx6O9Ulqh/YJY7Bd/p4 YK/hFdcCd0edW+z3SpTiMTfItDIFAhSXBWFEMfQJu9wsDBdLXZ6+QyWyeJ180En73x9V i1j+dwqPrUN5rUt1J7ZxDK13WwHlMOQRlW12VmlGCsKdGZ7TkEpnsUBEL9fYN+YOY6A/ 3dXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+CcPEBgHGsNQE6ylPPKFriDFM9lo0brzFEEYjimckF4=; b=IdMFaPnyjO4rJx0785FQEuyO+ms8BjREScYwLi8QONNF5tFxE9mM0JW/qcHOfXuy4/ 8jZqqvPFl0jeF8ux2ev1Csjpq/MV5LodFS7fNe5kLfQcaaTtqENM/9gf2GDavWVOjmJm OKlbgIc8VSgqfLSAzapfbv9F3xAqs0MC9U7Tjh/GNSi+ioBehMlV7TdqeDq9ueGHQLEH lU2JysPFsNxwkJWYUrWPpl9lMNbPFNMDiUuSyFAavMB2DjZZq2OEZ5N1WQgE9GMOFE5Y CAt+zF0mPFlc5+EFApho5tAkmSLlVC/a4sQl0hblq0IYavmvFqnzREdwxiizo+jryzoY Amnw== X-Gm-Message-State: APjAAAUZP8MkWmt0IDwx7kRbrxDh8FOwA+bAn4zfyieapqfQRpc9KCck n7KuDyl+dpwZZGjjbnc1Wj3+Qxtjvzom2Q== X-Google-Smtp-Source: APXvYqwOHt0EToU3AFNIbZGEvQL+Aem3wn1mhhdrMTUvjDZwkNZVfVPtREeX0G7aTlYoQmWwT7GkRQ== X-Received: by 2002:a7b:cc09:: with SMTP id f9mr6190618wmh.71.1580394872276; Thu, 30 Jan 2020 06:34:32 -0800 (PST) Received: from localhost.localdomain ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id x10sm7353310wrv.60.2020.01.30.06.34.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 06:34:31 -0800 (PST) From: Jakub Witowski To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 1/4] mesh: use static node_comp instead of the pointer Date: Thu, 30 Jan 2020 15:34:22 +0100 Message-Id: <20200130143425.5844-2-jakub.witowski@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200130143425.5844-1-jakub.witowski@silvair.com> References: <20200130143425.5844-1-jakub.witowski@silvair.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org There is no need to use the pointer to the node_comp data. This pach uses static node_comp instead. --- mesh/node.c | 56 +++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/mesh/node.c b/mesh/node.c index de6e74c4f..6fe70742d 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -90,7 +90,7 @@ struct mesh_node { uint32_t seq_number; bool provisioner; uint16_t primary; - struct node_composition *comp; + struct node_composition comp; struct { uint16_t interval; uint8_t cnt; @@ -336,7 +336,6 @@ static void free_node_resources(void *data) free_node_dbus_resources(node); mesh_net_free(node->net); - l_free(node->comp); l_free(node->storage_dir); l_free(node); } @@ -503,11 +502,10 @@ static bool init_from_storage(struct mesh_config_node *db_node, l_queue_push_tail(nodes, node); - node->comp = l_new(struct node_composition, 1); - node->comp->cid = db_node->cid; - node->comp->pid = db_node->pid; - node->comp->vid = db_node->vid; - node->comp->crpl = db_node->crpl; + node->comp.cid = db_node->cid; + node->comp.pid = db_node->pid; + node->comp.vid = db_node->vid; + node->comp.crpl = db_node->crpl; node->lpn = db_node->modes.lpn; node->proxy = db_node->modes.proxy; @@ -753,7 +751,7 @@ uint16_t node_get_crpl(struct mesh_node *node) if (!node) return 0; - return node->comp->crpl; + return node->comp.crpl; } uint8_t node_relay_mode_get(struct mesh_node *node, uint8_t *count, @@ -886,18 +884,18 @@ uint16_t node_generate_comp(struct mesh_node *node, uint8_t *buf, uint16_t sz) uint16_t num_ele = 0; const struct l_queue_entry *ele_entry; - if (!node || !node->comp || sz < MIN_COMP_SIZE) + if (!node || sz < MIN_COMP_SIZE) return 0; n = 0; - l_put_le16(node->comp->cid, buf + n); + l_put_le16(node->comp.cid, buf + n); n += 2; - l_put_le16(node->comp->pid, buf + n); + l_put_le16(node->comp.pid, buf + n); n += 2; - l_put_le16(node->comp->vid, buf + n); + l_put_le16(node->comp.vid, buf + n); n += 2; - l_put_le16(node->comp->crpl, buf + n); + l_put_le16(node->comp.crpl, buf + n); n += 2; features = 0; @@ -1198,10 +1196,10 @@ static void convert_node_to_storage(struct mesh_node *node, { const struct l_queue_entry *entry; - db_node->cid = node->comp->cid; - db_node->pid = node->comp->pid; - db_node->vid = node->comp->vid; - db_node->crpl = node->comp->crpl; + db_node->cid = node->comp.cid; + db_node->pid = node->comp.pid; + db_node->vid = node->comp.vid; + db_node->crpl = node->comp.crpl; db_node->modes.lpn = node->lpn; db_node->modes.proxy = node->proxy; @@ -1285,29 +1283,28 @@ static bool get_app_properties(struct mesh_node *node, const char *path, l_debug("path %s", path); - node->comp = l_new(struct node_composition, 1); - node->comp->crpl = mesh_get_crpl(); + node->comp.crpl = mesh_get_crpl(); while (l_dbus_message_iter_next_entry(properties, &key, &variant)) { if (!cid && !strcmp(key, "CompanyID")) { if (!l_dbus_message_iter_get_variant(&variant, "q", - &node->comp->cid)) - goto fail; + &node->comp.cid)) + return false; cid = true; continue; } if (!pid && !strcmp(key, "ProductID")) { if (!l_dbus_message_iter_get_variant(&variant, "q", - &node->comp->pid)) - goto fail; + &node->comp.pid)) + return false; pid = true; continue; } if (!vid && !strcmp(key, "VersionID")) { if (!l_dbus_message_iter_get_variant(&variant, "q", - &node->comp->vid)) + &node->comp.vid)) return false; vid = true; continue; @@ -1315,21 +1312,16 @@ static bool get_app_properties(struct mesh_node *node, const char *path, if (!strcmp(key, "CRPL")) { if (!l_dbus_message_iter_get_variant(&variant, "q", - &node->comp->crpl)) - goto fail; + &node->comp.crpl)) + return false; continue; } } if (!cid || !pid || !vid) - goto fail; + return false; return true; -fail: - l_free(node->comp); - node->comp = NULL; - - return false; } static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr, From patchwork Thu Jan 30 14:34:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Witowski X-Patchwork-Id: 11358137 X-Patchwork-Delegate: brian.gix@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4416F13A4 for ; Thu, 30 Jan 2020 14:34:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 22433214D8 for ; Thu, 30 Jan 2020 14:34:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=silvair-com.20150623.gappssmtp.com header.i=@silvair-com.20150623.gappssmtp.com header.b="tiY41Aok" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727454AbgA3Oeh (ORCPT ); Thu, 30 Jan 2020 09:34:37 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:36925 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727142AbgA3Oeg (ORCPT ); Thu, 30 Jan 2020 09:34:36 -0500 Received: by mail-wr1-f65.google.com with SMTP id w15so4322203wru.4 for ; Thu, 30 Jan 2020 06:34:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=DJ6Q57hGK1VsvuqVochs9G8UKuI8NFxmGEDJ9WKl60k=; b=tiY41AokQS+g+vYHbnd9StQRUZvWXjNza08Jy3AlCE1KJe2UTx6kZl7Ik0HQGTeSqg D073Cy/P3aRYfNcsGjYFU5fe5KOlFh0ah8OhGbRPXUz2fvWUnwnp3gALHSIbamRvWOmU NeKr9qJG+9+vFdpyt2jKWDRijAxLAc+zbEEXtVQimd+mcghPAg/egmrsc9fhEHoTyvSo jpjJRA+PR49ssX6pg6Uiw1+7xpIPihqnSMqDVJsZCwZmAULV5Nt2WxjnGqDBnQOrShFR /G/icBHU3ejgD4THo6NwHZeLcttJ9UVy5vozaVDfMGWoaqJZGDiKc88J463O5UhYo48i qXyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DJ6Q57hGK1VsvuqVochs9G8UKuI8NFxmGEDJ9WKl60k=; b=mzQN2Ltm8gH772/h6etVlMg2k7FVKIJD0bnCyeswz/LWe1y/DEVeBpA0lpK+dI5JHr AY7f6TnJHw9Z105z9LDG5S/vF63aoNUZVAXDL1KRWf5q1mgXDY2cmxE2eIBXldJQBaDL HA2DxqEUdkHKQr55hFUIKJSV6cdNDMWYOAVwC8XBbvUwflIuZz7DUl6urZqLWNY8FTi+ 9XBA5/OBqrafUl9paWQKOiS5XKem+uoE9qKxUX5UNXly1/NjdzfUe2TuQ2nTY0DtIv4P jCBJgAT0tB2yTcbRf1ZVWO4F4nxuGT1mF25zOnxHHktGh+qrssMnzJds7VrxWbNyBN2m Zu1Q== X-Gm-Message-State: APjAAAX2W7C2xP7iwtrQ+9+YhkWBwnDbVDhNFunSO34+GaA/m3TgrL2l 4eyp3hSr80DS98m8ZfdD9vfxatVSy10rMw== X-Google-Smtp-Source: APXvYqyDlgKRUMpvopsLMCkoa5oLJWAt1ACpe116BscWZn94ET4H6HHufV9Jq4VPgRSoQoWyLed4NQ== X-Received: by 2002:a5d:6551:: with SMTP id z17mr6033796wrv.269.1580394873221; Thu, 30 Jan 2020 06:34:33 -0800 (PST) Received: from localhost.localdomain ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id x10sm7353310wrv.60.2020.01.30.06.34.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 06:34:32 -0800 (PST) From: Jakub Witowski To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 2/4] mesh: add cid/pid/vid setter Date: Thu, 30 Jan 2020 15:34:23 +0100 Message-Id: <20200130143425.5844-3-jakub.witowski@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200130143425.5844-1-jakub.witowski@silvair.com> References: <20200130143425.5844-1-jakub.witowski@silvair.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch adds the setter for the CID PID and VID. --- mesh/mesh-config-json.c | 40 ++++++++++++++++++++++++++++++++-------- mesh/mesh-config.h | 2 ++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c index 5855149e3..0574c166e 100644 --- a/mesh/mesh-config-json.c +++ b/mesh/mesh-config-json.c @@ -1456,6 +1456,24 @@ static bool write_mode(json_object *jobj, const char *keyword, int value) return true; } +static bool write_comp_id(json_object *jobj, uint16_t cid, uint16_t pid, + uint16_t vid) +{ + if (!jobj) + return false; + + if (!write_uint16_hex(jobj, "cid", cid)) + return false; + + if (!write_uint16_hex(jobj, "pid", pid)) + return false; + + if (!write_uint16_hex(jobj, "vid", vid)) + return false; + + return true; +} + bool mesh_config_write_mode(struct mesh_config *cfg, const char *keyword, int value) { @@ -1595,16 +1613,10 @@ static struct mesh_config *create_config(const char *cfg_path, jnode = json_object_new_object(); - /* CID, PID, VID, crpl */ - if (!write_uint16_hex(jnode, "cid", node->cid)) - return NULL; - - if (!write_uint16_hex(jnode, "pid", node->pid)) - return NULL; - - if (!write_uint16_hex(jnode, "vid", node->vid)) + if (!write_comp_id(jnode, node->cid, node->pid, node->vid)) return NULL; + /* CRPL */ if (!write_uint16_hex(jnode, "crpl", node->crpl)) return NULL; @@ -2052,6 +2064,18 @@ bool mesh_config_write_ttl(struct mesh_config *cfg, uint8_t ttl) return save_config(cfg->jnode, cfg->node_dir_path); } +bool mesh_config_write_comp_id(struct mesh_config *cfg, uint16_t cid, + uint16_t pid, uint16_t vid) +{ + if (!cfg) + return false; + + if (!write_comp_id(cfg->jnode, cid, pid, vid)) + return false; + + return true; +} + static bool load_node(const char *fname, const uint8_t uuid[16], mesh_config_node_func_t cb, void *user_data) { diff --git a/mesh/mesh-config.h b/mesh/mesh-config.h index a5b12bbad..9a5d6e57a 100644 --- a/mesh/mesh-config.h +++ b/mesh/mesh-config.h @@ -135,6 +135,8 @@ bool mesh_config_write_unicast(struct mesh_config *cfg, uint16_t unicast); bool mesh_config_write_relay_mode(struct mesh_config *cfg, uint8_t mode, uint8_t count, uint16_t interval); bool mesh_config_write_ttl(struct mesh_config *cfg, uint8_t ttl); +bool mesh_config_write_comp_id(struct mesh_config *cfg, uint16_t cid, + uint16_t pid, uint16_t vid); bool mesh_config_write_mode(struct mesh_config *cfg, const char *keyword, int value); bool mesh_config_model_binding_add(struct mesh_config *cfg, uint16_t ele_addr, From patchwork Thu Jan 30 14:34:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Witowski X-Patchwork-Id: 11358139 X-Patchwork-Delegate: brian.gix@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 894B714E3 for ; Thu, 30 Jan 2020 14:34:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 67B0F20CC7 for ; Thu, 30 Jan 2020 14:34:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=silvair-com.20150623.gappssmtp.com header.i=@silvair-com.20150623.gappssmtp.com header.b="hkXuyBfp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727457AbgA3Oeh (ORCPT ); Thu, 30 Jan 2020 09:34:37 -0500 Received: from mail-wr1-f49.google.com ([209.85.221.49]:46625 "EHLO mail-wr1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727425AbgA3Oeh (ORCPT ); Thu, 30 Jan 2020 09:34:37 -0500 Received: by mail-wr1-f49.google.com with SMTP id z7so4232709wrl.13 for ; Thu, 30 Jan 2020 06:34:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=llKE6xq/cgQVAnARAsbQbpWNPADx/DTs2fqp+Ih+bgk=; b=hkXuyBfp2RcwyVT0l/392ss/w78Ga/VchfYTHySHU1ylLQgM7xigWNrzYciqBsId94 YPl3yDw6H4ztFzg0/z51yrPdURoMBMm9ZXJGgsNhOlErvRaRcusZ5H8eERycd7yN8UKr CTJrNoMMCDYwgSRLU+QJQRPNNjcSnd3TqpExbSbvlbWyhzaPbi6QytRgRZwa0SGbFrYf htP1x+INfiZQ5MHim+dUuMTQkU1zUBLx2bsIQBkaLFsXKWKs4sWWUiVVQpZfML+vWqZY rzjia1O5SEEKn11YFUt/TASTNnYRV6bhyUqsvE9QpBB5lytMos6z32nTIydNl4r21vzU qyuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=llKE6xq/cgQVAnARAsbQbpWNPADx/DTs2fqp+Ih+bgk=; b=KAqizHnOpK38nxZIyNk0KIdXONqgVB0qUZG7CuxfZUNYhgJzFDw+oG1vlUi14dwv3V 2BIzgJwfEtawRMTlfRM2DvVEKMws7E+TEc8vLrXXJDsjj8B2M1mIh536cSx1CjRg8gqv fwkcfvz32QvVX7XI2tK6Dr2Co3qeCcmhfRxur9Hm1NZNXhyNFZMA/to3GHjiiS0rGkUE tfb8QhtEL3ouFBn2SzLMbS5gPk/LhMiwmtIt2bMVnzqPA5LZdSMCasX5lqh5U/3nPYUg zOnXWJb35rGv7zRmUrP3SW0X3m2M7TxZinaqhOs0w5Q6YIe9L6Q77XJszg/j1naaiN8W jGCQ== X-Gm-Message-State: APjAAAVu5TArbFLJEzK0HJ0I08VvfBy3MSqplnaBaerZmnnEssVAUtx0 rkp7AlADsBahVyxl+8XHdBYHwI0TtUHt2A== X-Google-Smtp-Source: APXvYqwHqhNVsH02Jdo2kcNyghRPvWkQZdIaUZTVitkffq245s4epXS/DnZ38eaUo4zvjKNJjlcsvw== X-Received: by 2002:a5d:4e90:: with SMTP id e16mr5890078wru.318.1580394874306; Thu, 30 Jan 2020 06:34:34 -0800 (PST) Received: from localhost.localdomain ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id x10sm7353310wrv.60.2020.01.30.06.34.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 06:34:33 -0800 (PST) From: Jakub Witowski To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 3/4] mesh: remove unused node_set_device_key() Date: Thu, 30 Jan 2020 15:34:24 +0100 Message-Id: <20200130143425.5844-4-jakub.witowski@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200130143425.5844-1-jakub.witowski@silvair.com> References: <20200130143425.5844-1-jakub.witowski@silvair.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch removes node_set_device_key() function, because it is unused. --- mesh/node.c | 5 ----- mesh/node.h | 1 - 2 files changed, 6 deletions(-) diff --git a/mesh/node.c b/mesh/node.c index 6fe70742d..d4be070fa 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -628,11 +628,6 @@ uint16_t node_get_primary(struct mesh_node *node) return node->primary; } -void node_set_device_key(struct mesh_node *node, uint8_t key[16]) -{ - memcpy(node->dev_key, key, 16); -} - const uint8_t *node_get_device_key(struct mesh_node *node) { if (!node) diff --git a/mesh/node.h b/mesh/node.h index a6bc4a2a6..38aea138f 100644 --- a/mesh/node.h +++ b/mesh/node.h @@ -46,7 +46,6 @@ uint16_t node_get_primary(struct mesh_node *node); uint16_t node_get_primary_net_idx(struct mesh_node *node); void node_set_token(struct mesh_node *node, uint8_t token[8]); const uint8_t *node_get_token(struct mesh_node *node); -void node_set_device_key(struct mesh_node *node, uint8_t key[16]); const uint8_t *node_get_device_key(struct mesh_node *node); void node_set_num_elements(struct mesh_node *node, uint8_t num_ele); uint8_t node_get_num_elements(struct mesh_node *node); From patchwork Thu Jan 30 14:34:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Witowski X-Patchwork-Id: 11358143 X-Patchwork-Delegate: brian.gix@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D7B6112B for ; Thu, 30 Jan 2020 14:34:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A7F7206F0 for ; Thu, 30 Jan 2020 14:34:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=silvair-com.20150623.gappssmtp.com header.i=@silvair-com.20150623.gappssmtp.com header.b="OzkWayPv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727442AbgA3Oej (ORCPT ); Thu, 30 Jan 2020 09:34:39 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38218 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727440AbgA3Oei (ORCPT ); Thu, 30 Jan 2020 09:34:38 -0500 Received: by mail-wm1-f66.google.com with SMTP id a9so4478215wmj.3 for ; Thu, 30 Jan 2020 06:34:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=1JONOnTp+j8P+u1SKuer0eDRKjS3RD/D691AgdZxP7A=; b=OzkWayPvGukx0tkOa2yBy8Af90McUfqK85yQHw7ynLFkIB3pejLnZjiyXb/1IaxBcd rcAOlJLPzltovzvlIvalrlL4RF6CRRVAhdq4h+rUk7mRoin/p0NmylLnhrptruzdI3al HlCE3+wnU7U9LfYjfd0/ruFN/cogp+C6g2JqxSZd1rw6eBQg6mF8SBqEUW+X08A765rQ uwJxQ4FmQTRyc7vFvh2Pfo3Lxuz4ker+ySeEIkAMRFgSCFN5SuKIUuJiSH11zDKKxEBC oAtYV6eR6O3IcLJJUMF4QHHkBPCMtKfkv/tVbiK2rhDl6nFnDE8+S4RKIVcmiixJQkMe AJ8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1JONOnTp+j8P+u1SKuer0eDRKjS3RD/D691AgdZxP7A=; b=EGOcdPKWdCzUNQ5BCJnzTO3BgzjUYXv0WHWTh/z9rdWl9cPmMyFiTEqGW5iwFLAZzl F/CL5MQtE3Fjlzh4o8NEdS2+BPj3iCyTACr8hqJu2WtrGGw1KtpLVzLNeV0qbhJvKWpQ 9E3/5BO46krct8E1XzRalm8AQVkd3gwUvl6Gxtj1nq3U9BHznuD1+YNYFELd/w4ELnx/ KkTVAntjf/9wD/3hVqlaqGwudJeA2RqKzq1Y9F4nqJZRMNN8mg6EIlHBADb0IW/DWxyA TdhyXmqVAZUb8xR/tg30dWOcriPsQUAkNMLqaO6TzJTXRRIhe9YPaNZ8r2pxiqJiVmFH 4pWQ== X-Gm-Message-State: APjAAAXHupXT4LTrsL9u+Q1TFkxH/iJF2IK45ci1xLtLDaPlD6yX9b1o HIF2EaHDXxzFEmck/fKTMaf8OopNl8kk8Q== X-Google-Smtp-Source: APXvYqwlAn1zKoNYKIND31ouZKtq39tsv1kPXOCnlRRl0Ug6doYFt/N9JsRKPF1J4k5mrvSiNHtakg== X-Received: by 2002:a7b:ce84:: with SMTP id q4mr5812619wmj.57.1580394875776; Thu, 30 Jan 2020 06:34:35 -0800 (PST) Received: from localhost.localdomain ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id x10sm7353310wrv.60.2020.01.30.06.34.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 06:34:35 -0800 (PST) From: Jakub Witowski To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 4/4] mesh: allow to reattach with new composition data Date: Thu, 30 Jan 2020 15:34:25 +0100 Message-Id: <20200130143425.5844-5-jakub.witowski@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200130143425.5844-1-jakub.witowski@silvair.com> References: <20200130143425.5844-1-jakub.witowski@silvair.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch allows to change the CIP/PID/VID data when reattaching. Additionally the device key is verified during those change. --- mesh/node.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/mesh/node.c b/mesh/node.c index d4be070fa..86102d1da 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -47,6 +47,9 @@ #define MIN_COMP_SIZE 14 +/* COMP_ID_SIZE consists of length of the CID, PID and VID */ +#define COMP_ID_SIZE 6 + #define MESH_NODE_PATH_PREFIX "/node" /* Default values for a new locally created node */ @@ -1389,15 +1392,49 @@ static bool check_req_node(struct managed_obj_request *req) uint16_t attach_len = node_generate_comp(req->attach, attach_comp, sizeof(attach_comp)); + uint8_t keyring_dev_key[16]; + /* Ignore feature bits in Composition Compare */ node_comp[8] = 0; attach_comp[8] = 0; + /* Ignore CID, PID, VID in Composition Compare */ if (node_len != attach_len || - memcmp(node_comp, attach_comp, node_len)) { + memcmp(node_comp + COMP_ID_SIZE, + attach_comp + COMP_ID_SIZE, + node_len - COMP_ID_SIZE)) { l_debug("Failed to verify app's composition data"); return false; } + + /* Compare CID, VID and PID */ + if (!memcmp(node_comp, attach_comp, COMP_ID_SIZE)) + return true; + + /* Verify the device key */ + keyring_get_remote_dev_key(req->attach, req->attach->primary, + keyring_dev_key); + + if (memcmp(keyring_dev_key, + node_get_device_key(req->attach), 16)) + return false; + + if (!mesh_config_write_comp_id(req->attach->cfg, + req->node->comp.cid, + req->node->comp.pid, + req->node->comp.vid)) { + l_debug("Failed to update comp id data"); + return false; + } + + if (!mesh_config_save(req->attach->cfg, true, NULL, NULL)) { + l_debug("Failed to store comp id"); + return false; + } + + memcpy(&req->attach->comp, &req->node->comp, + sizeof(struct node_composition) - + sizeof(req->node->comp.crpl)); } return true;