Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp733865pxa; Wed, 12 Aug 2020 12:04:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzwAEEVFZVUYmYa21pdWXucmdVR+0mipECwtsxw5jSg3fSf7h0KCqkZIT62F+z1n6cxwE1 X-Received: by 2002:a17:906:37d1:: with SMTP id o17mr1345150ejc.98.1597259077926; Wed, 12 Aug 2020 12:04:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597259077; cv=none; d=google.com; s=arc-20160816; b=rFGEBHP9d/5s5f9jn6aZQAapuAFK3/x7zQG1GLw9B3w/wlEfczKst63kOOmDo8Dp3O tp6Zn5sFsKnhkr0Os5ZPPOPRY94bmJj738IwT3dMkE4Vgdl4bZRjvWyEsycNTP2WqxFl UTRhvoQUC2UjnLB9gfnXffATq0G9tSMYnZMbvVelY8sYBcxUaHo5Ejk1UZosxkSKzhNP JT4XbY1idSNwVQB5Jbo3sWl2DWrPvEDYkI6KJVrApYOeRdy7KcV4g3ITk5dzNsoxPwYn gY5+8Ik0K4NSVyetfkTBaXMAJ+jXD4MBM+0fkYwD+shmQMv9nP457Rm8532MSD4uo6EH kzXw== 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:ironport-sdr:ironport-sdr; bh=dIPGb4gMOPxhGTEVN1zV5RmkoNdqKBFmdV0rmMSZVZA=; b=ooXDsPy7edWu0dgOv0pv4u5pMpsKN8uLpcrHXCHFqgGeFa4rBX1a1hAJaYETXCFyso BSZd0uJmSwngkK+3BD9YvB+6Y8SJSLAJR979sxLDMg6gyAD9/3UGmq8DeAcN2TczCkT6 1jWGjcquGogA71APDe569RA5jB8kJ7PU022jlkIKO3lCcJoyFiRb/WRdvH/fWZsS8ho5 iMKY5djO4Yzo00c7Mifrbhn3DH7BLOyiegiwO+m06nS4K9/wOT+QXbRNsuy8c1nxZ4gU e+mOG8fuBAek6FnajDlUX1+Z+2Z8NQFYtLDhlnnUU8yxaYCl5/ilqu/gA0OgtjFB2g+v xw+g== 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 s15si1839928edy.237.2020.08.12.12.03.52; Wed, 12 Aug 2020 12:04:37 -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 S1726639AbgHLTDT (ORCPT + 99 others); Wed, 12 Aug 2020 15:03:19 -0400 Received: from mga02.intel.com ([134.134.136.20]:7248 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726512AbgHLTDT (ORCPT ); Wed, 12 Aug 2020 15:03:19 -0400 IronPort-SDR: xiFcWE0lHd+xYdGqEbn5TJPFULxUYdXZmZqV1Ng7xueaLnav29dqs6279TlyJISC/As/n/iEy4 EF2BNpXgYduQ== X-IronPort-AV: E=McAfee;i="6000,8403,9711"; a="141885366" X-IronPort-AV: E=Sophos;i="5.76,305,1592895600"; d="scan'208";a="141885366" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2020 12:03:18 -0700 IronPort-SDR: 5zmocYRBpVxRPPJJOx4wq4wTO2vnEA+HtzanBpcTTwi9pNkLpBvHZP/QM7SFeK3P0sHG1PDE+D qz73AgfLYUwQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,305,1592895600"; d="scan'208";a="295161208" Received: from vsriva1-mobl1.amr.corp.intel.com (HELO ingas-nuc1.intel.com) ([10.255.229.126]) by orsmga006.jf.intel.com with ESMTP; 12 Aug 2020 12:03:18 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, michal.lowas-rzechonek@silvair.com, Inga Stotland Subject: [PATCH BlueZ 1/2] mesh: Fix model ID prior to calling mesh config functions Date: Wed, 12 Aug 2020 12:03:16 -0700 Message-Id: <20200812190317.102140-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.2 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 Model IDs for SIG defined models need to be stripped off SIG_VENDOR value used for internal housekeeping prior to calling functions that save new model state in node configuration. Also, remove duplicate statements for model lookup in node config. --- mesh/mesh-config-json.c | 7 +------ mesh/model.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c index a40f92c01..086d618b1 100644 --- a/mesh/mesh-config-json.c +++ b/mesh/mesh-config-json.c @@ -169,11 +169,6 @@ static json_object *get_element_model(json_object *jnode, int ele_idx, size_t len; char buf[9]; - if (!vendor) - snprintf(buf, 5, "%4.4x", (uint16_t)mod_id); - else - snprintf(buf, 9, "%8.8x", mod_id); - if (!json_object_object_get_ex(jnode, "elements", &jelements)) return NULL; @@ -189,7 +184,7 @@ static json_object *get_element_model(json_object *jnode, int ele_idx, return NULL; if (!vendor) { - snprintf(buf, 5, "%4.4x", mod_id); + snprintf(buf, 5, "%4.4x", (uint16_t)mod_id); len = 4; } else { snprintf(buf, 9, "%8.8x", mod_id); diff --git a/mesh/model.c b/mesh/model.c index 23afb93a8..136edb194 100644 --- a/mesh/model.c +++ b/mesh/model.c @@ -628,6 +628,7 @@ 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 vendor; int ele_idx = node_get_element_idx(node, addr); if (ele_idx < 0) @@ -651,11 +652,15 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id, if (unbind ^ has_binding(mod->bindings, app_idx)) return MESH_STATUS_SUCCESS; + vendor = IS_VENDOR(id); + id = vendor ? id : MODEL_ID(id); + if (unbind) { model_unbind_idx(node, ele_idx, mod, app_idx); + if (!mesh_config_model_binding_del(node_config_get(node), - addr, IS_VENDOR(id), - id, app_idx)) + addr, vendor, id, + app_idx)) return MESH_STATUS_STORAGE_FAIL; l_debug("Unbind key %4.4x to model %8.8x", app_idx, mod->id); @@ -666,13 +671,12 @@ 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), addr, - IS_VENDOR(id), id, app_idx)) + vendor, id, app_idx)) return MESH_STATUS_STORAGE_FAIL; model_bind_idx(node, ele_idx, mod, app_idx); return MESH_STATUS_SUCCESS; - } static struct mesh_virtual *add_virtual(const uint8_t *v) -- 2.26.2