Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1861109pxa; Thu, 6 Aug 2020 18:39:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDFddlahqNpfHV7s8RREXfmiM/Fzk2n01yzjSPMuiUHuuTmX/dpDaN2l3MifuT2TECFiiO X-Received: by 2002:a17:906:600f:: with SMTP id o15mr6875432ejj.529.1596764363472; Thu, 06 Aug 2020 18:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596764363; cv=none; d=google.com; s=arc-20160816; b=iSq/50bQfhR/XE7rvr5hLg2EIpa3mH6iZuaCBE8dRmxEu0HvAUpIIdZNDVzajqDKcZ 6xwJ7f8KYyH2JgFbyhUBcALGHa4csiCf1qoX7c7JGNEVLz+VK49KGFkEpotQYD+s0kU8 pabunSQd7wGrE4/YjPcUBe1Rz8tzNKGMDfCXehzgNKLOogKI2LKhrIBiYPjOZ/CLuH3r IRaExHZJb7QGUWWkZT8yfLxLQ8LYfBkd6HjqDck/1WYH2nnG8xHIV70d9ahuD3qV0Fgy oZsBVw/k9aONMFH35bJ7+23Y++oSwb2oqYR0MBAAEcKVWZmLubmSrD2bpk5sguZkjEYI 0Rxg== 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=vk3LtClC9raniuemI6QPZztptGJVfsdrRA+ptTZizvQ=; b=Ren50j9eBbzRU3g7aSVdYG2s4jR4XC9lJl0UUPHX8HmX9yDwSrSBonLVYNkROuq7+t dE9PsfbtP16NNS61Z9t49TIuTSFS4Q7So0kIyDbUx27mWQ0qQUvbvw0inky0ng82OiTu cjrkLNjWxd6i9P79WVnyk/lcxoxB2FmWAF2vrYWMTFPlRFoHvAGeMbLnZkltiI6H+wN1 NGI+6RSMTeDfO6fJ5mbFkSgpdUY4gZbvqQjnzO8aT/GDXuw8ug+mybYkT37Jb0VR/IP1 +geRLq536YrZQ0L3HK1ztmWueqYeBwvkd+a6/Gq4McLvT0phZcgkbzG2sFUiwthxertv u3sQ== 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 q2si4425944edn.377.2020.08.06.18.38.47; Thu, 06 Aug 2020 18:39:23 -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 S1726198AbgHGBim (ORCPT + 99 others); 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 S1726055AbgHGBil (ORCPT ); Thu, 6 Aug 2020 21:38:41 -0400 IronPort-SDR: 20VQxvOQKB9lmPCP++Kwmj2QoYb+PiuACJm2YK93i+kgWmersfuUv3C8H6CXfeRuOgW/8l23iU EhEC4VeasN7Q== X-IronPort-AV: E=McAfee;i="6000,8403,9705"; a="140558042" X-IronPort-AV: E=Sophos;i="5.75,443,1589266800"; d="scan'208";a="140558042" 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: ciAcmXg7ns3jkrU8LZSFKvvTUkIWhSuEKautbb0W7K7oBtP1QKYjQ0ZlurvlPLha7T64Z1APRb 4nPcP3Hv0ogw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,443,1589266800"; d="scan'208";a="397442082" Received: from unknown (HELO ingas-nuc1.intel.com) ([10.254.119.50]) by fmsmga001.fm.intel.com with ESMTP; 06 Aug 2020 18:38:40 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ v5 05/10] mesh: Clean up handling of config net and app key messages Date: Thu, 6 Aug 2020 18:38:29 -0700 Message-Id: <20200807013834.123263-6-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 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 | 155 +++++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 72 deletions(-) diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c index 6ed5800c0..2797de8ab 100644 --- a/mesh/cfgmod-server.c +++ b/mesh/cfgmod-server.c @@ -547,6 +547,81 @@ static void node_reset(void *user_data) node_remove(node); } +static uint16_t cfg_appkey_msg(struct mesh_node *node, const uint8_t *pkt, + int opcode) +{ + uint16_t n_idx, a_idx, n; + struct mesh_net *net = node_get_net(node); + + n_idx = l_get_le16(pkt) & 0xfff; + if (n_idx > NET_IDX_MAX) + return 0; + + a_idx = l_get_le16(pkt + 1) >> 4; + if (a_idx > APP_IDX_MAX) + return 0; + + n = mesh_model_opcode_set(OP_APPKEY_STATUS, msg); + + if (opcode == OP_APPKEY_ADD) + msg[n] = appkey_key_add(net, n_idx, a_idx, pkt + 3); + else if (opcode == OP_APPKEY_UPDATE) + msg[n] = appkey_key_update(net, n_idx, a_idx, pkt + 3); + else + msg[n] = appkey_key_delete(net, n_idx, a_idx); + + l_debug("AppKey Command %s: Net_Idx %3.3x, App_Idx %3.3x", + (msg[n] == MESH_STATUS_SUCCESS) ? "success" : "fail", + n_idx, a_idx); + + memcpy(msg + n + 1, &pkt[0], 3); + + return n + 4; +} + +static uint16_t cfg_netkey_msg(struct mesh_node *node, const uint8_t *pkt, + int opcode) +{ + uint16_t n_idx, n; + struct mesh_net *net = node_get_net(node); + + n_idx = l_get_le16(pkt); + if (n_idx > NET_IDX_MAX) + return 0; + + n = mesh_model_opcode_set(OP_NETKEY_STATUS, msg); + + if (opcode == OP_NETKEY_ADD) + msg[n] = mesh_net_add_key(net, n_idx, pkt + 2); + else if (opcode == OP_NETKEY_UPDATE) + msg[n] = mesh_net_update_key(net, n_idx, pkt + 2); + else + msg[n] = mesh_net_del_key(net, n_idx); + + l_debug("NetKey Command %s: Net_Idx %3.3x", + (msg[n] == MESH_STATUS_SUCCESS) ? "success" : "fail", + n_idx); + + memcpy(msg + n + 1, &pkt[0], 2); + + return n + 3; +} + +static uint16_t cfg_get_appkeys_msg(struct mesh_node *node, const uint8_t *pkt) +{ + uint16_t n_idx, sz, n; + + n_idx = l_get_le16(pkt); + + n = mesh_model_opcode_set(OP_APPKEY_LIST, msg); + l_put_le16(n_idx, msg + n + 1); + + msg[n] = appkey_list(node_get_net(node), n_idx, msg + n + 3, + MAX_MSG_LEN - (n + 3), &sz); + + return n + 3 + sz; +} + static uint16_t get_composition(struct mesh_node *node, uint8_t page, uint8_t *buf) { @@ -585,7 +660,7 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx, uint32_t opcode, tmp32; int b_res = MESH_STATUS_SUCCESS; struct mesh_net_heartbeat *hb; - uint16_t n_idx, a_idx; + uint16_t n_idx; uint8_t state, status; uint8_t phase; bool virt = false; @@ -858,60 +933,19 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx, if (size != 19) return true; - n_idx = l_get_le16(pkt) & 0xfff; - a_idx = l_get_le16(pkt + 1) >> 4; - - if (opcode == OP_APPKEY_ADD) - b_res = appkey_key_add(net, n_idx, a_idx, pkt + 3); - else - b_res = appkey_key_update(net, n_idx, a_idx, - pkt + 3); - - l_debug("Add/Update AppKey %s: Net_Idx %3.3x, App_Idx %3.3x", - (b_res == MESH_STATUS_SUCCESS) ? "success" : "fail", - n_idx, a_idx); - - - n = mesh_model_opcode_set(OP_APPKEY_STATUS, msg); - - msg[n++] = b_res; - msg[n++] = pkt[0]; - msg[n++] = pkt[1]; - msg[n++] = pkt[2]; - break; - + /* Fall Through */ case OP_APPKEY_DELETE: - if (size != 3) + if (opcode == OP_APPKEY_DELETE && size != 3) return true; - n_idx = l_get_le16(pkt) & 0xfff; - a_idx = l_get_le16(pkt + 1) >> 4; - b_res = appkey_key_delete(net, n_idx, a_idx); - l_debug("Delete AppKey %s Net_Idx %3.3x to App_Idx %3.3x", - (b_res == MESH_STATUS_SUCCESS) ? "success" : "fail", - n_idx, a_idx); - - n = mesh_model_opcode_set(OP_APPKEY_STATUS, msg); - msg[n++] = b_res; - msg[n++] = pkt[0]; - msg[n++] = pkt[1]; - msg[n++] = pkt[2]; + n = cfg_appkey_msg(node, pkt, opcode); break; case OP_APPKEY_GET: if (size != 2) return true; - n_idx = l_get_le16(pkt); - - n = mesh_model_opcode_set(OP_APPKEY_LIST, msg); - - status = appkey_list(net, n_idx, msg + n + 3, - MAX_MSG_LEN - n - 3, &size); - - msg[n] = status; - l_put_le16(n_idx, msg + n + 1); - n += (size + 3); + n = cfg_get_appkeys_msg(node, pkt); break; case OP_NETKEY_ADD: @@ -919,35 +953,12 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx, if (size != 18) return true; - n_idx = l_get_le16(pkt); - - if (opcode == OP_NETKEY_ADD) - b_res = mesh_net_add_key(net, n_idx, pkt + 2); - else - b_res = mesh_net_update_key(net, n_idx, pkt + 2); - - l_debug("NetKey Add/Update %s", - (b_res == MESH_STATUS_SUCCESS) ? "success" : "fail"); - - n = mesh_model_opcode_set(OP_NETKEY_STATUS, msg); - msg[n++] = b_res; - l_put_le16(l_get_le16(pkt), msg + n); - n += 2; - break; - + /* Fall Through */ case OP_NETKEY_DELETE: - if (size != 2) + if (opcode == OP_NETKEY_DELETE && size != 2) return true; - b_res = mesh_net_del_key(net, l_get_le16(pkt)); - - l_debug("NetKey delete %s", - (b_res == MESH_STATUS_SUCCESS) ? "success" : "fail"); - - n = mesh_model_opcode_set(OP_NETKEY_STATUS, msg); - msg[n++] = b_res; - l_put_le16(l_get_le16(pkt), msg + n); - n += 2; + n = cfg_netkey_msg(node, pkt, opcode); break; case OP_NETKEY_GET: -- 2.26.2