Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp184727ybj; Wed, 6 May 2020 14:45:43 -0700 (PDT) X-Google-Smtp-Source: APiQypKpR6HjjOq52RqLjFB8I0zC3bAyGc9QkXzfqKXIs5uaiYbA3EpyUOt+a2K1wO7ke5VbXwVR X-Received: by 2002:a17:906:4993:: with SMTP id p19mr8936935eju.67.1588801542794; Wed, 06 May 2020 14:45:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588801542; cv=none; d=google.com; s=arc-20160816; b=k7PwhMxA66E8Iwg3YkGeAWvegGRoHWY8/Szp/C15iCcIBh/lV4dSUtRtC+Wzk9F2xn iQsV9luGGZ300LD6GgvNtFo8+fZmPdlrEBqKuCFRFysVx2lo8GY91WC13jEHe5EjiuAv qTOVyTchzQqhX3w8TitbbemzO6BsFtLSM+adp95FgORzcDBEM0HDQpRQjRETqPK+y14m IQBv56qx5gJ7w36K6G66EzHAoumHeylagMGLQsMdgX+oiUD/Qb1SnTIfJRH9ZjyUiUZ7 wFpiY3JaMcmuj5jqTf11uUyTlTylkbKsudAWM3cPQd3qfgAY/fA0BrlZ0EFok27k5nyd ugqA== 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=u3nKNJESrUWVTBy9RR5uq2aH/WkADEVCI3cVj+hxgaY=; b=MBqfrXF9fCJKxumQzttik0D8UBrsp7ZpVgIhcGGPbLhe69jUmMvifusO3OjkWTXOtj twY5b7ud58GbOCKGiFAYhp1Un7t08LFUgqb6zkLI0wtDMiYHZW3bEYPf4TDhb1pyn/2v 4y/9xOCKUNXQkORqIt9FFsUlax+YvypJppMn3SmTjUH0P+M5sHNwhNsoFTlvtWXlncea ZZTYHj56ETqU60F2rUk19/xDxDTCdo6BZ6F1RRT+tzqLtWrWbwNTvDSLWHJwYpiDfcWz GOBjeRJyjJkQGY9umH7ihGcPoB0xutBieStoMPLvuiAlcaaF1pZ1kTI3VGuQx0jO47TI Wwig== 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 h20si1972017eds.141.2020.05.06.14.44.59; Wed, 06 May 2020 14:45:42 -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 S1729268AbgEFVo4 (ORCPT + 99 others); Wed, 6 May 2020 17:44:56 -0400 Received: from mga01.intel.com ([192.55.52.88]:10221 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729261AbgEFVo4 (ORCPT ); Wed, 6 May 2020 17:44:56 -0400 IronPort-SDR: YZx4PuzIEIUtTILrygoHeZnUzUEaMRGIMhdpVuojbJgOW2KkLd0WSvqobpJRujQx2y/kxKXMoK JDEcSOciM4xg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2020 14:44:55 -0700 IronPort-SDR: zLsMMjFxuhiOwA2RN34B239GzAEpzNFEuJytMZQuQxbq8GTV5WAM8BplmqPtUbXY1NDGhhx4M7 xC6XRSZBG/Jg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,360,1583222400"; d="scan'208";a="435046069" Received: from ingas-nuc1.sea.intel.com ([10.254.112.165]) by orsmga005.jf.intel.com with ESMTP; 06 May 2020 14:44:55 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ v3] tools/mesh-cfgclient: Fix model app list parsing Date: Wed, 6 May 2020 14:44:49 -0700 Message-Id: <20200506214449.20099-1-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.1 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 fixes parsing of Model AppKey List & Vendor Model Appkey List messages: taking into account the packt that AppKey indices are parked two in three octets. Also, when printing key indices, print in both decimal and hexadecimal formats. --- tools/mesh-cfgclient.c | 6 ++-- tools/mesh/cfgcli.c | 80 ++++++++++++++++++++++++++---------------- tools/mesh/keys.c | 6 ++-- tools/mesh/remote.c | 6 ++-- 4 files changed, 59 insertions(+), 39 deletions(-) diff --git a/tools/mesh-cfgclient.c b/tools/mesh-cfgclient.c index d7318ffb7..fe82a8bbe 100644 --- a/tools/mesh-cfgclient.c +++ b/tools/mesh-cfgclient.c @@ -338,12 +338,14 @@ static bool send_key(void *user_data, uint16_t dst, uint16_t key_idx, } if (!is_appkey && !keys_subnet_exists(key_idx)) { - bt_shell_printf("Local NetKey %u not found\n", key_idx); + bt_shell_printf("Local NetKey %u (0x%3.3x) not found\n", + key_idx, key_idx); return false; } if (is_appkey && (keys_get_bound_key(key_idx) == NET_IDX_INVALID)) { - bt_shell_printf("Local AppKey %u not found\n", key_idx); + bt_shell_printf("Local AppKey %u (0x%3.3x) not found\n", + key_idx, key_idx); return false; } diff --git a/tools/mesh/cfgcli.c b/tools/mesh/cfgcli.c index d9f1c9b72..b96c6c9e6 100644 --- a/tools/mesh/cfgcli.c +++ b/tools/mesh/cfgcli.c @@ -351,7 +351,8 @@ static void print_pub(uint16_t ele_addr, uint32_t mod_id, bt_shell_printf("\tModel: %4.4x\n", (uint16_t) (mod_id & 0xffff)); - bt_shell_printf("\tApp Key Idx: %4.4x\n", pub->app_idx); + bt_shell_printf("\tApp Key Idx: %u (0x%3.3x)\n", pub->app_idx, + pub->app_idx); bt_shell_printf("\tTTL: %2.2x\n", pub->ttl); } @@ -374,6 +375,27 @@ static void print_sub_list(uint16_t addr, bool is_vendor, uint8_t *data, bt_shell_printf("\t\t%4.4x\n ", get_le16(data + i)); } +static void print_appkey_list(uint16_t len, uint8_t *data) +{ + uint16_t app_idx; + + bt_shell_printf("AppKeys:\n"); + + while (len >= 3) { + app_idx = l_get_le16(data) & 0xfff; + bt_shell_printf("\t%u (0x%3.3x)\n", app_idx, app_idx); + app_idx = l_get_le16(data + 1) >> 4; + bt_shell_printf("\t%u (0x%3.3x)\n", app_idx, app_idx); + data += 3; + len -= 3; + } + + if (len == 2) { + app_idx = l_get_le16(data) & 0xfff; + bt_shell_printf("\t %u (0x%3.3x)\n", app_idx, app_idx); + } +} + static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, uint16_t len) { @@ -384,7 +406,6 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, uint32_t mod_id; struct model_pub pub; int n; - uint16_t i; struct pending_req *req; if (mesh_opcode_get(data, len, &opcode, &n)) { @@ -424,8 +445,8 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, net_idx = get_le16(data + 1) & 0xfff; app_idx = get_le16(data + 2) >> 4; - bt_shell_printf("NetKey\t%3.3x\n", net_idx); - bt_shell_printf("AppKey\t%3.3x\n", app_idx); + bt_shell_printf("NetKey\t%u (0x%3.3x)\n", net_idx, net_idx); + bt_shell_printf("AppKey\t%u (0x%3.3x)\n", app_idx, app_idx); if (data[0] != MESH_STATUS_SUCCESS) break; @@ -449,24 +470,16 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, bt_shell_printf("AppKey List (node %4.4x) Status %s\n", src, mesh_status_str(data[0])); - bt_shell_printf("NetKey %3.3x\n", l_get_le16(&data[1])); + + net_idx = l_get_le16(&data[1]); + bt_shell_printf("NetKey %u (0x%3.3x)\n", net_idx, net_idx); len -= 3; if (data[0] != MESH_STATUS_SUCCESS) break; - bt_shell_printf("AppKeys:\n"); data += 3; - - while (len >= 3) { - bt_shell_printf("\t%3.3x\n", l_get_le16(data) & 0xfff); - bt_shell_printf("\t%3.3x\n", l_get_le16(data + 1) >> 4); - len -= 3; - data += 3; - } - - if (len == 2) - bt_shell_printf("\t%3.3x\n", l_get_le16(data)); + print_appkey_list(len, data); break; @@ -478,7 +491,7 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, mesh_status_str(data[0])); net_idx = get_le16(data + 1) & 0xfff; - bt_shell_printf("\tNetKey %3.3x\n", net_idx); + bt_shell_printf("\tNetKey %u (0x%3.3x)\n", net_idx, net_idx); if (data[0] != MESH_STATUS_SUCCESS) break; @@ -504,15 +517,17 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, while (len >= 3) { net_idx = l_get_le16(data) & 0xfff; - bt_shell_printf("\t%3.3x\n", net_idx); + bt_shell_printf("\t%u (0x%3.3x)\n", net_idx, net_idx); net_idx = l_get_le16(data + 1) >> 4; - bt_shell_printf("\t%3.3x\n", net_idx); + bt_shell_printf("\t%u (0x%3.3x)\n", net_idx, net_idx); data += 3; len -= 3; } - if (len == 2) - bt_shell_printf("\t%3.3x\n", l_get_le16(data) & 0xfff); + if (len == 2) { + net_idx = l_get_le16(data) & 0xfff; + bt_shell_printf("\t %u (0x%3.3x)\n", net_idx, net_idx); + } break; @@ -524,7 +539,7 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, mesh_status_str(data[0])); net_idx = get_le16(data + 1) & 0xfff; - bt_shell_printf("\tNetKey %3.3x\n", net_idx); + bt_shell_printf("\tNetKey %u (0x%3.3x)\n", net_idx, net_idx); bt_shell_printf("\tKR Phase %2.2x\n", data[3]); break; @@ -541,7 +556,7 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, print_mod_id(data + 5, len == 9, ""); - bt_shell_printf("AppIdx\t\t%3.3x\n ", app_idx); + bt_shell_printf("AppIdx\t\t%u (0x%3.3x)\n ", app_idx, app_idx); break; @@ -673,9 +688,10 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, bt_shell_printf("Element Addr\t%4.4x\n", get_le16(data + 1)); bt_shell_printf("Model ID\t%4.4x\n", get_le16(data + 3)); - for (i = 5; i < len; i += 2) - bt_shell_printf("Model AppIdx\t%4.4x\n", - get_le16(data + i)); + data += 5; + len -= 5; + print_appkey_list(len, data); + break; case OP_VEND_MODEL_APP_LIST: @@ -691,9 +707,10 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, bt_shell_printf("Element Addr\t%4.4x\n", get_le16(data + 1)); print_mod_id(data + 3, true, ""); - for (i = 7; i < len; i += 2) - bt_shell_printf("Model AppIdx\t%4.4x\n", - get_le16(data + i)); + data += 7; + len -= 7; + print_appkey_list(len, data); + break; /* Per Mesh Profile 4.3.2.63 */ @@ -709,7 +726,8 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, bt_shell_printf("Period\t\t%2.2x\n", data[4]); bt_shell_printf("TTL\t\t%2.2x\n", data[5]); bt_shell_printf("Features\t%4.4x\n", get_le16(data + 6)); - bt_shell_printf("Net_Idx\t%4.4x\n", get_le16(data + 8)); + net_idx = get_le16(data + 8); + bt_shell_printf("Net_Idx\t%u (0x%3.3x)\n", net_idx, net_idx); break; /* Per Mesh Profile 4.3.2.66 */ @@ -733,7 +751,7 @@ static bool msg_recvd(uint16_t src, uint16_t idx, uint8_t *data, if (len != 1) return true; - bt_shell_printf("Node %4.4x: Network transmit cnt %d, steps %d\n", + bt_shell_printf("Node %4.4x: Net transmit cnt %d, steps %d\n", src, data[0] & 7, data[0] >> 3); break; diff --git a/tools/mesh/keys.c b/tools/mesh/keys.c index ff3b23f61..c4070cb75 100644 --- a/tools/mesh/keys.c +++ b/tools/mesh/keys.c @@ -193,15 +193,15 @@ static void print_appkey(void *app_key, void *user_data) { uint16_t app_idx = L_PTR_TO_UINT(app_key); - bt_shell_printf("0x%3.3x, ", app_idx); + bt_shell_printf("%u (0x%3.3x), ", app_idx, app_idx); } static void print_netkey(void *net_key, void *user_data) { struct net_key *key = net_key; - bt_shell_printf(COLOR_YELLOW "NetKey: 0x%3.3x, phase: %u\n" COLOR_OFF, - key->idx, key->phase); + bt_shell_printf(COLOR_YELLOW "NetKey: %u (0x%3.3x), phase: %u\n" + COLOR_OFF, key->idx, key->idx, key->phase); if (!key->app_keys || l_queue_isempty(key->app_keys)) return; diff --git a/tools/mesh/remote.c b/tools/mesh/remote.c index b9bc6b5c0..24bc59129 100644 --- a/tools/mesh/remote.c +++ b/tools/mesh/remote.c @@ -217,11 +217,11 @@ uint16_t remote_get_subnet_idx(uint16_t addr) return (uint16_t) net_idx; } -static void print_key(void *net_key, void *user_data) +static void print_key(void *key, void *user_data) { - uint16_t net_idx = L_PTR_TO_UINT(net_key); + uint16_t idx = L_PTR_TO_UINT(key); - bt_shell_printf("%3.3x, ", net_idx); + bt_shell_printf("%u (0x%3.3x), ", idx, idx); } static void print_node(void *rmt, void *user_data) -- 2.21.1