Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2220429ybg; Thu, 30 Jul 2020 13:40:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3C40cKJ+DuB9dI2veKM4AUctBv6u5AjyeIDGN+VK/2MJG62kob66S3715mP2Skzl01Vyn X-Received: by 2002:a17:906:5a8a:: with SMTP id l10mr811230ejq.397.1596141615604; Thu, 30 Jul 2020 13:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596141615; cv=none; d=google.com; s=arc-20160816; b=uY6HEhy98mugcklbJHDT+prO1F9AJDzP1aBmiTq9yHq4bF4iFuXFIlAKFUsGof8nNO B+potzbuS8K0mc6/7KDk0vghgk4prWeLkKwPws2hbyzo9/yVyJWEb90HMoCHeAuujd8i +EuJzKBnpG4gStmah7hh+SdSO7Jxh4DMi4p4SBLkfm0APB2/G9TtgkXDdaZdHAJxds5k p2NTt8+YwQeRmF4jhalJPeSUsjFJE31NfMj2ES+9dnubwYDnBFGYJgmOqm7zRc8JgIHt SjpKfJDAtLfV3olq5gD96nZ0AAQa3YUv/FTugoQFCxuMPS5TJn66xLGkmiCQQhpjNP1A ubvg== 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:cc:to:from :ironport-sdr:ironport-sdr; bh=nJedRlgjj09sfEeHziKUC0JByW9oPBWrwNzp3hJiIuQ=; b=TJtHgBdai7MPkSOL3IHyuLJOoYhuhWLMB8gyiKXrCjnRX1eLrLr3aMndUThGSiz96r Bb0XoeClL+pd1aHbUKjmLTuyUc+tusVUfA66koEXLuGs7iCB/1XfwUz5xyjt79v0sbPM bsiy9t/k/kUfb0AsShIYUUD97Wyn13w0AsK+8EE0h+ZqAeQrFr7n4CGMpGLb9telkTsz UAbKOI/DVFAbFq1kQZj+Z5chsmywtmphc717DSLMDobhBZRR/Pmhp+1JNtDRQG2XU2kf sdXMqYCGWBbRxiwzwO8tJNTx3248Iu9ckjh3YfTifSDFvO2lXK8vmN56V5oNJ+Vt/kBW 5zFw== 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 cq22si2920241edb.609.2020.07.30.13.39.48; Thu, 30 Jul 2020 13:40:15 -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 S1730551AbgG3UjH (ORCPT + 99 others); Thu, 30 Jul 2020 16:39:07 -0400 Received: from mga01.intel.com ([192.55.52.88]:35043 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730552AbgG3UjF (ORCPT ); Thu, 30 Jul 2020 16:39:05 -0400 IronPort-SDR: ZYoBTIQVrr45weGxRAQysws92frWjjy/4dwc3NWnq47N1h3y6skDtNQ2neFYny8IA20JC9wbIQ tcTK2njatHfQ== X-IronPort-AV: E=McAfee;i="6000,8403,9698"; a="169803109" X-IronPort-AV: E=Sophos;i="5.75,415,1589266800"; d="scan'208";a="169803109" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2020 13:39:04 -0700 IronPort-SDR: IG42GYL9o1wYXLviryrJKNcrYDe0A3/wiPeWaSvAqZAikcMYlIuFpXrZnwfms+yQtppH9g+9hh JAO4M8nOVrmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,415,1589266800"; d="scan'208";a="330864997" Received: from wlloyd-mobl.amr.corp.intel.com (HELO ingas-nuc1.intel.com) ([10.254.79.39]) by orsmga007.jf.intel.com with ESMTP; 30 Jul 2020 13:39:04 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ 09/10] mesh: Clean up handling of config KR phase messages Date: Thu, 30 Jul 2020 13:38:50 -0700 Message-Id: <20200730203851.32043-10-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200730203851.32043-1-inga.stotland@intel.com> References: <20200730203851.32043-1-inga.stotland@intel.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 This modification allows using a single point for sending out the composed status messages by the Config Server. --- mesh/cfgmod-server.c | 55 +++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c index a7369e435..cacc8b6ea 100644 --- a/mesh/cfgmod-server.c +++ b/mesh/cfgmod-server.c @@ -414,6 +414,31 @@ static uint16_t cfg_relay_msg(struct mesh_node *node, const uint8_t *pkt, return n; } +static uint16_t cfg_key_refresh_phase(struct mesh_node *node, + const uint8_t *pkt, int opcode) +{ + struct mesh_net *net = node_get_net(node); + uint16_t n, idx = l_get_le16(pkt); + uint8_t phase; + + n = mesh_model_opcode_set(OP_CONFIG_KEY_REFRESH_PHASE_STATUS, msg); + + if (opcode == OP_CONFIG_KEY_REFRESH_PHASE_SET) { + phase = pkt[2]; + msg[n] = mesh_net_key_refresh_phase_set(net, idx, phase); + l_debug("Set KR Phase: net=%3.3x transition=%d", idx, phase); + } else { + msg[n] = mesh_net_key_refresh_phase_get(net, idx, &phase); + l_debug("Get KR Phase: net=%3.3x phase=%d", idx, phase); + } + + l_put_le16(idx, msg + n); + msg[n + 2] = (msg[n] != MESH_STATUS_SUCCESS) ? + KEY_REFRESH_PHASE_NONE : phase; + + return n + 3; +} + static void hb_pub_timeout_func(struct l_timeout *timeout, void *user_data) { struct mesh_net *net = user_data; @@ -712,8 +737,7 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx, int b_res = MESH_STATUS_SUCCESS; struct mesh_net_heartbeat *hb; uint16_t n_idx; - uint8_t state, status; - uint8_t phase; + uint8_t state; bool virt = false; uint16_t n; @@ -920,37 +944,16 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx, break; case OP_CONFIG_KEY_REFRESH_PHASE_SET: - if (size != 3 || pkt[2] > 0x03) + if (size != 3 || pkt[2] > KEY_REFRESH_PHASE_THREE) return true; - b_res = mesh_net_key_refresh_phase_set(net, l_get_le16(pkt), - pkt[2]); - size = 2; /* Fall Through */ case OP_CONFIG_KEY_REFRESH_PHASE_GET: - if (size != 2) + if (size != 2 && opcode == OP_CONFIG_KEY_REFRESH_PHASE_GET) return true; - n_idx = l_get_le16(pkt); - - n = mesh_model_opcode_set(OP_CONFIG_KEY_REFRESH_PHASE_STATUS, - msg); - - /* State: 0x00-0x03 phase of key refresh */ - status = mesh_net_key_refresh_phase_get(net, n_idx, - &phase); - if (status != MESH_STATUS_SUCCESS) { - b_res = status; - phase = KEY_REFRESH_PHASE_NONE; - } - - msg[n++] = b_res; - l_put_le16(n_idx, msg + n); - n += 2; - msg[n++] = phase; - - l_debug("Get/Set Key Refresh State (%d)", msg[n-1]); + n = cfg_key_refresh_phase(node, pkt, opcode); break; case OP_APPKEY_ADD: -- 2.26.2