From patchwork Fri Aug 7 01:38:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inga Stotland X-Patchwork-Id: 252905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS,UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CE09C433E0 for ; Fri, 7 Aug 2020 01:38:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C66620855 for ; Fri, 7 Aug 2020 01:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726058AbgHGBik (ORCPT ); Thu, 6 Aug 2020 21:38:40 -0400 Received: from mga18.intel.com ([134.134.136.126]:43991 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726049AbgHGBij (ORCPT ); Thu, 6 Aug 2020 21:38:39 -0400 IronPort-SDR: qWtHpGPykUKRcTVKxDNNUtQYjg34kjx7QcA71yFFf/JH8vw/7tNC98ec+1UryY3mx/CprY4NUQ TV5ylr6g85jw== X-IronPort-AV: E=McAfee;i="6000,8403,9705"; a="140558038" X-IronPort-AV: E=Sophos;i="5.75,443,1589266800"; d="scan'208";a="140558038" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2020 18:38:38 -0700 IronPort-SDR: ct/Py4rrlJObpfK1wWbqZsfffDNGnctWguD15vEmbH0KhEcfu+tdAbRQY0XCMenp4qmBJXnHmK 4l1hA/AK/gSQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,443,1589266800"; d="scan'208";a="397442071" Received: from unknown (HELO ingas-nuc1.intel.com) ([10.254.119.50]) by fmsmga001.fm.intel.com with ESMTP; 06 Aug 2020 18:38:38 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ v5 02/10] mesh: Clean up handling of config model binding messages Date: Thu, 6 Aug 2020 18:38:26 -0700 Message-Id: <20200807013834.123263-3-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200807013834.123263-1-inga.stotland@intel.com> References: <20200807013834.123263-1-inga.stotland@intel.com> MIME-Version: 1.0 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. Also, remove unused definitions for binding functions in node.h --- mesh/cfgmod-server.c | 130 ++++++++++++------------------------------- mesh/mesh-defs.h | 3 + mesh/model.c | 20 ++----- mesh/node.h | 4 -- 4 files changed, 45 insertions(+), 112 deletions(-) diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c index 069c25062..992279165 100644 --- a/mesh/cfgmod-server.c +++ b/mesh/cfgmod-server.c @@ -112,8 +112,7 @@ static void config_pub_set(struct mesh_node *node, uint16_t net_idx, uint16_t ele_addr, idx, ota = UNASSIGNED_ADDRESS; const uint8_t *pub_addr; uint16_t test_addr; - uint8_t ttl, period; - uint8_t retransmit; + uint8_t ttl, period, retransmit; int status; bool cred_flag; @@ -362,115 +361,56 @@ static uint16_t config_sub_del_all(struct mesh_node *node, const uint8_t *pkt, return n; } -static void send_model_app_status(struct mesh_node *node, uint16_t net_idx, - uint16_t src, uint16_t dst, - uint8_t status, uint16_t addr, - uint32_t id, uint16_t idx) -{ - size_t n = mesh_model_opcode_set(OP_MODEL_APP_STATUS, msg); - - msg[n++] = status; - l_put_le16(addr, msg + n); - n += 2; - l_put_le16(idx, msg + n); - n += 2; - - if (IS_VENDOR(id)) { - l_put_le16(VENDOR_ID(id), msg + n); - n += 2; - } - - l_put_le16(MODEL_ID(id), msg + n); - n += 2; - - mesh_model_send(node, dst, src, APP_IDX_DEV_LOCAL, net_idx, DEFAULT_TTL, - false, msg, n); -} - -static void model_app_list(struct mesh_node *node, uint16_t net_idx, - uint16_t src, uint16_t dst, +static uint16_t model_app_list(struct mesh_node *node, const uint8_t *pkt, uint16_t size) { - uint16_t ele_addr; + uint16_t ele_addr, n, bnd_len; uint32_t id; - uint8_t *status; - uint16_t n; - int result; + int opcode; + opcode = (size == 4) ? OP_MODEL_APP_LIST : OP_VEND_MODEL_APP_LIST; ele_addr = l_get_le16(pkt); - switch (size) { - default: - return; - case 4: - n = mesh_model_opcode_set(OP_MODEL_APP_LIST, msg); - status = msg + n; - id = l_get_le16(pkt + 2); - l_put_le16(ele_addr, msg + 1 + n); - l_put_le16((uint16_t) id, msg + 3 + n); - id = SET_ID(SIG_VENDOR, id); - n += 5; - break; - case 6: - n = mesh_model_opcode_set(OP_VEND_MODEL_APP_LIST, msg); - status = msg + n; - id = SET_ID(l_get_le16(pkt + 2), l_get_le16(pkt + 4)); + n = mesh_model_opcode_set(opcode, msg); + memcpy(msg + n + 1, pkt, size); - l_put_le16(ele_addr, msg + 1 + n); - l_put_le16((uint16_t) VENDOR_ID(id), msg + 3 + n); - l_put_le16((uint16_t) MODEL_ID(id), msg + 5 + n); - n += 7; - break; - } + id = CFG_GET_ID(size == 6, pkt + 2); - result = mesh_model_get_bindings(node, ele_addr, id, msg + n, - MAX_MSG_LEN - n, &size); - n += size; + msg[n] = mesh_model_get_bindings(node, ele_addr, id, msg + n + 1 + size, + MAX_MSG_LEN - (n + 1 + size), &bnd_len); - if (result >= 0) { - *status = result; - mesh_model_send(node, dst, src, APP_IDX_DEV_LOCAL, net_idx, - DEFAULT_TTL, false, msg, n); - } + if (msg[n] == MESH_STATUS_SUCCESS) + n += bnd_len; + + n += (size + 1); + return n; } -static bool model_app_bind(struct mesh_node *node, uint16_t net_idx, - uint16_t src, uint16_t dst, - const uint8_t *pkt, uint16_t size, - bool unbind) +static uint16_t model_app_bind(struct mesh_node *node, const uint8_t *pkt, + uint16_t size, bool unbind) { - uint16_t ele_addr; + uint16_t ele_addr, idx, n; uint32_t id; - uint16_t idx; - int result; - switch (size) { - default: - return false; - case 6: - id = SET_ID(SIG_VENDOR, l_get_le16(pkt + 4)); - break; - case 8: - id = SET_ID(l_get_le16(pkt + 4), l_get_le16(pkt + 6)); - break; - } + idx = l_get_le16(pkt + 2); + if (idx > APP_IDX_MAX) + return 0; ele_addr = l_get_le16(pkt); - idx = l_get_le16(pkt + 2); + id = CFG_GET_ID(size == 8, pkt + 4); - if (idx > 0xfff) - return false; + n = mesh_model_opcode_set(OP_MODEL_APP_STATUS, msg); if (unbind) - result = mesh_model_binding_del(node, ele_addr, id, idx); + msg[n] = mesh_model_binding_del(node, ele_addr, id, idx); else - result = mesh_model_binding_add(node, ele_addr, id, idx); + msg[n] = mesh_model_binding_add(node, ele_addr, id, idx); - send_model_app_status(node, net_idx, src, dst, result, ele_addr, - id, idx); + memcpy(msg + n + 1, pkt, size); + n += (size + 1); - return true; + return n; } static void hb_pub_timeout_func(struct l_timeout *timeout, void *user_data) @@ -703,8 +643,7 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx, if (size != 1 || pkt[0] > TTL_MASK || pkt[0] == 1) return true; - if (pkt[0] <= TTL_MASK) - node_default_ttl_set(node, pkt[0]); + node_default_ttl_set(node, pkt[0]); /* Fall Through */ case OP_CONFIG_DEFAULT_TTL_GET: @@ -1048,22 +987,25 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx, case OP_MODEL_APP_BIND: case OP_MODEL_APP_UNBIND: - model_app_bind(node, net_idx, src, dst, pkt, size, - opcode != OP_MODEL_APP_BIND); + if (size != 6 && size != 8) + return true; + + n = model_app_bind(node, pkt, size, + opcode != OP_MODEL_APP_BIND); break; case OP_VEND_MODEL_APP_GET: if (size != 6) return true; - model_app_list(node, net_idx, src, dst, pkt, size); + n = model_app_list(node, pkt, size); break; case OP_MODEL_APP_GET: if (size != 4) return true; - model_app_list(node, net_idx, src, dst, pkt, size); + n = model_app_list(node, pkt, size); break; case OP_CONFIG_HEARTBEAT_PUB_SET: diff --git a/mesh/mesh-defs.h b/mesh/mesh-defs.h index bbde53303..5ade751a3 100644 --- a/mesh/mesh-defs.h +++ b/mesh/mesh-defs.h @@ -105,6 +105,9 @@ #define NET_IDX_INVALID 0xffff #define NET_NID_INVALID 0xff +#define NET_IDX_MAX 0x0fff +#define APP_IDX_MAX 0x0fff + #define APP_IDX_MASK 0x0fff #define APP_IDX_DEV_REMOTE 0x6fff #define APP_IDX_DEV_LOCAL 0x7fff diff --git a/mesh/model.c b/mesh/model.c index 3c9b6577a..90192328f 100644 --- a/mesh/model.c +++ b/mesh/model.c @@ -111,13 +111,7 @@ static bool simple_match(const void *a, const void *b) static bool has_binding(struct l_queue *bindings, uint16_t idx) { - const struct l_queue_entry *l; - - for (l = l_queue_get_entries(bindings); l; l = l->next) { - if (L_PTR_TO_UINT(l->data) == idx) - return true; - } - return false; + return l_queue_find(bindings, simple_match, L_UINT_TO_PTR(idx)) != NULL; } static bool find_virt_by_label(const void *a, const void *b) @@ -628,7 +622,6 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id, uint16_t app_idx, bool unbind) { struct mesh_model *mod; - bool is_present; int ele_idx = node_get_element_idx(node, addr); if (ele_idx < 0) @@ -645,12 +638,11 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id, if (!appkey_have_key(node_get_net(node), app_idx)) return MESH_STATUS_INVALID_APPKEY; - is_present = has_binding(mod->bindings, app_idx); - - if (!is_present && unbind) - return MESH_STATUS_SUCCESS; - - if (is_present && !unbind) + /* + * If deleting a binding that is not present, return success. + * If adding a binding that already exists, return success. + */ + if (unbind ^ has_binding(mod->bindings, app_idx)) return MESH_STATUS_SUCCESS; if (unbind) { diff --git a/mesh/node.h b/mesh/node.h index 47c998530..7874b8692 100644 --- a/mesh/node.h +++ b/mesh/node.h @@ -49,10 +49,6 @@ const uint8_t *node_get_token(struct mesh_node *node); const uint8_t *node_get_device_key(struct mesh_node *node); void node_set_num_elements(struct mesh_node *node, uint8_t num_ele); uint8_t node_get_num_elements(struct mesh_node *node); -bool node_add_binding(struct mesh_node *node, uint8_t ele_idx, - uint32_t model_id, uint16_t app_idx); -bool node_del_binding(struct mesh_node *node, uint8_t ele_idx, - uint32_t model_id, uint16_t app_idx); uint8_t node_default_ttl_get(struct mesh_node *node); bool node_default_ttl_set(struct mesh_node *node, uint8_t ttl); bool node_set_sequence_number(struct mesh_node *node, uint32_t seq); From patchwork Fri Aug 7 01:38:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inga Stotland X-Patchwork-Id: 252904 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS,UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED050C433E3 for ; Fri, 7 Aug 2020 01:38:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E151820855 for ; Fri, 7 Aug 2020 01:38:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726197AbgHGBil (ORCPT ); Thu, 6 Aug 2020 21:38:41 -0400 Received: from mga18.intel.com ([134.134.136.126]:43978 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726049AbgHGBik (ORCPT ); Thu, 6 Aug 2020 21:38:40 -0400 IronPort-SDR: ZzcnPh6Lt501SNsJPhdJR/EhXTcvz6rPyOaqZMM8jKe//6kssTcu3mCxhYH+UHLwDFZD1jMQpE AT7HZ2rXm09A== X-IronPort-AV: E=McAfee;i="6000,8403,9705"; a="140558041" X-IronPort-AV: E=Sophos;i="5.75,443,1589266800"; d="scan'208";a="140558041" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2020 18:38:40 -0700 IronPort-SDR: Krc5OgDgSfq50jRfe6RvxcaJaTEqj73WRjAlWjHkYgFY+BZkfqZz9/zQlmi0uD9MwwgNSukT1U JmDe9zPR+IkA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,443,1589266800"; d="scan'208";a="397442078" Received: from unknown (HELO ingas-nuc1.intel.com) ([10.254.119.50]) by fmsmga001.fm.intel.com with ESMTP; 06 Aug 2020 18:38:39 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ v5 04/10] mesh: Clean up handling of config publication messages Date: Thu, 6 Aug 2020 18:38:28 -0700 Message-Id: <20200807013834.123263-5-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200807013834.123263-1-inga.stotland@intel.com> References: <20200807013834.123263-1-inga.stotland@intel.com> MIME-Version: 1.0 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. Also, return Feature Not Supported errror code when credential flag is set, but the node does not support LPN feature --- mesh/cfgmod-server.c | 99 ++++++++++++++++++-------------------------- mesh/model.c | 7 +++- mesh/net.h | 2 - 3 files changed, 46 insertions(+), 62 deletions(-) diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c index 82938dc83..6ed5800c0 100644 --- a/mesh/cfgmod-server.c +++ b/mesh/cfgmod-server.c @@ -32,6 +32,8 @@ #include "mesh/mesh-config.h" #include "mesh/cfgmod.h" +#define CREDFLAG_MASK 0x1000 + #define CFG_GET_ID(vendor, pkt) ((vendor) ? \ (SET_ID(l_get_le16((pkt)), l_get_le16((pkt) + 2))) : \ (SET_ID(SIG_VENDOR, l_get_le16(pkt)))) @@ -44,11 +46,9 @@ static const uint8_t supported_pages[] = { static uint8_t msg[MAX_MSG_LEN]; -static void send_pub_status(struct mesh_node *node, uint16_t net_idx, - uint16_t src, uint16_t dst, - uint8_t status, uint16_t ele_addr, uint32_t id, - uint16_t pub_addr, uint16_t idx, bool cred_flag, - uint8_t ttl, uint8_t period, uint8_t retransmit) +static uint16_t set_pub_status(uint8_t status, uint16_t ele_addr, uint32_t id, + uint16_t pub_addr, uint16_t idx, bool cred_flag, + uint8_t ttl, uint8_t period, uint8_t retransmit) { size_t n; @@ -72,46 +72,36 @@ static void send_pub_status(struct mesh_node *node, uint16_t net_idx, n += 4; } - mesh_model_send(node, dst, src, APP_IDX_DEV_LOCAL, net_idx, DEFAULT_TTL, - false, msg, n); + return n; } -static void config_pub_get(struct mesh_node *node, uint16_t net_idx, - uint16_t src, uint16_t dst, - const uint8_t *pkt, uint16_t size) +static uint16_t config_pub_get(struct mesh_node *node, const uint8_t *pkt, + bool vendor) { uint32_t id; uint16_t ele_addr; struct mesh_model_pub *pub; int status; - if (size == 4) { - id = SET_ID(SIG_VENDOR, l_get_le16(pkt + 2)); - } else if (size == 6) { - id = SET_ID(l_get_le16(pkt + 2), l_get_le16(pkt + 4)); - } else - return; - ele_addr = l_get_le16(pkt); + id = CFG_GET_ID(vendor, pkt + 2); + pub = mesh_model_pub_get(node, ele_addr, id, &status); if (pub && status == MESH_STATUS_SUCCESS) - send_pub_status(node, net_idx, src, dst, status, ele_addr, - id, pub->addr, pub->idx, pub->credential, - pub->ttl, pub->period, pub->retransmit); + return set_pub_status(status, ele_addr, id, pub->addr, pub->idx, + pub->credential, pub->ttl, pub->period, + pub->retransmit); else - send_pub_status(node, net_idx, src, dst, status, ele_addr, - id, 0, 0, 0, 0, 0, 0); + return set_pub_status(status, ele_addr, id, 0, 0, 0, 0, 0, 0); } -static void config_pub_set(struct mesh_node *node, uint16_t net_idx, - uint16_t src, uint16_t dst, - const uint8_t *pkt, bool virt, bool vendor) +static uint16_t config_pub_set(struct mesh_node *node, const uint8_t *pkt, + bool virt, bool vendor) { uint32_t id; - uint16_t ele_addr, idx, ota = UNASSIGNED_ADDRESS; + uint16_t ele_addr, idx, pub_dst; const uint8_t *pub_addr; - uint16_t test_addr; uint8_t ttl, period, retransmit; int status; bool cred_flag; @@ -119,42 +109,35 @@ static void config_pub_set(struct mesh_node *node, uint16_t net_idx, ele_addr = l_get_le16(pkt); pub_addr = pkt + 2; - pkt += (virt ? 14 : 0); + pub_dst = l_get_le16(pub_addr); - idx = l_get_le16(pkt + 4); - ttl = pkt[6]; - period = pkt[7]; - retransmit = pkt[8]; - id = l_get_le16(pkt + 9); + if (!virt && IS_VIRTUAL(pub_dst)) + return 0; - if (!vendor) - id = SET_ID(SIG_VENDOR, id); - else - id = SET_ID(id, l_get_le16(pkt + 11)); + pkt += (virt ? 14 : 0); - /* Don't accept virtual seeming addresses */ - test_addr = l_get_le16(pub_addr); - if (!virt && IS_VIRTUAL(test_addr)) - return; + idx = l_get_le16(pkt + 4); + if (idx > CREDFLAG_MASK) + return 0; cred_flag = !!(CREDFLAG_MASK & idx); idx &= APP_IDX_MASK; + ttl = pkt[6]; + period = pkt[7]; + retransmit = pkt[8]; + id = CFG_GET_ID(vendor, pkt + 9); status = mesh_model_pub_set(node, ele_addr, id, pub_addr, idx, cred_flag, ttl, period, retransmit, - virt, &ota); - - l_debug("pub_set: status %d, ea %4.4x, ota: %4.4x, mod: %x, idx: %3.3x", - status, ele_addr, ota, id, idx); + virt, &pub_dst); - if (status != MESH_STATUS_SUCCESS) { - send_pub_status(node, net_idx, src, dst, status, ele_addr, - id, 0, 0, 0, 0, 0, 0); + l_debug("pub_set: status %d, ea %4.4x, ota: %4.4x, id: %x, idx: %3.3x", + status, ele_addr, pub_dst, id, idx); - return; - } + if (status != MESH_STATUS_SUCCESS) + return set_pub_status(status, ele_addr, id, 0, 0, 0, 0, 0, 0); - if (IS_UNASSIGNED(test_addr) && !virt) { + if (IS_UNASSIGNED(pub_dst) && !virt) { ttl = period = idx = 0; /* Remove model publication from config file */ @@ -165,7 +148,7 @@ static void config_pub_set(struct mesh_node *node, uint16_t net_idx, } else { struct mesh_config_pub db_pub = { .virt = virt, - .addr = ota, + .addr = pub_dst, .idx = idx, .ttl = ttl, .credential = cred_flag, @@ -180,12 +163,12 @@ static void config_pub_set(struct mesh_node *node, uint16_t net_idx, /* Save model publication to config file */ if (!mesh_config_model_pub_add(node_config_get(node), ele_addr, vendor ? id : MODEL_ID(id), - vendor, &db_pub)) + vendor, &db_pub)) status = MESH_STATUS_STORAGE_FAIL; } - send_pub_status(node, net_idx, src, dst, status, ele_addr, id, ota, - idx, cred_flag, ttl, period, retransmit); + return set_pub_status(status, ele_addr, id, pub_dst, idx, cred_flag, + ttl, period, retransmit); } static uint16_t cfg_sub_get_msg(struct mesh_node *node, const uint8_t *pkt, @@ -667,14 +650,14 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx, if (!virt && (size != 11 && size != 13)) return true; - config_pub_set(node, net_idx, src, dst, pkt, virt, - size == 13 || size == 27); + n = config_pub_set(node, pkt, virt, size == 13 || size == 27); break; case OP_CONFIG_MODEL_PUB_GET: if (size != 4 && size != 6) return true; - config_pub_get(node, net_idx, src, dst, pkt, size); + + n = config_pub_get(node, pkt, size == 6); break; case OP_CONFIG_VEND_MODEL_SUB_GET: diff --git a/mesh/model.c b/mesh/model.c index 90192328f..c6ca0db47 100644 --- a/mesh/model.c +++ b/mesh/model.c @@ -1076,7 +1076,7 @@ bool mesh_model_send(struct mesh_node *node, uint16_t src, uint16_t dst, int mesh_model_pub_set(struct mesh_node *node, uint16_t addr, uint32_t id, const uint8_t *pub_addr, uint16_t idx, bool cred_flag, uint8_t ttl, uint8_t period, uint8_t retransmit, - bool is_virt, uint16_t *dst) + bool is_virt, uint16_t *pub_dst) { struct mesh_model *mod; int status, ele_idx = node_get_element_idx(node, addr); @@ -1103,6 +1103,9 @@ int mesh_model_pub_set(struct mesh_node *node, uint16_t addr, uint32_t id, return MESH_STATUS_SUCCESS; } + if (cred_flag && node_lpn_mode_get(node) != MESH_MODE_ENABLED) + return MESH_STATUS_FEATURE_NO_SUPPORT; + /* Check if the old publication destination is a virtual label */ if (mod->pub && mod->pub->virt) { unref_virt(mod->pub->virt); @@ -1116,7 +1119,7 @@ int mesh_model_pub_set(struct mesh_node *node, uint16_t addr, uint32_t id, status = set_virt_pub(mod, pub_addr, idx, cred_flag, ttl, period, retransmit); - *dst = mod->pub->addr; + *pub_dst = mod->pub->addr; if (status != MESH_STATUS_SUCCESS) return status; diff --git a/mesh/net.h b/mesh/net.h index 7117f1a47..2673b895a 100644 --- a/mesh/net.h +++ b/mesh/net.h @@ -32,8 +32,6 @@ struct mesh_node; #define CTL 0x80 -#define CREDFLAG_MASK 0x1000 - #define KEY_CACHE_SIZE 64 #define FRND_CACHE_MAX 32 From patchwork Fri Aug 7 01:38:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inga Stotland X-Patchwork-Id: 252903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1E1AC433DF for ; Fri, 7 Aug 2020 01:38:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D46020855 for ; Fri, 7 Aug 2020 01:38:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726202AbgHGBim (ORCPT ); Thu, 6 Aug 2020 21:38:42 -0400 Received: from mga18.intel.com ([134.134.136.126]:44001 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726049AbgHGBil (ORCPT ); Thu, 6 Aug 2020 21:38:41 -0400 IronPort-SDR: vQbbzfuBlVyfccbG1etcMX7RgamVILNBQT94snjHH+oWjAcZE3PND9bB0zfFhGhS42DjRnOT00 QTwnlUJCm5bQ== X-IronPort-AV: E=McAfee;i="6000,8403,9705"; a="140558044" X-IronPort-AV: E=Sophos;i="5.75,443,1589266800"; d="scan'208";a="140558044" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2020 18:38:41 -0700 IronPort-SDR: b4jZ3c9jq2K7PYNHGYvVE4GuMLlCr2vaFzOh2sccQ2PrU3fmHQ4x8nxY9QbTOD7/q7QlPlmlc0 gsv4/rEn/Enw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,443,1589266800"; d="scan'208";a="397442085" Received: from unknown (HELO ingas-nuc1.intel.com) ([10.254.119.50]) by fmsmga001.fm.intel.com with ESMTP; 06 Aug 2020 18:38:41 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ v5 06/10] mesh: Clean up handling of config relay messages Date: Thu, 6 Aug 2020 18:38:30 -0700 Message-Id: <20200807013834.123263-7-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200807013834.123263-1-inga.stotland@intel.com> References: <20200807013834.123263-1-inga.stotland@intel.com> MIME-Version: 1.0 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 | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c index 2797de8ab..8e3da79d5 100644 --- a/mesh/cfgmod-server.c +++ b/mesh/cfgmod-server.c @@ -396,6 +396,27 @@ static uint16_t model_app_bind(struct mesh_node *node, const uint8_t *pkt, return n; } +static uint16_t cfg_relay_msg(struct mesh_node *node, const uint8_t *pkt, + int opcode) +{ + uint8_t count; + uint16_t interval; + uint16_t n; + + if (opcode == OP_CONFIG_RELAY_SET) { + count = (pkt[1] & 0x7) + 1; + interval = ((pkt[1] >> 3) + 1) * 10; + node_relay_mode_set(node, !!pkt[0], count, interval); + } + + n = mesh_model_opcode_set(OP_CONFIG_RELAY_STATUS, msg); + + msg[n++] = node_relay_mode_get(node, &count, &interval); + msg[n++] = (count - 1) + ((interval/10 - 1) << 3); + + return n; +} + static void hb_pub_timeout_func(struct l_timeout *timeout, void *user_data) { struct mesh_net *net = user_data; @@ -775,22 +796,13 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx, case OP_CONFIG_RELAY_SET: if (size != 2 || pkt[0] > 0x01) return true; - - count = (pkt[1] & 0x7) + 1; - interval = ((pkt[1] >> 3) + 1) * 10; - node_relay_mode_set(node, !!pkt[0], count, interval); /* Fall Through */ case OP_CONFIG_RELAY_GET: if (opcode == OP_CONFIG_RELAY_GET && size != 0) return true; - n = mesh_model_opcode_set(OP_CONFIG_RELAY_STATUS, msg); - - msg[n++] = node_relay_mode_get(node, &count, &interval); - msg[n++] = (count - 1) + ((interval/10 - 1) << 3); - - l_debug("Get/Set Relay Config (%d)", msg[n-1]); + n = cfg_relay_msg(node, pkt, opcode); break; case OP_CONFIG_NETWORK_TRANSMIT_SET: From patchwork Fri Aug 7 01:38:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inga Stotland X-Patchwork-Id: 252902 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDE82C433E0 for ; Fri, 7 Aug 2020 01:38:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5F7B20855 for ; Fri, 7 Aug 2020 01:38:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726226AbgHGBio (ORCPT ); Thu, 6 Aug 2020 21:38:44 -0400 Received: from mga18.intel.com ([134.134.136.126]:44001 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726201AbgHGBim (ORCPT ); Thu, 6 Aug 2020 21:38:42 -0400 IronPort-SDR: B6W4LUokobmJ5obUoKf+X9khfQEd4nHt/H+LDJmohabGmzgMv0t5Xdl5xFP+FS34ueQlyy0H1t Yxun+m2DSNcg== X-IronPort-AV: E=McAfee;i="6000,8403,9705"; a="140558047" X-IronPort-AV: E=Sophos;i="5.75,443,1589266800"; d="scan'208";a="140558047" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2020 18:38:41 -0700 IronPort-SDR: 7DEo5aJlG/yNggW9YwePrDRfPi/596QvV/ldC363lNeMU771eW7lSz6GGFRc31NyRPhk+qEUbo U4SqfHzt1rZw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,443,1589266800"; d="scan'208";a="397442090" Received: from unknown (HELO ingas-nuc1.intel.com) ([10.254.119.50]) by fmsmga001.fm.intel.com with ESMTP; 06 Aug 2020 18:38:41 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ v5 07/10] mesh: Clean up handling of config poll timeout message Date: Thu, 6 Aug 2020 18:38:31 -0700 Message-Id: <20200807013834.123263-8-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200807013834.123263-1-inga.stotland@intel.com> References: <20200807013834.123263-1-inga.stotland@intel.com> MIME-Version: 1.0 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 | 34 +++++++++++++++++++++++----------- mesh/cfgmod.h | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c index 8e3da79d5..f3cc18ae0 100644 --- a/mesh/cfgmod-server.c +++ b/mesh/cfgmod-server.c @@ -643,6 +643,25 @@ static uint16_t cfg_get_appkeys_msg(struct mesh_node *node, const uint8_t *pkt) return n + 3 + sz; } +static uint16_t cfg_poll_timeout_msg(struct mesh_node *node, const uint8_t *pkt) +{ + uint16_t n, addr = l_get_le16(pkt); + uint32_t poll_to; + + if (!IS_UNICAST(addr)) + return 0; + + n = mesh_model_opcode_set(OP_CONFIG_POLL_TIMEOUT_STATUS, msg); + l_put_le16(addr, msg + n); + n += 2; + + poll_to = mesh_net_friend_timeout(node_get_net(node), addr); + msg[n++] = poll_to; + msg[n++] = poll_to >> 8; + msg[n++] = poll_to >> 16; + return n; +} + static uint16_t get_composition(struct mesh_node *node, uint8_t page, uint8_t *buf) { @@ -678,7 +697,7 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx, struct mesh_net *net; const uint8_t *pkt = data; struct timeval time_now; - uint32_t opcode, tmp32; + uint32_t opcode; int b_res = MESH_STATUS_SUCCESS; struct mesh_net_heartbeat *hb; uint16_t n_idx; @@ -1117,18 +1136,11 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx, msg[n++] = hb->sub_max_hops; break; - case OP_CONFIG_POLL_TIMEOUT_LIST: - if (size != 2 || l_get_le16(pkt) == 0 || - l_get_le16(pkt) > 0x7fff) + case OP_CONFIG_POLL_TIMEOUT_GET: + if (size != 2) return true; - n = mesh_model_opcode_set(OP_CONFIG_POLL_TIMEOUT_STATUS, msg); - l_put_le16(l_get_le16(pkt), msg + n); - n += 2; - tmp32 = mesh_net_friend_timeout(net, l_get_le16(pkt)); - msg[n++] = tmp32; - msg[n++] = tmp32 >> 8; - msg[n++] = tmp32 >> 16; + n = cfg_poll_timeout_msg(node, pkt); break; case OP_NODE_RESET: diff --git a/mesh/cfgmod.h b/mesh/cfgmod.h index 7b6a95807..6d73656a7 100644 --- a/mesh/cfgmod.h +++ b/mesh/cfgmod.h @@ -66,7 +66,7 @@ #define OP_CONFIG_MODEL_SUB_LIST 0x802A #define OP_CONFIG_VEND_MODEL_SUB_GET 0x802B #define OP_CONFIG_VEND_MODEL_SUB_LIST 0x802C -#define OP_CONFIG_POLL_TIMEOUT_LIST 0x802D +#define OP_CONFIG_POLL_TIMEOUT_GET 0x802D #define OP_CONFIG_POLL_TIMEOUT_STATUS 0x802E /* Health opcodes in health-mod.h */ #define OP_CONFIG_HEARTBEAT_PUB_GET 0x8038 From patchwork Fri Aug 7 01:38:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inga Stotland X-Patchwork-Id: 252901 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2B98C433E0 for ; Fri, 7 Aug 2020 01:38:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB93520855 for ; Fri, 7 Aug 2020 01:38:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726238AbgHGBip (ORCPT ); Thu, 6 Aug 2020 21:38:45 -0400 Received: from mga18.intel.com ([134.134.136.126]:44019 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726049AbgHGBin (ORCPT ); Thu, 6 Aug 2020 21:38:43 -0400 IronPort-SDR: LlFEVufB2rlM+AxlXgfEkUDZVwdDbL2n3pkRkM3131dQXSWNw5uTeDEZHuSq0oc/pI30gBpKCy 07nxbe0a6UsA== X-IronPort-AV: E=McAfee;i="6000,8403,9705"; a="140558050" X-IronPort-AV: E=Sophos;i="5.75,443,1589266800"; d="scan'208";a="140558050" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2020 18:38:43 -0700 IronPort-SDR: t4uVcoSKqelWuFm0deHcGzx3AKwsL/jB1yuMIYOVfbwMq9Z10Y6SV1B1G2SojXSa+s5bq/9O0A 9OJNVY6/+k4A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,443,1589266800"; d="scan'208";a="397442098" Received: from unknown (HELO ingas-nuc1.intel.com) ([10.254.119.50]) by fmsmga001.fm.intel.com with ESMTP; 06 Aug 2020 18:38:42 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ v5 09/10] mesh: Clean up handling of config KR phase messages Date: Thu, 6 Aug 2020 18:38:33 -0700 Message-Id: <20200807013834.123263-10-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200807013834.123263-1-inga.stotland@intel.com> References: <20200807013834.123263-1-inga.stotland@intel.com> MIME-Version: 1.0 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. Also, this checks for the correct relationship between KR transition and KR phase values. Correct error codes are sent on unsuccessful requests and malformed requests are ignored. --- mesh/cfgmod-server.c | 68 +++++++++++++++++++++++++++----------------- mesh/mesh-defs.h | 3 ++ mesh/net.c | 53 ++++++++++++---------------------- mesh/net.h | 4 +-- 4 files changed, 65 insertions(+), 63 deletions(-) diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c index 191c5b8ef..ea0741969 100644 --- a/mesh/cfgmod-server.c +++ b/mesh/cfgmod-server.c @@ -417,6 +417,43 @@ 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; + int status; + + n = mesh_model_opcode_set(OP_CONFIG_KEY_REFRESH_PHASE_STATUS, msg); + status = mesh_net_key_refresh_phase_get(net, idx, &phase); + + if (status == MESH_STATUS_SUCCESS && + opcode == OP_CONFIG_KEY_REFRESH_PHASE_SET) { + + if (pkt[2] == KEY_REFRESH_TRANS_TWO) { + if (phase == KEY_REFRESH_PHASE_TWO) + goto done; + else if (phase != KEY_REFRESH_PHASE_ONE) + return 0; + } + + status = mesh_net_key_refresh_phase_set(net, idx, pkt[2]); + l_debug("Set KR Phase: net=%3.3x transition=%d", idx, pkt[2]); + + if (status == MESH_STATUS_SUCCESS) + mesh_net_key_refresh_phase_get(net, idx, &phase); + } + +done: + msg[n] = status; + l_put_le16(idx, msg + n); + msg[n + 2] = (status != 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; @@ -723,8 +760,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; @@ -934,37 +970,17 @@ 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_TRANS_THREE && + pkt[2] != KEY_REFRESH_TRANS_TWO)) 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: diff --git a/mesh/mesh-defs.h b/mesh/mesh-defs.h index 5ade751a3..1a41e987b 100644 --- a/mesh/mesh-defs.h +++ b/mesh/mesh-defs.h @@ -36,6 +36,9 @@ #define KEY_REFRESH_PHASE_TWO 0x02 #define KEY_REFRESH_PHASE_THREE 0x03 +#define KEY_REFRESH_TRANS_TWO 0x02 +#define KEY_REFRESH_TRANS_THREE 0x03 + #define DEFAULT_TTL 0xff #define TTL_MASK 0x7f diff --git a/mesh/net.c b/mesh/net.c index b54c647cb..9b4454fee 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -2433,6 +2433,10 @@ static int key_refresh_phase_two(struct mesh_net *net, uint16_t idx) return MESH_STATUS_INVALID_NETKEY; l_debug("Key refresh procedure phase 2: start using new net TX keys"); + + if (subnet->kr_phase == KEY_REFRESH_PHASE_TWO) + return MESH_STATUS_SUCCESS; + subnet->key_refresh = 1; subnet->net_key_tx = subnet->net_key_upd; /* @@ -2445,8 +2449,9 @@ static int key_refresh_phase_two(struct mesh_net *net, uint16_t idx) l_queue_foreach(net->friends, frnd_kr_phase2, net); - mesh_config_net_key_set_phase(node_config_get(net->node), idx, - KEY_REFRESH_PHASE_TWO); + if (!mesh_config_net_key_set_phase(node_config_get(net->node), idx, + KEY_REFRESH_PHASE_TWO)) + return MESH_STATUS_STORAGE_FAIL; return MESH_STATUS_SUCCESS; } @@ -2479,8 +2484,9 @@ static int key_refresh_finish(struct mesh_net *net, uint16_t idx) l_queue_foreach(net->friends, frnd_kr_phase3, net); - mesh_config_net_key_set_phase(node_config_get(net->node), idx, - KEY_REFRESH_PHASE_NONE); + if (!mesh_config_net_key_set_phase(node_config_get(net->node), idx, + KEY_REFRESH_PHASE_NONE)) + return MESH_STATUS_STORAGE_FAIL; return MESH_STATUS_SUCCESS; } @@ -3168,45 +3174,22 @@ void mesh_net_transport_send(struct mesh_net *net, uint32_t key_id, send_msg_pkt(net, pkt, pkt_len + 1); } -uint8_t mesh_net_key_refresh_phase_set(struct mesh_net *net, uint16_t idx, +int mesh_net_key_refresh_phase_set(struct mesh_net *net, uint16_t idx, uint8_t transition) { - struct mesh_subnet *subnet; - - if (!net) - return MESH_STATUS_UNSPECIFIED_ERROR; - - subnet = l_queue_find(net->subnets, match_key_index, - L_UINT_TO_PTR(idx)); - if (!subnet) - return MESH_STATUS_INVALID_NETKEY; - - if (transition == subnet->kr_phase) - return MESH_STATUS_SUCCESS; + switch (transition) { + case KEY_REFRESH_TRANS_TWO: + return key_refresh_phase_two(net, idx); - if ((transition != 2 && transition != 3) || - transition < subnet->kr_phase) - return MESH_STATUS_CANNOT_SET; + case KEY_REFRESH_TRANS_THREE: + return key_refresh_finish(net, idx); - switch (transition) { - case 2: - if (key_refresh_phase_two(net, idx) - != MESH_STATUS_SUCCESS) - return MESH_STATUS_CANNOT_SET; - break; - case 3: - if (key_refresh_finish(net, idx) - != MESH_STATUS_SUCCESS) - return MESH_STATUS_CANNOT_SET; - break; default: - return MESH_STATUS_CANNOT_SET; + return MESH_STATUS_UNSPECIFIED_ERROR; } - - return MESH_STATUS_SUCCESS; } -uint8_t mesh_net_key_refresh_phase_get(struct mesh_net *net, uint16_t idx, +int mesh_net_key_refresh_phase_get(struct mesh_net *net, uint16_t idx, uint8_t *phase) { struct mesh_subnet *subnet; diff --git a/mesh/net.h b/mesh/net.h index 2673b895a..3d374280f 100644 --- a/mesh/net.h +++ b/mesh/net.h @@ -320,9 +320,9 @@ void mesh_friend_sub_add(struct mesh_net *net, uint16_t lpn, uint8_t ele_cnt, const uint8_t *list); void mesh_friend_sub_del(struct mesh_net *net, uint16_t lpn, uint8_t cnt, const uint8_t *del_list); -uint8_t mesh_net_key_refresh_phase_set(struct mesh_net *net, uint16_t net_idx, +int mesh_net_key_refresh_phase_set(struct mesh_net *net, uint16_t net_idx, uint8_t transition); -uint8_t mesh_net_key_refresh_phase_get(struct mesh_net *net, uint16_t net_idx, +int mesh_net_key_refresh_phase_get(struct mesh_net *net, uint16_t net_idx, uint8_t *phase); void mesh_net_send_seg(struct mesh_net *net, uint32_t key_id, uint32_t iv_index, uint8_t ttl, uint32_t seq,