Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp142047ybl; Fri, 17 Jan 2020 20:25:14 -0800 (PST) X-Google-Smtp-Source: APXvYqxWOriaX2IuOzugNSi2Lk5H2afPIwcOlSKjx6eGDiCil8VDV3MY/iLTUgFzO7tgtYQonjzp X-Received: by 2002:a54:4e08:: with SMTP id a8mr6041077oiy.77.1579321514387; Fri, 17 Jan 2020 20:25:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579321514; cv=none; d=google.com; s=arc-20160816; b=Vmdohnn++tI0h3ma5nA+XmRMvoRKLUUZ/rqsXVWRC6eoMymD0wyi3HixwESQ/0jfTW 0wQr8xulpJiepChuVgwhVNgTZROCUU+hoBZJnEW7hSACSi4m63dO8vs2IfdcCpn0az0P GSipQAgj//9cLRz/B/7+Qwn0a1B98n6ywvsiyCv1RzRWwIkaoDdq8RIeya8S4talxvYI E6NwBebiCzB1ef8XhnstunLMqhEjeSkNpHOEoE9equwP6y66UtguW2wTV3NmrJULxKuZ je/8icSw3P/LULwG3ZYltDb8W1kcb/VzMdoyeEOCQasflo6BsHhrOeWR8d2LPh9y1dA6 0G/g== 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; bh=haT2R555Cabh3Au2dH2evn3NALGTMdQVivfR1ffuNLw=; b=09/2rDYSoio6yYGYe+fNm+S/SJQAjHTskFwcF9zZ4TjA1TZMYYb5hEL3gqLf/S1kPn siETArtoVOZOv6hWs1BWSSaEtS26bauB+tGaZtukB61vPlNDdqYg4nZqXvzobCtCeH62 MkdNZwYo0huFosHwEhD0j70jtRE9lfiWlpcoHEKXsXxioihFNQ7A9kEaU0IwlxEP184j sFB9kJ7aA3I19HVfeMdkAr61GgIA7LSc9LnMBP1yqeKRpSx6wc4DlIpepRgVCLMgTqff vKXIHF5K8hocMIP6712wt+slZPrAoch89RXkg/aJbidCexZzBJz7YVr//d5p9ntGk4ZA 9bNg== 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 b25si15804132otp.212.2020.01.17.20.25.03; Fri, 17 Jan 2020 20:25:14 -0800 (PST) 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 S1726566AbgAREWg (ORCPT + 99 others); Fri, 17 Jan 2020 23:22:36 -0500 Received: from mga11.intel.com ([192.55.52.93]:11361 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726896AbgAREWf (ORCPT ); Fri, 17 Jan 2020 23:22:35 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jan 2020 20:22:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,332,1574150400"; d="scan'208";a="220926440" Received: from ingas-nuc1.sea.intel.com ([10.251.138.89]) by fmsmga008.fm.intel.com with ESMTP; 17 Jan 2020 20:22:35 -0800 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ 1/4] tools/mesh: Refactor code for generating model ID Date: Fri, 17 Jan 2020 20:22:30 -0800 Message-Id: <20200118042233.15338-2-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200118042233.15338-1-inga.stotland@intel.com> References: <20200118042233.15338-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 Common code for populating message buffer with Model ID (either SIG or vendor defined) for misc commands is refactored into a single function. --- tools/mesh/cfgcli.c | 61 +++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/tools/mesh/cfgcli.c b/tools/mesh/cfgcli.c index 50d2ce706..23fca4df6 100644 --- a/tools/mesh/cfgcli.c +++ b/tools/mesh/cfgcli.c @@ -240,11 +240,11 @@ static void add_request(uint32_t opcode) l_queue_push_tail(requests, req); } -static uint32_t print_mod_id(uint8_t *data, bool vid, const char *offset) +static uint32_t print_mod_id(uint8_t *data, bool vendor, const char *offset) { uint32_t mod_id; - if (!vid) { + if (!vendor) { mod_id = get_le16(data); bt_shell_printf("%sModel Id\t%4.4x\n", offset, mod_id); mod_id = VENDOR_ID_MASK | mod_id; @@ -691,6 +691,21 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, return true; } +static uint16_t put_model_id(uint8_t *buf, uint32_t *args, bool vendor) +{ + uint16_t n = 2; + + if (vendor) { + put_le16(args[1], buf); + buf += 2; + n = 4; + } + + put_le16(args[0], buf); + + return n; +} + static uint32_t read_input_parameters(int argc, char *argv[]) { uint32_t i; @@ -973,14 +988,7 @@ static void cmd_bind(uint32_t opcode, int argc, char *argv[]) put_le16(parms[1], msg + n); n += 2; - if (parm_cnt == 4) { - put_le16(parms[3], msg + n); - put_le16(parms[2], msg + n + 2); - n += 4; - } else { - put_le16(parms[2], msg + n); - n += 2; - } + n += put_model_id(msg + n, &parms[2], parm_cnt == 4); if (!config_send(msg, n, opcode)) return bt_shell_noninteractive_quit(EXIT_FAILURE); @@ -1178,14 +1186,7 @@ static void cmd_pub_set(int argc, char *argv[]) msg[n++] = parms[4]; /* Model Id */ - if (parm_cnt == 7) { - put_le16(parms[6], msg + n); - put_le16(parms[5], msg + n + 2); - n += 4; - } else { - put_le16(parms[5], msg + n); - n += 2; - } + n += put_model_id(msg + n, &parms[5], parm_cnt == 7); if (!config_send(msg, n, OP_CONFIG_MODEL_PUB_SET)) return bt_shell_noninteractive_quit(EXIT_FAILURE); @@ -1212,14 +1213,7 @@ static void cmd_pub_get(int argc, char *argv[]) n += 2; /* Model Id */ - if (parm_cnt == 3) { - put_le16(parms[2], msg + n); - put_le16(parms[1], msg + n + 2); - n += 4; - } else { - put_le16(parms[1], msg + n); - n += 2; - } + n += put_model_id(msg + n, &parms[1], parm_cnt == 3); if (!config_send(msg, n, OP_CONFIG_MODEL_PUB_GET)) return bt_shell_noninteractive_quit(EXIT_FAILURE); @@ -1497,21 +1491,22 @@ static const struct bt_shell_menu cfg_menu = { "Delete AppKey"}, {"appkey-get", "", cmd_appkey_get, "List AppKeys bound to the NetKey"}, - {"bind", " [vendor_id]", cmd_add_binding, + {"bind", " [vendor_id]", cmd_add_binding, "Bind AppKey to a model"}, - {"unbind", " [vendor_id]", cmd_del_binding, + {"unbind", " [vendor_id]", + cmd_del_binding, "Remove AppKey from a model"}, - {"mod-appidx-get", " ", cmd_mod_appidx_get, + {"mod-appidx-get", " ", cmd_mod_appidx_get, "Get model app_idx"}, {"ttl-set", "", cmd_ttl_set, "Set default TTL"}, {"ttl-get", NULL, cmd_ttl_get, "Get default TTL"}, {"pub-set", " " - " [vendor_id]", + " [vendor_id]", cmd_pub_set, "Set publication"}, - {"pub-get", " ", cmd_pub_get, + {"pub-get", " [vendor_id]", cmd_pub_get, "Get publication"}, {"proxy-set", "", cmd_proxy_set, "Set proxy state"}, @@ -1546,9 +1541,9 @@ static const struct bt_shell_menu cfg_menu = { "Set heartbeat subscribe"}, {"hb-sub-get", NULL, cmd_hb_sub_get, "Get heartbeat subscribe"}, - {"sub-add", " ", cmd_sub_add, + {"sub-add", " ", cmd_sub_add, "Add subscription"}, - {"sub-get", " ", cmd_sub_get, + {"sub-get", " ", cmd_sub_get, "Get subscription"}, {"node-reset", NULL, cmd_node_reset, "Reset a node and remove it from network"}, -- 2.21.1