Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp708962yba; Thu, 16 May 2019 07:44:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRYaw2D0D+Az3IvLeiexmviaG0mVbFt18Mn18H3bbr0CvwMtAkj6+rB8m0rQCgNtj4No3r X-Received: by 2002:a62:1692:: with SMTP id 140mr32858213pfw.166.1558017898612; Thu, 16 May 2019 07:44:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558017898; cv=none; d=google.com; s=arc-20160816; b=UJU/YkdovnlwiNjA+iXjNu5ixqoSBdKukmvj1hatez+V7Ci2nFfMxZhnm5OmyarfOL 5yVDdd48c45vviW9OjAQuqth2pRp0bQafk0EqgbvO86rBM7nrIjd30gXk3Vob69bhtY6 UQs/aCmDWG2WF4bGxzdBU6+jpgt84rG60TzF6knNm8zJXIZvsTiKuSkHdj9cv8j8Tkvk ysdEcxn9GDGIM8ucKsPER2TXhGyRLrFBnq1tKWkmzvwe0JZ2q+MtEW0kJXnRtdpf2j1F 4KaP8wq+bAGYQN5JIVnaDAHMS7DCsrhwEODdFFwny2Up8CGGLCLwRWwe5XlSaoW158b6 zr9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:thread-index :content-transfer-encoding:mime-version:message-id:date:subject:to :from; bh=Ge9z53ArN+bS8Q9W0xVdMu66n/zSv8kWLMXCTMfkanc=; b=H31D4Ke3cHC09tZXc6JGyvZMirdqCS1P0WXNY8mx0vvFAxfbsvgo1WgKyo9XHBQTgT CxNRqMuLym7AGGVUDiebozeRVGdLD7GL7wVhyP16dFnAYQoaHysM/N0TwYhoMMLHLG2s zf+vTJgcmdoqGMpFXS3JMhtxeFWSb9wlCwRPu7hA5rjM3rNtc5XHxq1X9TOtZEHdZL5M vJyFmzGRy7DnVfkvxkj8zdPHBASRSjOGevU8tillUGEJcpI46XOq3pdogARBxRU/nIQN PYhGHVsa3l56D1D1QOC1PiqNDdVARjhnxtasaUR2OmIg4YvWIsVRFEv4vIyyzTBtTKTk bArg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si4964292pgp.199.2019.05.16.07.44.43; Thu, 16 May 2019 07:44:58 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727287AbfEPOm1 (ORCPT + 99 others); Thu, 16 May 2019 10:42:27 -0400 Received: from mail.tinia.eu ([185.96.219.211]:39606 "EHLO mail.tinia.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727266AbfEPOm0 (ORCPT ); Thu, 16 May 2019 10:42:26 -0400 X-Greylist: delayed 374 seconds by postgrey-1.27 at vger.kernel.org; Thu, 16 May 2019 10:42:25 EDT Received: from localhost (localhost [127.0.0.1]) by mail.tinia.eu (Postfix) with ESMTP id E0E402226C5 for ; Thu, 16 May 2019 16:36:05 +0200 (CEST) Received: from mail.tinia.eu ([127.0.0.1]) by localhost (mail.tinia.eu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 3XrFluSv_V9Q for ; Thu, 16 May 2019 16:36:04 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.tinia.eu (Postfix) with ESMTP id 7531B22299B for ; Thu, 16 May 2019 16:36:04 +0200 (CEST) X-Virus-Scanned: amavisd-new at yes Received: from mail.tinia.eu ([127.0.0.1]) by localhost (mail.tinia.eu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id R4ziCWsFlfja for ; Thu, 16 May 2019 16:36:04 +0200 (CEST) Received: from DANBIAMBL (customer-31-185-23-59.com-com.it [31.185.23.59]) by mail.tinia.eu (Postfix) with ESMTPSA id 469602226C5 for ; Thu, 16 May 2019 16:36:04 +0200 (CEST) From: "Daniele Biagetti" To: Subject: [PATCH 2/4] meshctl: Status messages processed even if they do not belong to the model Date: Thu, 16 May 2019 16:35:48 +0200 Message-ID: <000501d50bf4$b040a510$10c1ef30$@cblelectronics.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdUL8J+AwKb/FsyNSy6EMVVe8dYf/g== Content-Language: it Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Fix: The status messages was processed and displayed even if they do not belong to the present model. Now the status messages are processed only if they have the correct opcode. Addition: Added generic onoff set unack message Addition: Replaced the return statement with a warning message in case of transmission or reception of messages coming from unknown addresses (such as group addresses) Signed-off-by: Daniele Biagetti --- tools/mesh/node.c | 11 ++++++++ tools/mesh/onoff-model.c | 56 +++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/tools/mesh/node.c b/tools/mesh/node.c index d23315ce4..3171ef01a 100644 --- a/tools/mesh/node.c +++ b/tools/mesh/node.c @@ -475,6 +475,8 @@ static bool deliver_model_data(struct mesh_element* element, uint16_t src, uint16_t app_idx, uint8_t *data, uint16_t len) { GList *l; + uint32_t opcode; + int n; for(l = element->models; l; l = l->next) { struct mesh_model *model = l->data; @@ -487,6 +489,15 @@ static bool deliver_model_data(struct mesh_element* element, uint16_t src, return true; } + if (mesh_opcode_get(data, len, &opcode, &n)) { + len -= n; + data += n; + } else + return false; + bt_shell_printf("Unknown Model Message received (%d) opcode %x\n", + len, opcode); + print_byte_array("\t",data, len); + return false; } diff --git a/tools/mesh/onoff-model.c b/tools/mesh/onoff-model.c index b52afe2c8..8c41e005d 100644 --- a/tools/mesh/onoff-model.c +++ b/tools/mesh/onoff-model.c @@ -111,6 +111,7 @@ static bool client_msg_recvd(uint16_t src, uint8_t *data, { uint32_t opcode; int n; + char s[128]; if (mesh_opcode_get(data, len, &opcode, &n)) { len -= n; @@ -118,27 +119,27 @@ static bool client_msg_recvd(uint16_t src, uint8_t *data, } else return false; - bt_shell_printf("On Off Model Message received (%d) opcode %x\n", - len, opcode); - print_byte_array("\t",data, len); - switch (opcode & ~OP_UNRELIABLE) { default: return false; case OP_GENERIC_ONOFF_STATUS: + bt_shell_printf("On Off Model Message received (%d) opcode %x\n", + len, opcode); + print_byte_array("\t",data, len); if (len != 1 && len != 3) break; - bt_shell_printf("Node %4.4x: Off Status present = %s", - src, data[0] ? "ON" : "OFF"); - + sprintf(s, "Node %4.4x: On Off Status present = %s", + src, data[0] ? "ON" : "OFF"); if (len == 3) { - bt_shell_printf(", target = %s", - data[1] ? "ON" : "OFF"); + sprintf(s, ", target = %s", + data[1] ? "ON" : "OFF"); + bt_shell_printf("%s\n", s); print_remaining_time(data[2]); - } else - bt_shell_printf("\n"); + }else + bt_shell_printf("%s\n", s); + break; } @@ -220,8 +221,9 @@ static void cmd_get_status(int argc, char *argv[]) node = node_find_by_addr(target); - if (!node) - return; + if (!node){ + bt_shell_printf("Warning: node %4.4x not found in database\n",target); + } n = mesh_opcode_set(OP_GENERIC_ONOFF_GET, msg); @@ -238,6 +240,8 @@ static void cmd_set(int argc, char *argv[]) uint16_t n; uint8_t msg[32]; struct mesh_node *node; + int np; + uint32_t opcode; if (IS_UNASSIGNED(target)) { bt_shell_printf("Destination not set\n"); @@ -246,16 +250,26 @@ static void cmd_set(int argc, char *argv[]) node = node_find_by_addr(target); - if (!node) - return; + if (!node){ + bt_shell_printf("Warning: node %4.4x not found in database\n",target); + } - if ((read_input_parameters(argc, argv) != 1) && - parms[0] != 0 && parms[0] != 1) { - bt_shell_printf("Bad arguments: Expecting \"0\" or \"1\"\n"); - return bt_shell_noninteractive_quit(EXIT_FAILURE); + np = read_input_parameters(argc, argv); + if ((np != 1) && (np != 2) && + parms[0] != 0 && parms[0] != 1 && + parms[1] != 0 && parms[1] != 1) { + bt_shell_printf("Bad arguments: Expecting \"0\" or \"1\" " + "and an optional \"0\" or \"1\" as unack\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + if( (np==2) && parms[1] ){ + opcode = OP_GENERIC_ONOFF_SET_UNACK; + }else{ + opcode = OP_GENERIC_ONOFF_SET; } - n = mesh_opcode_set(OP_GENERIC_ONOFF_SET, msg); + n = mesh_opcode_set(opcode, msg); msg[n++] = parms[0]; msg[n++] = trans_id++; @@ -275,7 +289,7 @@ static const struct bt_shell_menu onoff_menu = { "Set node to configure"}, {"get", NULL, cmd_get_status, "Get ON/OFF status"}, - {"onoff", "<0/1>", cmd_set, + {"onoff", "<0/1> [unack]", cmd_set, "Send \"SET ON/OFF\" command"}, {} }, }; -- 2.19.2.windows.1