Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp6178pxa; Thu, 20 Aug 2020 22:50:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxB+1Y56r451w6FmQ6xRZ1FRhlfzdejsAQSfvqfv4FzSsvoVWZXG5kATOMmnmifR2R3MWfB X-Received: by 2002:a05:6402:c0a:: with SMTP id co10mr1300356edb.342.1597989019685; Thu, 20 Aug 2020 22:50:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597989019; cv=none; d=google.com; s=arc-20160816; b=gKLFn/Utap7S+uYwhqUnJ9bvs/qCHp+akm9K0R4DmJ+8DhQpFgBZa6kMEkTdizKRu+ 75q1/exxoZuWK4Z5FZ5WsOsnrRULWg0uZLh5+zZhegjC6MXHDmdpF369rqlB+sugewaY DNBt+FDIJmLGE9JVjQgmThsX3GyqqgREB7GA6FH07fRBLjyXXqypgDx4wCSmu4ARVDv9 qsJes6NKIvA0f3+o+qfupUzTuCWpxVUZYp0rNvbaEgI1MT/UkL2oXqKkIT9OzqV/1d8l LpGc6i9ZwRKZCuxz9TaTdbZ5jAM9KGfGbev6pEi0s26jqACWKzBqNA0xiL8Cm+0rI3b/ /g+g== 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 :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=oLUuHv9EnUeOdrzgkErS8PR5gAXXMJX8hj1znFAsbwk=; b=RAQRPGVIxCy9SeduoNOS4dN4bQo8mI/RowpgNjBHl0dbG0oO6aU+J/jcKOVz5XaDE9 /pNYWOhlYaigG4IDqytHpGaozn5lHKK1yq7e4m66cLRbEizRBUvBLQ4gnyX6hf/xQYhy hCfwEL4NCGi/Ihjb5iCom63lmROREwcjXUIMVf1Dwo+Bc2lRTQGYceZ3v/2JBMmdVSp5 mnoOBNNXFYwK8hKEZRjuGRdq2F/UeNgAY5qEg8wMwvguUlxXDpzikQg1FckVvezN6zC/ G73jGYq8m7J5iF49Jx8ln1vJQjhy44zApP9gPsKSA8SsCws5nXlIyuiNevwJWslU/kw3 duCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z62si760119ede.173.2020.08.20.22.49.36; Thu, 20 Aug 2020 22:50:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726057AbgHUFtA (ORCPT + 99 others); Fri, 21 Aug 2020 01:49:00 -0400 Received: from mga18.intel.com ([134.134.136.126]:50493 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725268AbgHUFs7 (ORCPT ); Fri, 21 Aug 2020 01:48:59 -0400 IronPort-SDR: 91QqtAPYnpRBUcNOh8znkfKxR6R8MMBs7BiJYtG2UgwrMxzuohsXczKf0QNyCwmUl53/L881Le 0J/q6LnIheBQ== X-IronPort-AV: E=McAfee;i="6000,8403,9719"; a="143101665" X-IronPort-AV: E=Sophos;i="5.76,335,1592895600"; d="scan'208";a="143101665" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Aug 2020 22:48:57 -0700 IronPort-SDR: 7dBW4DEL9L/mDCU1/sgLup0lVPcE6otDVhkmqqa7o3FaLrhgBk547W7QD5dFuEL+cDnVWoJYEc Ut/AI7p1yIeg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,335,1592895600"; d="scan'208";a="278829511" Received: from ssuhag-mobl.amr.corp.intel.com (HELO ingas-nuc1.intel.com) ([10.254.84.187]) by fmsmga007.fm.intel.com with ESMTP; 20 Aug 2020 22:48:57 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ] mesh: Use valid net key index when handling Send call Date: Thu, 20 Aug 2020 22:48:56 -0700 Message-Id: <20200821054856.41857-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 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 Retrieve value of bound Net Key index based on the value of passed AppKey index. Check if the key is present and fail early in case of error. Also, pass the correct NetKey index to model layer in mesh_model_send(), instead of hard coded 0. --- mesh/model.c | 2 -- mesh/node.c | 13 +++++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/mesh/model.c b/mesh/model.c index eb5142503..7e1c4ab92 100644 --- a/mesh/model.c +++ b/mesh/model.c @@ -547,8 +547,6 @@ static bool msg_send(struct mesh_node *node, bool cred, uint16_t src, l_debug("no app key for (%x)", app_idx); return false; } - - net_idx = appkey_net_idx(node_get_net(node), app_idx); } out = l_malloc(out_len); diff --git a/mesh/node.c b/mesh/node.c index 1eeffeb8b..ed3d959c5 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -1761,7 +1761,7 @@ static struct l_dbus_message *send_call(struct l_dbus *dbus, const char *sender, *ele_path; struct l_dbus_message_iter iter_data; struct node_element *ele; - uint16_t dst, app_idx, src; + uint16_t dst, app_idx, net_idx, src; uint8_t *data; uint32_t len; @@ -1790,10 +1790,15 @@ static struct l_dbus_message *send_call(struct l_dbus *dbus, if (app_idx & ~APP_IDX_MASK) return dbus_error(msg, MESH_ERROR_INVALID_ARGS, - "Invalid key_index"); + "Invalid key index"); + + net_idx = appkey_net_idx(node_get_net(node), app_idx); + if (net_idx == NET_IDX_INVALID) + return dbus_error(msg, MESH_ERROR_INVALID_ARGS, + "Key not found"); - if (!mesh_model_send(node, src, dst, app_idx, 0, DEFAULT_TTL, false, - data, len)) + if (!mesh_model_send(node, src, dst, app_idx, net_idx, DEFAULT_TTL, + false, data, len)) return dbus_error(msg, MESH_ERROR_FAILED, NULL); return l_dbus_message_new_method_return(msg); -- 2.26.2