Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2725759ybl; Mon, 20 Jan 2020 08:13:49 -0800 (PST) X-Google-Smtp-Source: APXvYqws9SlmWekwcGesA+Vzn6YvZmJmvnimP3PrczGevhGTPh3s9FX2uM8X39rit5iHqZtrAkXD X-Received: by 2002:a54:4396:: with SMTP id u22mr47984oiv.128.1579536829760; Mon, 20 Jan 2020 08:13:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579536829; cv=none; d=google.com; s=arc-20160816; b=frRA2gNsoKrlt9i2invqxdPqixxvaxjLJo39GX5iLqQCJSGcNJgbAhWqOytHZ3VW5M XKOzoXmQJB088Zg0bIopZJZ5g51e6zkuDhCMtcXxGVrHhm9GR09+6ZFk7pj3Iqcv/Vmt BpnY0JMP89VZd2GrYcyDcB49v6vxCZe35cdgEUp18LFr4xyiXl23YVAIud93deJG99K5 iEJo/WvPx58YCAoVQ9J54dXrsBRJKxMPDpwj2eK8kZ5KAuLmwNXmvrqGAxNA+2Rj7mpW G466jWhTkSsR8aaXH9UsgwjADGRHwk86omqh1kh2VItu508ohE2WW/sIrqqZ659zdKHB Q3og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=KmtQ5vJs04+y7YOuZpyU/tHE9nbTiu1Y147WH5ZpNJg=; b=z54q8WM/nia8rnOEJaXQZFsTmeOGAcndEIsHi6VfQOfbsupr6xZOkReU2m1NBlU1UX M2jzjLH9u0QA87oCV487FfPhydV/eYjawR8/18QTnOxUYw4KRup/jRHEdAbbvdI7OO4o bWfLTQnCMXfTFsFoCt5w2ACvEtbnToHvFl1NRi6KCUUb7ejFtTvZ9CpheYjmWrbAVQ+P qeMvxNP37jUYyRwzNuXU614wTvasRrx/D3Fh4ows1hDNlgTw4Kld90SLBLL+Ca0ubRke UZtAxCSGkojRpI8CTi6mtEK/JoEdfNh8uywwqfardMg2H1s8raipzCtyon+SzXR/hDrI nwEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b="gyH/kxkn"; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y26si20606044otk.315.2020.01.20.08.13.36; Mon, 20 Jan 2020 08:13:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b="gyH/kxkn"; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728842AbgATQL0 (ORCPT + 99 others); Mon, 20 Jan 2020 11:11:26 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:36977 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726642AbgATQL0 (ORCPT ); Mon, 20 Jan 2020 11:11:26 -0500 Received: by mail-wm1-f68.google.com with SMTP id f129so152192wmf.2 for ; Mon, 20 Jan 2020 08:11:25 -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=KmtQ5vJs04+y7YOuZpyU/tHE9nbTiu1Y147WH5ZpNJg=; b=gyH/kxknCFhLDkLUO8LacMslhsaccB2/ahww5W0R7F0igQuTl4IHmIz9LrOB3FlYum 6iMsJQ0hm+u7BjoZYIsrPl+8whc7FcI9tFBVu89QVlwY0yaIQ7kHaSoTMBEl4LVrqAh6 gKdKzsG9wYFwweF6o6KNWx+7bKq4KjDzhB8NxXSBn7qTfLuoh805AGYzZviC+YdxoMzR rG3dki+6UBHwzA/X7O5vE8un4xc9Z3SQvkhR/MaDtdMcwXdKexLhUQQsr1qeCYvoLgBu Q8AzH+h8r59RZklhiJ9WF64vrrjZCRLwCFqs4aQLBYoiUIbxH4ESKoZzK1ZRvpTrq14F JMoQ== 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=KmtQ5vJs04+y7YOuZpyU/tHE9nbTiu1Y147WH5ZpNJg=; b=eORt9tPStmSDETiyuojLlfdw8zkpKeyGPqLWodawpNdr7rbje/MU6Ok5tyA6kpOt1D RMPUZW7vEhqlN5ch01c+ainj1XtI1ScIFxA1fbQSVj98SYvVbY2PYIRqVjP0JeBwmgrI TBFKoEZd1SRogt85q6do/U3XAexWzTGBRVW1mBAxKQjuVoHUynM2Q39XxEyJI9Tutk+x IvmBEHpR4o6e8cp0qs4zlCxcVDjYZ9vkU3lJXMmtyJ0P9VAHLg9b9Ulay2zjCIHwzCYd sbdH7iIkWk5JMcwo7lgYRvnaXH0FO08XSZXXxhm4dDLc0I1lpDOGiqPHHISje8nShFyq atlA== X-Gm-Message-State: APjAAAWaL4IATub1o3WaWSdsZAEpkJ98UpZWcNwFq2my6Mxh6nJFSwhO Fr4pni0MmnfaFl82f1EoOkCetQCEy3s6JQ== X-Received: by 2002:a1c:7c11:: with SMTP id x17mr103151wmc.168.1579536684920; Mon, 20 Jan 2020 08:11:24 -0800 (PST) Received: from localhost.localdomain ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id 16sm22564602wmi.0.2020.01.20.08.11.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2020 08:11:24 -0800 (PST) From: Jakub Witowski To: linux-bluetooth@vger.kernel.org Subject: [PATCH 3/3] mesh: allow to reattach with new composition data Date: Mon, 20 Jan 2020 17:11:14 +0100 Message-Id: <20200120161114.6757-4-jakub.witowski@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200120161114.6757-1-jakub.witowski@silvair.com> References: <20200120161114.6757-1-jakub.witowski@silvair.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- mesh/node.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/mesh/node.c b/mesh/node.c index 6fe70742d..f9a2d5722 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -47,6 +47,12 @@ #define MIN_COMP_SIZE 14 +/* Composition data header size contains the length of belows: + * CID, PID, VID, CRPL and Feature bits + */ +#define COMP_HDR_SIZE 10 +#define COMP_FEATURE_BITS_SIZE 2 + #define MESH_NODE_PATH_PREFIX "/node" /* Default values for a new locally created node */ @@ -1394,15 +1400,39 @@ static bool check_req_node(struct managed_obj_request *req) uint16_t attach_len = node_generate_comp(req->attach, attach_comp, sizeof(attach_comp)); - /* Ignore feature bits in Composition Compare */ - node_comp[8] = 0; - attach_comp[8] = 0; - + /* Ignore CID, VID, PID, CRPL and feature bits + * in Composition Compare + */ if (node_len != attach_len || - memcmp(node_comp, attach_comp, node_len)) { + memcmp(node_comp + COMP_HDR_SIZE, + attach_comp + COMP_HDR_SIZE, + node_len - COMP_HDR_SIZE)) { l_debug("Failed to verify app's composition data"); return false; } + + /* Compare CID, VID, PID and CRPL */ + if (!memcmp(node_comp, attach_comp, + COMP_HDR_SIZE - COMP_FEATURE_BITS_SIZE)) + return true; + + l_debug("Composition data update"); + + if (!mesh_config_write_comp(req->attach->cfg, + req->node->comp.cid, req->node->comp.pid, + req->node->comp.vid, req->node->comp.crpl)) { + + l_debug("Failed to update composition data"); + return false; + } + + if (!mesh_config_save(req->attach->cfg, true, NULL, NULL)) { + l_debug("Failed to store composition data"); + return false; + } + + memcpy(&req->attach->comp, &req->node->comp, + sizeof(struct node_composition)); } return true; -- 2.20.1