Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5355003ybe; Tue, 10 Sep 2019 02:21:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwW48P7nf+4M3wN7EyIWK49spk4ylASxhFXE6P5k1ue9hB8AExirzNZ4Irrl8BHiLMPYAkz X-Received: by 2002:a17:906:b88f:: with SMTP id hb15mr23548621ejb.292.1568107282825; Tue, 10 Sep 2019 02:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568107282; cv=none; d=google.com; s=arc-20160816; b=c9iZqqyLgVtadh/IjMRqn8M7VhtUVRA7F2qEeoxADPy4er4KZOUI6SAiTxbWH4n30d AmJLcF2Sz2J15VocXerh3ulP6IPXJ18pGWyOvfaCJ47x/lobWbsvPAWVk9tBXZlFmr58 QTKBgg6SMTTCuk8AkT5bX4P3+sJcfxim8mM8fMnyO3e42U0JHBN3OPi3tWSfc2bgVSO2 sxnSAfplNexE3XHptPV2mfcw2P0jKb/H5Mu1gN7szt9BgMNnbJDg32cyAln6pr4olW+6 GyjPNVenR8i9Ds4jBphit936mIfkT1Ws1byy6GZGdE68Hkz/c1MltoCzXhlurdwMN+YR Fz+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:to:from:dkim-signature; bh=U/wXBGUzX0jqWZ1IaMMUMtkYbR0sC01H/tyQ+UFHiPE=; b=oGCskxROCCSAmJy+jTXulrcNhoXjksF1ZVcHRwpXbXo+vpXgMZUEh6LL/a9sxjcf0c U0baI5eLL1DI6pYd9oYLoX5oEbdleCSraUCHy7M/2R7SOkOtKMbqqFVsJ2uNkxD0U9Qd q8Iwey28mB4bpPabJvP/hNrWQnS8pASXj3gYc7lDHhVolwLuskpyZ6FQfoqXL6Jqcz5Q BTmaqLucOHafkl8PMVxUzPHeUzzVFJM91ovQdrS+JalJBzXIH/yCwzmcN5xOEiRlktSh NE6Ki/ad5L3DkCufPiAmc/zvy0g1r+svHgzdkKXNphvRecZf8qMCWwSlveqytXh7ogHv REOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=IVNtSueW; 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 lu17si8790149ejb.146.2019.09.10.02.20.57; Tue, 10 Sep 2019 02:21:22 -0700 (PDT) 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=IVNtSueW; 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 S2405468AbfIITZV (ORCPT + 99 others); Mon, 9 Sep 2019 15:25:21 -0400 Received: from mail-lf1-f49.google.com ([209.85.167.49]:40823 "EHLO mail-lf1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729060AbfIITZU (ORCPT ); Mon, 9 Sep 2019 15:25:20 -0400 Received: by mail-lf1-f49.google.com with SMTP id u29so11426980lfk.7 for ; Mon, 09 Sep 2019 12:25:19 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=U/wXBGUzX0jqWZ1IaMMUMtkYbR0sC01H/tyQ+UFHiPE=; b=IVNtSueWxObNSt5UDX2kk5i0NMHMfckpOUhzg7pEylWK6mY75HEVBCdbk85Sb+xtcv xvpzHKENqX+c0df3ubzHo76uK+wj1FvtDu1BB0raEIJYPQN0CBYmjqqIGShI34S5BcMi W0M3THUreNyQlk0+fEARGWPhYvTajkKNvAJOfOmb7oKnckaLxOUBH5ZyDYqh61iwTTA7 55YmwgitBVET+/8uSyLowMf32T9jkdmMADrLTMIS/1NpctRdNwa2JI6naxatT8CfV+1w E4qgq71spvNRSqxs9Kwf6k3nSIpUyqKUqLVTTu8JNRzQFah+t8U2J51XPKPQ24IlKAJ9 mopg== 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:mime-version :content-transfer-encoding; bh=U/wXBGUzX0jqWZ1IaMMUMtkYbR0sC01H/tyQ+UFHiPE=; b=NqqBx3mlILShG5644s2tLLUySNON5WYydDodscNwxyEevN3Oq5SgxTU1QTd73mR2+B ek9Gl3x3lUdJse5HGlUS88omr2D5F8CCPRp46e/ZfQuLE4arsHcELI66if5dDkBOHGgE jdHZN9UF1TVXSspbHZMO0kgg1IF2NGMWumQdbcqd9i5HGo4xMLrtunApd3bqgjaE5HhF UUZ4xlutgTv29hLx6kriz8b0k7jl19+pMaOXNhD3LDIipz8lwGpVid9K3JslR/aODVfR K5Yr5jYBJ+OCm9Wlr3ohM9HZYoBXb9OccYlPA6zE/VbcZRj63u6msDyd76nKqZIiZuX+ Lp4A== X-Gm-Message-State: APjAAAVdub5CfX3AsCwtkQiF8pppEuFdHQDbMykqNI0n3RZTaI0Sv+nu hvNsVuW9g2nEdqROdZkU9c62j592t8M= X-Received: by 2002:a19:f11c:: with SMTP id p28mr17292000lfh.44.1568057118374; Mon, 09 Sep 2019 12:25:18 -0700 (PDT) Received: from kynes.internet.domowy (apn-37-248-119-32.dynamic.gprs.plus.pl. [37.248.119.32]) by smtp.gmail.com with ESMTPSA id c3sm3622904lfi.32.2019.09.09.12.25.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Sep 2019 12:25:17 -0700 (PDT) From: =?UTF-8?q?Micha=C5=82=20Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2] mesh: Fix IV Recovery procedure when IV Update is in progress Date: Mon, 9 Sep 2019 21:25:09 +0200 Message-Id: <20190909192509.15007-1-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.22.0 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 This patch ensures that Sequence Number is reset only when IV Index used for outgoing messages increases. This fixes erroneously cleared sequence number when node performs IV Recovery procedure on startup in a following scenario: - node has IV Index set to - node starts in IV_UPD_INIT state - node receives a Secure Network Beacon with IV Index +1 and IV Update flag set Upon reception, the node shall: - increase its IV Index to +1 - enter IV_UPD_UPDATING state This means that the node keeps transmitting messages using IV Index equal to , therefore it shall *not* reset its Sequence Number before IV Update procedure completes. If, on the other hand, SNB contains either: - IV Index +2 (regardless of IV Update flag) - IV Index +1 and IV Update flag *not* set the node shall reset the Sequence Number right away. --- mesh/net.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mesh/net.c b/mesh/net.c index 7c4049e0e..ba7bb32fd 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -2735,8 +2735,6 @@ static void update_iv_kr_state(struct mesh_subnet *subnet, uint32_t iv_index, } if (net->iv_upd_state == IV_UPD_INIT) { - if (iv_index > net->iv_index) - mesh_net_set_seq_num(net, 0); net->iv_index = iv_index; if (iv_update) { @@ -2757,6 +2755,12 @@ static void update_iv_kr_state(struct mesh_subnet *subnet, uint32_t iv_index, mesh_config_write_iv_index(node_config_get(net->node), iv_index, net->iv_upd_state); + /* Reset seq num if iv index used for *outgoing* messages has + * just been increased + */ + if (mesh_net_get_iv_index(net) > local_iv_index) + mesh_net_set_seq_num(net, 0); + /* Figure out the key refresh phase */ if (kr_transition) { l_debug("Beacon based KR phase change"); -- 2.22.0