Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2497963ybl; Thu, 9 Jan 2020 13:55:27 -0800 (PST) X-Google-Smtp-Source: APXvYqze5Jfj67BXp2gDnaxtl6Kd6exZ/q/bo8UmLVForAQr2CnMQ01H/7odTfcGcrZs0yBB63mh X-Received: by 2002:a05:6808:181:: with SMTP id w1mr5088104oic.176.1578606927295; Thu, 09 Jan 2020 13:55:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578606927; cv=none; d=google.com; s=arc-20160816; b=p5RM4CXu3UdLl7XfBc/XYUotk6bPKa/QdAAJ1ezuqW1tS/gGKSZ2ABbWSpGisn7Mai 11E55DI3wXUefTIWU04ZKH3VlF6CTWjJsr+iVS0mbRbgwBPrbvYof39b40BBnC4l7HPd Rzq5FoMNi1981/yFucvrCxwWPKcpymZKhJ89MUw3QRD33DrT+L+EdBvPVSu/ATN8lDcp AuOg8E5/WL52PREXBvk32m7RuT5DkVmwod04wNjFNFbndfMIc131CxQpWU14WHbcSv/9 UUFoSPd2ZCDtHn5e5VuZp+1mZuQveQc7yQJ2OiLXC8qjo871mHvkD1GsBXBZ/0dXWT1N io7Q== 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; bh=vjPdt6Sk3vHvtTwaPirPP+esD8nxksOKa1Zka80kHMk=; b=cipTeFgNWpyc6oag/WTVN9rcVaeH+NaJ4EpSOGGpTgqULcJIjZDiechNxMyInkiIsH uJLSjMoLZCKgRy2Smla/P8YxQlMH8fXo7b9Y72Zg5xExwQCwK88uoa3H+ptMqhBdPaKP Eui/ZHZy+RKfUUvhaZtyZMFtp1ztxchlJYX43VB4dwrewDtItBthFfqsBLcvAJ6qtFn3 ZDrTcM50ZHLg0A/L5O6xv7RRewwYqOnfj91V++5QpaItgXFjPqR/O3U5QWaK9B5yAPag T3kjT2Q88ipxoIdIPfcC+QVsTPFYFEunxVY0j7BU4bZOrN4NKIAO1WrRovZIJuqQgbCU 0tiQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v124si4337866oib.173.2020.01.09.13.55.08; Thu, 09 Jan 2020 13:55:27 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726380AbgAIVyd (ORCPT + 99 others); Thu, 9 Jan 2020 16:54:33 -0500 Received: from mga07.intel.com ([134.134.136.100]:33920 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725775AbgAIVyd (ORCPT ); Thu, 9 Jan 2020 16:54:33 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2020 13:54:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,414,1571727600"; d="scan'208";a="236221031" Received: from ingas-nuc1.sea.intel.com ([10.254.104.252]) by orsmga002.jf.intel.com with ESMTP; 09 Jan 2020 13:54:32 -0800 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, michal.lowas-rzechonek@silvair.com, Inga Stotland Subject: [PATCH BlueZ v2] mesh: Correctly generate NetKey list Date: Thu, 9 Jan 2020 13:54:32 -0800 Message-Id: <20200109215432.28295-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.1 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 When responding with NetKey List Status, packed NetKey indices into 3 octets per pair. If number of NetKeys is odd, append the last key index as a 2-octet value. --- mesh/net.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/mesh/net.c b/mesh/net.c index 0a4d2e72c..dfaf7ccef 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -1065,26 +1065,46 @@ bool mesh_net_get_key(struct mesh_net *net, bool new_key, uint16_t idx, bool mesh_net_key_list_get(struct mesh_net *net, uint8_t *buf, uint16_t *size) { const struct l_queue_entry *entry; - uint16_t n, buf_size; + uint16_t num_keys, req_size, buf_size; + struct mesh_subnet *subnet; if (!net || !buf || !size) return false; buf_size = *size; - if (buf_size < l_queue_length(net->subnets) * 2) + + num_keys = l_queue_length(net->subnets); + req_size = (num_keys / 2) * 3 + (num_keys % 2) * 2; + + if (buf_size < req_size) return false; - n = 0; - entry = l_queue_get_entries(net->subnets); + *size = req_size; + + /* Pack NetKey indices in 3 octets */ + for (entry = l_queue_get_entries(net->subnets); num_keys > 1;) { + uint32_t idx_pair; - for (; entry; entry = entry->next) { - struct mesh_subnet *subnet = entry->data; + subnet = entry->data; + idx_pair = subnet->idx; + idx_pair <<= 12; + + subnet = entry->next->data; + idx_pair += subnet->idx; + + l_put_le32(idx_pair, buf); + buf += 3; + + num_keys -= 2; + entry = entry->next->next; + } + /* If odd number of NetKeys, fill in the end of the buffer */ + if (num_keys % 2) { + subnet = entry->data; l_put_le16(subnet->idx, buf); - n += 2; } - *size = n; return true; } -- 2.21.1