Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp7914794ybn; Mon, 30 Sep 2019 23:38:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2OuTvBp03g2oOMJYCLK+2QdoCLuRfqZ0vS3+2HaTevrTzeTBca6yKIB3ZAmz+d8O5aRem X-Received: by 2002:a50:fa9a:: with SMTP id w26mr23814958edr.227.1569911904855; Mon, 30 Sep 2019 23:38:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569911904; cv=none; d=google.com; s=arc-20160816; b=DWT5u5y3DOhGKUS1SJ6G/lEDa0Hnd15v64susmG1inSGbteZoyhz3GAJvH5rI+zj7o GhjKradoI2RrNpxpZid54Wk85rStXS97uIHpKak+8VNkFIq/nfnWWJ8o40n7rbeGvxY5 GqczCJCL4rqFR31Q4ibOwFxjzTccdCox2cMkoA+0fGECIg3caT3a80KpsKFrT3R35pow tkuRgT19ZZ3C0bXBQHBeZXLIxIv3jLhsee++WZZUFNQcJQu0+4ifj+v6jLcpehD21/Qh Iyp1zjLSid2Xc1gkX5GnCP+VnYC44zNM3PDWo/pe4+Mz0k/ouQjvkYgC815bCULJnRW1 xuIw== 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=VmJD2OujliUpfFl1Ac39/UlxcRe0CPK7AppQwb34yBg=; b=mMrDn/DbH2cBY8Oho0UkGOEMK8eBl3Tr9cSIMfO9K3HJsNXwhlR7Q/Kig8klkgT3Z5 XjcuRhNNEAGnP10D1IuYFKZ1h1lH0+ScPtg0Eg516NY1OakeQebcXRdUisJS0X10HZ9O QpnwsYjTibKfA0kpDPdiFaGAIw1CsRWmydA3itAxFCe2B76wBohuw730DzKwTprliBgp Fhc6/jP5j46MBnWzXPD/nzx48SqNbxLMWJWwIy2bqGGt+Nnw+4kxNRA29pb61GqZAh0V nDILjVCgrgYgPqdKx7vJFNIllR0aL4pPSnuDSWtW/8Vy6kDX7gLq1XAOH9mTXb35MgML FfXg== 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 w58si52334edc.312.2019.09.30.23.37.47; Mon, 30 Sep 2019 23:38:24 -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; 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 S1730309AbfJAGhM (ORCPT + 99 others); Tue, 1 Oct 2019 02:37:12 -0400 Received: from mga17.intel.com ([192.55.52.151]:4987 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726672AbfJAGhM (ORCPT ); Tue, 1 Oct 2019 02:37:12 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Sep 2019 23:37:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,570,1559545200"; d="scan'208";a="342887857" Received: from ingas-nuc1.sea.intel.com ([10.254.103.206]) by orsmga004.jf.intel.com with ESMTP; 30 Sep 2019 23:37:09 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ] mesh: Make mesh-config API more consistent Date: Mon, 30 Sep 2019 23:37:08 -0700 Message-Id: <20191001063708.8279-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.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 changes the prototypes for mesh_config_model_binding_add() and mesh_config_model_binding_del() to take the element's address as input parameter instead of the element's index. The change aligns the API with other functions that handle storage of model states. --- mesh/mesh-config-json.c | 34 ++++++++++++++++++++++------------ mesh/mesh-config.h | 11 ++++++----- mesh/model.c | 7 ++----- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c index cafa2fdd7..4fe05a802 100644 --- a/mesh/mesh-config-json.c +++ b/mesh/mesh-config-json.c @@ -835,11 +835,12 @@ bool mesh_config_app_key_del(struct mesh_config *cfg, uint16_t net_idx, return save_config(jnode, cfg->node_dir_path); } -bool mesh_config_model_binding_add(struct mesh_config *cfg, uint8_t ele_idx, - bool vendor, uint32_t mod_id, +bool mesh_config_model_binding_add(struct mesh_config *cfg, uint16_t ele_addr, + bool vendor, uint32_t mod_id, uint16_t app_idx) { json_object *jnode, *jmodel, *jstring, *jarray = NULL; + int ele_idx; char buf[5]; if (!cfg) @@ -847,6 +848,10 @@ bool mesh_config_model_binding_add(struct mesh_config *cfg, uint8_t ele_idx, jnode = cfg->jnode; + ele_idx = get_element_index(jnode, ele_addr); + if (ele_idx < 0) + return false; + jmodel = get_element_model(jnode, ele_idx, mod_id, vendor); if (!jmodel) return false; @@ -875,11 +880,12 @@ bool mesh_config_model_binding_add(struct mesh_config *cfg, uint8_t ele_idx, return save_config(jnode, cfg->node_dir_path); } -bool mesh_config_model_binding_del(struct mesh_config *cfg, uint8_t ele_idx, - bool vendor, uint32_t mod_id, +bool mesh_config_model_binding_del(struct mesh_config *cfg, uint8_t ele_addr, + bool vendor, uint32_t mod_id, uint16_t app_idx) { json_object *jnode, *jmodel, *jarray, *jarray_new; + int ele_idx; char buf[5]; if (!cfg) @@ -887,6 +893,10 @@ bool mesh_config_model_binding_del(struct mesh_config *cfg, uint8_t ele_idx, jnode = cfg->jnode; + ele_idx = get_element_index(jnode, ele_addr); + if (ele_idx < 0) + return false; + jmodel = get_element_model(jnode, ele_idx, mod_id, vendor); if (!jmodel) return false; @@ -1818,7 +1828,7 @@ bool mesh_config_net_key_set_phase(struct mesh_config *cfg, uint16_t idx, return save_config(jnode, cfg->node_dir_path); } -bool mesh_config_model_pub_add(struct mesh_config *cfg, uint16_t addr, +bool mesh_config_model_pub_add(struct mesh_config *cfg, uint16_t ele_addr, uint32_t mod_id, bool vendor, struct mesh_config_pub *pub) { @@ -1831,7 +1841,7 @@ bool mesh_config_model_pub_add(struct mesh_config *cfg, uint16_t addr, jnode = cfg->jnode; - ele_idx = get_element_index(jnode, addr); + ele_idx = get_element_index(jnode, ele_addr); if (ele_idx < 0) return false; @@ -1886,13 +1896,13 @@ fail: return false; } -static bool delete_model_property(json_object *jnode, uint16_t addr, +static bool delete_model_property(json_object *jnode, uint16_t ele_addr, uint32_t mod_id, bool vendor, const char *keyword) { json_object *jmodel; int ele_idx; - ele_idx = get_element_index(jnode, addr); + ele_idx = get_element_index(jnode, ele_addr); if (ele_idx < 0) return false; @@ -1915,7 +1925,7 @@ bool mesh_config_model_pub_del(struct mesh_config *cfg, uint16_t addr, return save_config(cfg->jnode, cfg->node_dir_path); } -bool mesh_config_model_sub_add(struct mesh_config *cfg, uint16_t addr, +bool mesh_config_model_sub_add(struct mesh_config *cfg, uint16_t ele_addr, uint32_t mod_id, bool vendor, struct mesh_config_sub *sub) { @@ -1928,7 +1938,7 @@ bool mesh_config_model_sub_add(struct mesh_config *cfg, uint16_t addr, jnode = cfg->jnode; - ele_idx = get_element_index(jnode, addr); + ele_idx = get_element_index(jnode, ele_addr); if (ele_idx < 0) return false; @@ -1966,7 +1976,7 @@ bool mesh_config_model_sub_add(struct mesh_config *cfg, uint16_t addr, return save_config(jnode, cfg->node_dir_path); } -bool mesh_config_model_sub_del(struct mesh_config *cfg, uint16_t addr, +bool mesh_config_model_sub_del(struct mesh_config *cfg, uint16_t ele_addr, uint32_t mod_id, bool vendor, struct mesh_config_sub *sub) { @@ -1979,7 +1989,7 @@ bool mesh_config_model_sub_del(struct mesh_config *cfg, uint16_t addr, jnode = cfg->jnode; - ele_idx = get_element_index(jnode, addr); + ele_idx = get_element_index(jnode, ele_addr); if (ele_idx < 0) return false; diff --git a/mesh/mesh-config.h b/mesh/mesh-config.h index cf1f8b299..595e53b3a 100644 --- a/mesh/mesh-config.h +++ b/mesh/mesh-config.h @@ -104,6 +104,7 @@ struct mesh_config_node { uint8_t dev_key[16]; uint8_t token[8]; }; + typedef void (*mesh_config_status_func_t)(void *user_data, bool result); typedef bool (*mesh_config_node_func_t)(struct mesh_config_node *node, const uint8_t uuid[16], @@ -136,10 +137,10 @@ bool mesh_config_write_relay_mode(struct mesh_config *cfg, uint8_t mode, bool mesh_config_write_ttl(struct mesh_config *cfg, uint8_t ttl); bool mesh_config_write_mode(struct mesh_config *cfg, const char *keyword, int value); -bool mesh_config_model_binding_add(struct mesh_config *cfg, uint8_t ele_idx, +bool mesh_config_model_binding_add(struct mesh_config *cfg, uint16_t ele_addr, bool vendor, uint32_t mod_id, uint16_t app_idx); -bool mesh_config_model_binding_del(struct mesh_config *cfg, uint8_t ele_idx, +bool mesh_config_model_binding_del(struct mesh_config *cfg, uint8_t ele_addr, bool vendor, uint32_t mod_id, uint16_t app_idx); bool mesh_config_model_pub_add(struct mesh_config *cfg, uint16_t ele_addr, @@ -147,13 +148,13 @@ bool mesh_config_model_pub_add(struct mesh_config *cfg, uint16_t ele_addr, struct mesh_config_pub *pub); bool mesh_config_model_pub_del(struct mesh_config *cfg, uint16_t ele_addr, uint32_t mod_id, bool vendor); -bool mesh_config_model_sub_add(struct mesh_config *cfg, uint16_t addr, +bool mesh_config_model_sub_add(struct mesh_config *cfg, uint16_t ele_addr, uint32_t mod_id, bool vendor, struct mesh_config_sub *sub); -bool mesh_config_model_sub_del(struct mesh_config *cfg, uint16_t addr, +bool mesh_config_model_sub_del(struct mesh_config *cfg, uint16_t ele_addr, uint32_t mod_id, bool vendor, struct mesh_config_sub *sub); -bool mesh_config_model_sub_del_all(struct mesh_config *cfg, uint16_t addr, +bool mesh_config_model_sub_del_all(struct mesh_config *cfg, uint16_t ele_addr, uint32_t mod_id, bool vendor); bool mesh_config_app_key_add(struct mesh_config *cfg, uint16_t net_idx, uint16_t app_idx, const uint8_t key[16]); diff --git a/mesh/model.c b/mesh/model.c index a06b684a5..f4b856108 100644 --- a/mesh/model.c +++ b/mesh/model.c @@ -561,7 +561,6 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id, int status; struct mesh_model *mod; bool is_present, is_vendor; - uint8_t ele_idx; mod = find_model(node, addr, id, &status); if (!mod) { @@ -586,12 +585,10 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id, if (is_present && !unbind) return MESH_STATUS_SUCCESS; - ele_idx = (uint8_t) node_get_element_idx(node, addr); - if (unbind) { model_unbind_idx(node, mod, app_idx); if (!mesh_config_model_binding_del(node_config_get(node), - ele_idx, is_vendor, id, app_idx)) + addr, is_vendor, id, app_idx)) return MESH_STATUS_STORAGE_FAIL; return MESH_STATUS_SUCCESS; @@ -601,7 +598,7 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id, return MESH_STATUS_INSUFF_RESOURCES; if (!mesh_config_model_binding_add(node_config_get(node), - ele_idx, is_vendor, id, app_idx)) + addr, is_vendor, id, app_idx)) return MESH_STATUS_STORAGE_FAIL; model_bind_idx(node, mod, app_idx); -- 2.21.0