From patchwork Fri Dec 3 16:02:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: daniele.biagetti@cblelectronics.com X-Patchwork-Id: 520301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82665C433EF for ; Fri, 3 Dec 2021 16:09:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382046AbhLCQMl (ORCPT ); Fri, 3 Dec 2021 11:12:41 -0500 Received: from smtp202-pc.aruba.it ([62.149.157.202]:36567 "EHLO smtp200-pc.aruba.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1382066AbhLCQMj (ORCPT ); Fri, 3 Dec 2021 11:12:39 -0500 Received: from danbia2MBL ([188.217.48.39]) by Aruba Outgoing Smtp with ESMTPSA id tB0imxNzZrBxFtB0lmsYJL; Fri, 03 Dec 2021 17:02:11 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aruba.it; s=a1; t=1638547331; bh=inxXi/2Ljmo41vlZVsG5c/isk9xC8rGDJWxaFKcyY6g=; h=From:To:Subject:Date:MIME-Version:Content-Type; b=E7GPCRD8SDUbSWwu7vrShuhDu0O5P0zMQUXr8jAnEHVsPmgNVDrZuHZQ2VEwryE6f 8ZT/cNTGraMuWkGTYhSu0WKp7hajpy+VSqkqtVgiusgFW2fy29dIin8pB1YbIIhFEx rh6bWgWh4VAYVvW87EMuCqRCavBh+0aGtI4letwGxtlokr4eyKBS4yJ9iqVkNwFWGn ZUbUDXbwPZeShFaDR+S+Sx/jZNQV3RMDkKNyFRic/6it3E4GoyHP3Ebu/4IZxryKyG Ji7JGtDJm5XdlOwj1jmPtdL48MvEVrWUBmPbjl//lEKvlEBI5vGeQD0jIlF3UyciMB 073K93bv72A7w== From: To: Subject: [PATCH 1/6] tools/mesh-gatt: Add onoff set unack message to onoff client model Date: Fri, 3 Dec 2021 17:02:10 +0100 Message-ID: <000501d7e85f$2105e2d0$6311a870$@cblelectronics.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdfoXvYc6r6XD9G+SoyL3P0w05mzBQ== Content-Language: it X-CMAE-Envelope: MS4xfF3cbRY1IExUTsa8XkcX1hn3XGTVIs94MpoLCroyiDhFw2UDoZAuhsZ/Wr93fkd/0PeIrcts8IjLGtDpYRFJN77hngk2usYjLLYNgc7p8QKumH3IIncF moCB8Utrfqz26pZTsM1bkDen0scUWELtuAk+j2FtXFSv/8EdUGiwfBQJ8xh8ORvBybw1E20/2wZrGM0stN0gXnkBVNrmHbWZpmx+RZC54NQkJnwU8BULiDPV Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- tools/mesh-gatt/onoff-model.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) @@ -263,7 +274,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"}, {} }, }; diff --git a/tools/mesh-gatt/onoff-model.c b/tools/mesh-gatt/onoff-model.c index 9dfedd85a..13ff4bbe3 100644 --- a/tools/mesh-gatt/onoff-model.c +++ b/tools/mesh-gatt/onoff-model.c @@ -226,6 +226,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"); @@ -237,13 +239,22 @@ static void cmd_set(int argc, char *argv[]) if (!node) return; - 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++; From patchwork Fri Dec 3 16:02:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: daniele.biagetti@cblelectronics.com X-Patchwork-Id: 520300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45401C433FE for ; Fri, 3 Dec 2021 16:09:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382058AbhLCQMm (ORCPT ); Fri, 3 Dec 2021 11:12:42 -0500 Received: from smtp202-pc.aruba.it ([62.149.157.202]:36198 "EHLO smtp200-pc.aruba.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1382077AbhLCQMj (ORCPT ); Fri, 3 Dec 2021 11:12:39 -0500 Received: from danbia2MBL ([188.217.48.39]) by Aruba Outgoing Smtp with ESMTPSA id tB0imxNzZrBxFtB0omsYKy; Fri, 03 Dec 2021 17:02:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aruba.it; s=a1; t=1638547334; bh=0N9A8HEtNgE0tJ8W97u9axtv58jzcGRcijZ/Nfpgj5s=; h=From:To:Subject:Date:MIME-Version:Content-Type; b=mk4D91qYla52PNwQcOZtkuEMHj4aKDNpA7/PVtPyP7SPn0p6wh8TR5dJwioTiG9Cf C1BvN6KOQFoxxYiWfx/9Ow3iWCuKOkEn1rPZpfTFw1Mf5BwyjaWAXR8RXC/OkPS0x3 aiW8fafnWxVRZ5RA1zwXzjC5fLSBD4x0obeXMXzzNBt07+d1gvFf5hZe1HxfXiaRGD SdqLCK3dTwcdcW+cB+KOv8qkVQd52YtIP5G3yYn12WLVhjjo9epp549NbuNQunhzvo RVA/6Ze0wxKEjTxRHSYN5eHGruvY+nB0JqZPdKx0/0T1hWMF7GsFMpEkmEj/eSy4R1 rQKtV7apMUx3w== From: To: Subject: [PATCH 2/6] tools/mesh-gatt: Fix status messages processing Date: Fri, 3 Dec 2021 17:02:12 +0100 Message-ID: <000601d7e85f$228e7ea0$67ab7be0$@cblelectronics.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdfoXhoSvPDwxinGTn6eFFOONeASOg== Content-Language: it X-CMAE-Envelope: MS4xfLi5yG4h1Fim+3qL6+VNFCkA3JR8q2JA/Jsb3z7QXxSPx50jOIAa1exTloc0QGftqINohpjvCX7UEzXArHWA4EY7XLQiAsEvlAC7sM+HmAigKEkdrv9a uI8YjSNtE+lCzeGNilIjIUxxGUfu2uR/xwmBktda4S6XJfaCy+kCO9QNBMMc/GWuUtFKL39FZExIt4Q5NJ64djnYJgwYjzhgZmWMSNi8/9Y7xpoDEwaMYG7u Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org The status messages was processed and displayed even if they do not belong to the present model. This fix ensure that the status messages are processed only if they have the correct opcode. --- tools/mesh-gatt/node.c | 11 +++++++++++ tools/mesh-gatt/onoff-model.c | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-) + bt_shell_printf("%s\n", s); + break; } diff --git a/tools/mesh-gatt/node.c b/tools/mesh-gatt/node.c index 356e1cd1a..4d0cc21e9 100644 --- a/tools/mesh-gatt/node.c +++ b/tools/mesh-gatt/node.c @@ -470,6 +470,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; @@ -482,6 +484,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-gatt/onoff-model.c b/tools/mesh-gatt/onoff-model.c index 13ff4bbe3..1c9676e03 100644 --- a/tools/mesh-gatt/onoff-model.c +++ b/tools/mesh-gatt/onoff-model.c @@ -99,6 +99,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; @@ -106,27 +107,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) { 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"); - + snprintf(s, sizeof(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"); + snprintf(s + strlen(s), sizeof(s), ", target = %s", + data[1] ? "ON" : "OFF"); + bt_shell_printf("%s\n", s); print_remaining_time(data[2]); - } else - bt_shell_printf("\n"); + }else From patchwork Fri Dec 3 16:02:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: daniele.biagetti@cblelectronics.com X-Patchwork-Id: 520567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F06F5C43219 for ; Fri, 3 Dec 2021 16:09:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382062AbhLCQMm (ORCPT ); Fri, 3 Dec 2021 11:12:42 -0500 Received: from smtp202-pc.aruba.it ([62.149.157.202]:35500 "EHLO smtp200-pc.aruba.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1382016AbhLCQMl (ORCPT ); Fri, 3 Dec 2021 11:12:41 -0500 Received: from danbia2MBL ([188.217.48.39]) by Aruba Outgoing Smtp with ESMTPSA id tB0imxNzZrBxFtB0qmsYLi; Fri, 03 Dec 2021 17:02:16 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aruba.it; s=a1; t=1638547336; bh=QQf3mmmEVxULFSu7xO7pOvWLUPxBOy5sWo4RhksAeFM=; h=From:To:Subject:Date:MIME-Version:Content-Type; b=kH/1y2qP22J6XrfSr1nPD/bXzQ0HWmeZqO44N+RtJKD4PJp72TTQe4Ky8MspD+PdF hdqVcZDjKHiNtE2YpdBmJOve28sQYIRC1hMqEes+ykf5NbqUXS9Gs+g9iQTAgQ9f0M wIxVPO6kB40nHaR89fHuCkkQ5rswwZof+4j4g+av6so7/cVpfIbdSKVQOYNtbWcEqV WYSl0uy+pM90OTiHdbcfBT0NbtoeU9l3WPtMtEgIFyjA/oJv+Sd5itQDg4jUOFFWfP /gRRlAEoH5+o0I12l/+NO8yHcO2iq3SE/Rvi7IGpVz8AmeOg0CBiTyHiFl2p7+N6hX +mWLAgw/YWGfA== From: To: Subject: [PATCH 3/6] tools/mesh-gatt: Fix unwanted return in onoff client model Date: Fri, 3 Dec 2021 17:02:15 +0100 Message-ID: <000701d7e85f$23f6c130$6be44390$@cblelectronics.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdfoXs1TBdJlpgZAQ+uVHl48Q+AG6w== Content-Language: it X-CMAE-Envelope: MS4xfOTdNVBBY3FYM0zajEmZBxntIuyi2WEJd+u9piumjIoUedNdIy/Yq9ztZWLSpOg8ifv8Rh6dskOT9F7ZyPUs+cfvqkvP851yJs+1mp4jjD8z5Hatxi9T HSLgSyzmgoj38IXO37D/Hbp/78Vnb/6iXnY4TFHnNABxFDRwTRnVW47KpmqeozY22tiv1yvQasAPMyO/jxoy9v9zc9Aw2ygm6xB0drVqoCnv1Ks3i6059ysN Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Replaced the return statement with a warning message in case of transmission or reception of messages coming from unknown addresses (such as group addresses) --- tools/mesh-gatt/onoff-model.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) @@ -237,8 +238,9 @@ 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); + } np = read_input_parameters(argc, argv); if ((np != 1) && (np != 2) && diff --git a/tools/mesh-gatt/onoff-model.c b/tools/mesh-gatt/onoff-model.c index 1c9676e03..9a4ef6d97 100644 --- a/tools/mesh-gatt/onoff-model.c +++ b/tools/mesh-gatt/onoff-model.c @@ -209,8 +209,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); From patchwork Fri Dec 3 16:02:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: daniele.biagetti@cblelectronics.com X-Patchwork-Id: 520566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23862C433F5 for ; Fri, 3 Dec 2021 16:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382104AbhLCQMy (ORCPT ); Fri, 3 Dec 2021 11:12:54 -0500 Received: from smtp202-pc.aruba.it ([62.149.157.202]:54421 "EHLO smtp200-pc.aruba.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1382063AbhLCQMn (ORCPT ); Fri, 3 Dec 2021 11:12:43 -0500 X-Greylist: delayed 420 seconds by postgrey-1.27 at vger.kernel.org; Fri, 03 Dec 2021 11:12:37 EST Received: from danbia2MBL ([188.217.48.39]) by Aruba Outgoing Smtp with ESMTPSA id tB0imxNzZrBxFtB0smsYMG; Fri, 03 Dec 2021 17:02:18 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aruba.it; s=a1; t=1638547338; bh=yOXpZilRtFzwUD8zDuZCx1oJ0FszD4bQpIKcFQHM54c=; h=From:To:Subject:Date:MIME-Version:Content-Type; b=DNR44fHVlFdcriDMwgURoChgELZDS20mylOas2L6SdB4JdNc9N7H33dbaAbVCOk5T JolsgiZUigSrcGmDZNe/pRcWx4PUIAlDorhw+fDGMnUcsBDOLnFSRaE/uOIUWiWVN4 JH98gnOSjJdurfmq73iTtmmP+9G2T4Sh1ipsRHqlA6Worh4Ry1uYSzz/JBP4zkpicN J8t56zaYefeW7UioDj9kbivv2IK0f1h5GIDFbtW+LP/NXskF5rqdkIxaOM2rAi3OxD OpisZgwyR3Wz0GzpwagHta/eHeaKaBg59wagejiGBKyWGX3XntjpPek/FQSAi/mM23 nAoFzP/YOTs9g== From: To: Subject: [PATCH 4/6] tools/mesh-gatt: Add subscription delete message to config client model Date: Fri, 3 Dec 2021 17:02:17 +0100 Message-ID: <000801d7e85f$251aa7c0$6f4ff740$@cblelectronics.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdfoXnOKPcaZMa9gRYmgsvtpIEz4Cg== Content-Language: it X-CMAE-Envelope: MS4xfNzmIgnB3GF9p4T0UfMgrb+aIKMwqgkFKm0louqXqEnNnLWb4H23GjouaOIxPskYqI2O1KAvY9kvNFoTzcYOG9AAbyx4bKfJ55p6MOmB1r0MkLzTp4Ax 8EpWoggTF3Qx6cketCQeHLfBdplyCy3euVxFTlz053q95AesDQM9hTVw/uE2X59iepppdoNM1qbGhWcogKsHSWImgrjByDrMgZfVrSMCS2QwHNS5nCGNP58Y Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- tools/mesh-gatt/config-client.c | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) uint16_t n; @@ -1232,6 +1270,8 @@ static const struct bt_shell_menu cfg_menu = { cmd_sub_add, "Add subscription"}, {"sub-get", " ", cmd_sub_get, "Get subscription"}, + {"sub-del", " ", + cmd_sub_del, "Delete subscription"}, {"node-reset", NULL, cmd_node_reset, "Reset a node and remove it from network"}, {} }, diff --git a/tools/mesh-gatt/config-client.c b/tools/mesh-gatt/config-client.c index 7bdd028d2..c61908b4e 100644 --- a/tools/mesh-gatt/config-client.c +++ b/tools/mesh-gatt/config-client.c @@ -1037,6 +1037,44 @@ static void cmd_sub_get(int argc, char *argv[]) return bt_shell_noninteractive_quit(EXIT_SUCCESS); } +static void cmd_sub_del(int argc, char *argv[]) +{ + uint16_t n; + uint8_t msg[32]; + int parm_cnt; + + if (IS_UNASSIGNED(target)) { + bt_shell_printf("Destination not set\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + n = mesh_opcode_set(OP_CONFIG_MODEL_SUB_DELETE, msg); + + parm_cnt = read_input_parameters(argc, argv); + if (parm_cnt != 3) { + bt_shell_printf("Bad arguments: %s\n", argv[1]); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + /* Per Mesh Profile 4.3.2.19 */ + /* Element Address */ + put_le16(parms[0], msg + n); + n += 2; + /* Subscription Address */ + put_le16(parms[1], msg + n); + n += 2; + /* SIG Model ID */ + put_le16(parms[2], msg + n); + n += 2; + + if (!config_send(msg, n)) { + bt_shell_printf("Failed to send \"DELETE SUBSCRIPTION\"\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + static void cmd_mod_appidx_get(int argc, char *argv[]) { From patchwork Fri Dec 3 16:02:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: daniele.biagetti@cblelectronics.com X-Patchwork-Id: 520299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82424C433EF for ; Fri, 3 Dec 2021 16:09:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382087AbhLCQNR (ORCPT ); Fri, 3 Dec 2021 11:13:17 -0500 Received: from smtp202-pc.aruba.it ([62.149.157.202]:36567 "EHLO smtp200-pc.aruba.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1382068AbhLCQMs (ORCPT ); Fri, 3 Dec 2021 11:12:48 -0500 Received: from danbia2MBL ([188.217.48.39]) by Aruba Outgoing Smtp with ESMTPSA id tB0vmxOChrBxFtB0vmsYNL; Fri, 03 Dec 2021 17:02:21 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aruba.it; s=a1; t=1638547341; bh=REM19N99t6s4l9l7Dk2shRnTQm4nOrlVJ7652b0u2s4=; h=From:To:Subject:Date:MIME-Version:Content-Type; b=I5sHOyF672PZFsdI1xzB/VIg1HkQQCRhfeh9nyzK+cGzikVh7Lj2RGxz4quHN15Vn pyYo6YuUueWd380g+ObOVIZb3Mx2pe5rotyyWEnva6jeOD40aes6geqgi59YUaq90v H9Q1L4OocNeYGlH9GnKUqShS5hkXvDQgnlYmZuLKOuXg2goNdwx8bU+mUeCpjyb570 VRNQCLc/xvO2VMfftaqXa0xqRlRNLkwUCwAyTbXnYy0pOGmnBWX0RqfU5JwlUzwil0 hHXx5VwSjUm/QjMpFYeqIGNvsb58dqzTr8m7Lhoi0Vg7Mq8Da3aPAx9Wf3HHT12om8 CuF43jY3M2lNw== From: To: Subject: [PATCH 5/6] tools/mesh-gatt: Add generic level model support Date: Fri, 3 Dec 2021 17:02:19 +0100 Message-ID: <000901d7e85f$26e29680$74a7c380$@cblelectronics.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdfoXoh9wntIOI/qRx6z5u0YY69mdw== Content-Language: it X-CMAE-Envelope: MS4xfBatWxN8bxVOQYmF9G754wJZBxt4MYdbM4s7U0PFme1sThlo1rO7hKBl9uAVsJoCkjt/kV96hvtjxJitYsaPZPz8PUJHvVNW4/EVGdJ2OsOPr9xD6eL7 W5YGl9G9umDk4tmuXizYiSgEfdltsUSHCC04RZy8JhX08VNKRmlJk46erKjb4pQ7R8LTuGHx6RXQzbyhf/3pzo6SL0D+DmUnFmGif4dO11enM1JvSnqBB9vQ Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- Makefile.tools | 4 +- tools/mesh-gatt/level-model.c | 288 ++++++++++++++++++++++++++++++++ tools/mesh-gatt/level-model.h | 21 +++ tools/mesh-gatt/local_node.json | 6 +- tools/meshctl.c | 4 + 5 files changed, 321 insertions(+), 2 deletions(-) create mode 100644 tools/mesh-gatt/level-model.c create mode 100644 tools/mesh-gatt/level-model.h g_dbus_client_unref(client); diff --git a/Makefile.tools b/Makefile.tools index c7bdff83f..c0d2e27de 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -331,7 +331,9 @@ tools_meshctl_SOURCES = tools/meshctl.c \ tools/mesh-gatt/config-client.c \ tools/mesh-gatt/config-server.c \ tools/mesh-gatt/onoff-model.h \ - tools/mesh-gatt/onoff-model.c + tools/mesh-gatt/onoff-model.c \ + tools/mesh-gatt/level-model.h \ + tools/mesh-gatt/level-model.c tools_meshctl_LDADD = gdbus/libgdbus-internal.la src/libshared-glib.la \ lib/libbluetooth-internal.la \ $(GLIB_LIBS) $(DBUS_LIBS) -ljson-c -lreadline diff --git a/tools/mesh-gatt/level-model.c b/tools/mesh-gatt/level-model.c new file mode 100644 index 000000000..6feb89d5d --- /dev/null +++ b/tools/mesh-gatt/level-model.c @@ -0,0 +1,288 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2017 Intel Corporation. All rights reserved. + * + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "src/shared/shell.h" +#include "src/shared/util.h" + +#include "tools/mesh-gatt/mesh-net.h" +#include "tools/mesh-gatt/keys.h" +#include "tools/mesh-gatt/net.h" +#include "tools/mesh-gatt/node.h" +#include "tools/mesh-gatt/prov-db.h" +#include "tools/mesh-gatt/util.h" +#include "tools/mesh-gatt/level-model.h" + +static uint8_t trans_id; +static uint16_t level_app_idx = APP_IDX_INVALID; +static int client_bind(uint16_t app_idx, int action) +{ + if (action == ACTION_ADD) { + if (level_app_idx != APP_IDX_INVALID) { + return MESH_STATUS_INSUFF_RESOURCES; + } else { + level_app_idx = app_idx; + bt_shell_printf("Level client model: new binding" + " %4.4x\n", app_idx); + } + } else { + if (level_app_idx == app_idx) + level_app_idx = APP_IDX_INVALID; + } + return MESH_STATUS_SUCCESS; +} +static void print_remaining_time(uint8_t remaining_time) +{ + uint8_t step = (remaining_time & 0xc0) >> 6; + uint8_t count = remaining_time & 0x3f; + int secs = 0, msecs = 0, minutes = 0, hours = 0; + switch (step) { + case 0: + msecs = 100 * count; + secs = msecs / 1000; + msecs -= (secs * 1000); + break; + case 1: + secs = 1 * count; + minutes = secs / 60; + secs -= (minutes * 60); + break; + case 2: + secs = 10 * count; + minutes = secs / 60; + secs -= (minutes * 60); + break; + case 3: + minutes = 10 * count; + hours = minutes / 60; + minutes -= (hours * 60); + break; + default: + break; + } + bt_shell_printf("\n\t\tRemaining time: %d hrs %d mins %d secs %d" + " msecs\n", hours, minutes, secs, msecs); +} +static bool client_msg_recvd(uint16_t src, uint8_t *data, + uint16_t len, void *user_data) +{ + uint32_t opcode; + int n; + uint8_t *p; + int16_t lev; + char s[128]; + + if (mesh_opcode_get(data, len, &opcode, &n)) { + len -= n; + data += n; + } else + return false; + + switch (opcode) { + default: + return false; + case OP_GENERIC_LEVEL_STATUS: + bt_shell_printf("Level Model Message received (%d) opcode %x\n", + len, opcode); + print_byte_array("\t",data, len); + + if (len != 2 && len != 4 && len != 5) + break; + lev = 0; + p = (uint8_t *)&lev; +#if __BYTE_ORDER == __LITTLE_ENDIAN + p[0] = data[0]; + p[1] = data[1]; +#elif __BYTE_ORDER == __BIG_ENDIAN + p[1] = data[0]; + p[0] = data[1]; +#else +#error "Unknown byte order" +#error Processor endianness unknown! +#endif + sprintf(s, "Node %4.4x: Level Status present = %d", + src, lev); + if (len >= 4) { + lev = (int16_t)(((uint16_t)data[3] << 8) | (uint16_t)data[2]); + sprintf(s, ", target = %d", + lev); + } + bt_shell_printf("%s\n", s); + if(len == 5){ + print_remaining_time(data[4]); + } + break; + } + return true; +} +static uint32_t target; +static int32_t parms[8]; +static uint32_t read_input_parameters(int argc, char *argv[]) +{ + uint32_t i; + if (!argc) + return 0; + --argc; + ++argv; + if (!argc || argv[0][0] == '\0') + return 0; + for (i = 0; i < sizeof(parms)/sizeof(parms[0]) && i < (unsigned) argc; + i++) { + if(sscanf(argv[i], "%d", &parms[i]) <= 0) + break; + } + return i; +} +static void cmd_set_node(int argc, char *argv[]) +{ + uint32_t dst; + char *end; + dst = strtol(argv[1], &end, 16); + if (end != (argv[1] + 4)) { + bt_shell_printf("Bad unicast address %s: " + "expected format 4 digit hex\n", argv[1]); + target = UNASSIGNED_ADDRESS; + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } else { + bt_shell_printf("Controlling Level for node %4.4x\n", dst); + target = dst; + set_menu_prompt("Level", argv[1]); + return bt_shell_noninteractive_quit(EXIT_SUCCESS); + } +} +static bool send_cmd(uint8_t *buf, uint16_t len) +{ + struct mesh_node *node = node_get_local_node(); + uint8_t ttl; + if(!node) + return false; + ttl = node_get_default_ttl(node); + return net_access_layer_send(ttl, node_get_primary(node), + target, level_app_idx, buf, len); +} +static void cmd_get_status(int argc, char *argv[]) +{ + uint16_t n; + uint8_t msg[32]; + struct mesh_node *node; + if (IS_UNASSIGNED(target)) { + bt_shell_printf("Destination not set\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + node = node_find_by_addr(target); + + if (!node){ + bt_shell_printf("Warning: node %4.4x not found in database\n",target); + } + + n = mesh_opcode_set(OP_GENERIC_LEVEL_GET, msg); + if (!send_cmd(msg, n)) { + bt_shell_printf("Failed to send \"GENERIC LEVEL GET\"\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} +static void cmd_set(int argc, char *argv[]) +{ + uint16_t n; + uint8_t msg[32]; + struct mesh_node *node; + uint8_t *p; + int np; + uint32_t opcode; + int16_t level; + + if (IS_UNASSIGNED(target)) { + bt_shell_printf("Destination not set\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + node = node_find_by_addr(target); + + if (!node){ + bt_shell_printf("Warning: node %4.4x not found in database\n",target); + } + + np = read_input_parameters(argc, argv); + if ((np != 1) && (np != 2) && + parms[0] < -32768 && parms[0] > 32767 && + parms[1] != 0 && parms[1] != 1) { + bt_shell_printf("Bad arguments: Expecting an integer " + "-32768 to 32767 and an optional 0 or 1 as unack\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + if( (np==2) && parms[1] ){ + opcode = OP_GENERIC_LEVEL_SET_UNACK; + }else{ + opcode = OP_GENERIC_LEVEL_SET; + } + + n = mesh_opcode_set(opcode, msg); + level = (int16_t)parms[0]; + p = (uint8_t *)&level; +#if __BYTE_ORDER == __LITTLE_ENDIAN + msg[n++] = p[0]; + msg[n++] = p[1]; +#elif __BYTE_ORDER == __BIG_ENDIAN + msg[n++] = p[1]; + msg[n++] = p[0]; +#else +#error "Unknown byte order" +#error Processor endianness unknown! +#endif + msg[n++] = trans_id++; + if (!send_cmd(msg, n)) { + bt_shell_printf("Failed to send \"GENERIC LEVEL SET\"\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} +static const struct bt_shell_menu level_menu = { + .name = "level", + .desc = "Level Model Submenu", + .entries = { + {"target", "", cmd_set_node, + "Set node to configure"}, + {"get", NULL, cmd_get_status, + "Get Level status"}, + {"level", "<-32768/+32767> [unack]", cmd_set, + "Send \"SET Level\" command"}, + {} }, +}; +static struct mesh_model_ops client_cbs = { + client_msg_recvd, + client_bind, + NULL, + NULL +}; +bool level_client_init(uint8_t ele) +{ + if (!node_local_model_register(ele, GENERIC_LEVEL_CLIENT_MODEL_ID, + &client_cbs, NULL)) + return false; + bt_shell_add_submenu(&level_menu); + return true; +} diff --git a/tools/mesh-gatt/level-model.h b/tools/mesh-gatt/level-model.h new file mode 100644 index 000000000..1c8b5f72e --- /dev/null +++ b/tools/mesh-gatt/level-model.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2017 Intel Corporation. All rights reserved. + * + * + */ +#define GENERIC_LEVEL_SERVER_MODEL_ID 0x1002 +#define GENERIC_LEVEL_CLIENT_MODEL_ID 0x1003 +#define OP_GENERIC_LEVEL_GET 0x8205 +#define OP_GENERIC_LEVEL_SET 0x8206 +#define OP_GENERIC_LEVEL_SET_UNACK 0x8207 +#define OP_GENERIC_LEVEL_STATUS 0x8208 +#define OP_GENERIC_DELTA_SET 0x8209 +#define OP_GENERIC_DELTA_SET_UNACK 0x820A +#define OP_GENERIC_MOVE_SET 0x820B +#define OP_GENERIC_MOVE_SET_UNACK 0x820C +void level_set_node(const char *args); +bool level_client_init(uint8_t ele); diff --git a/tools/mesh-gatt/local_node.json b/tools/mesh-gatt/local_node.json index 5ffa7ada1..462cd815d 100644 --- a/tools/mesh-gatt/local_node.json +++ b/tools/mesh-gatt/local_node.json @@ -36,7 +36,7 @@ { "elementIndex": 0, "location": "0001", - "models": ["0000", "0001", "1001"] + "models": ["0000", "0001", "1001", "1003"] } ] }, @@ -52,6 +52,10 @@ { "modelId": "1001", "bind": [1] + }, + { + "modelId": "1003", + "bind": [1] } ] } diff --git a/tools/meshctl.c b/tools/meshctl.c index 18e20c40d..69f8d412f 100644 --- a/tools/meshctl.c +++ b/tools/meshctl.c @@ -48,6 +48,7 @@ #include "mesh-gatt/util.h" #include "mesh-gatt/prov-db.h" #include "mesh-gatt/onoff-model.h" +#include "mesh-gatt/level-model.h" /* String display constants */ #define COLORED_NEW COLOR_GREEN "NEW" COLOR_OFF @@ -1999,6 +2000,9 @@ int main(int argc, char *argv[]) if (!onoff_client_init(PRIMARY_ELEMENT_IDX)) g_printerr("Failed to initialize mesh generic On/Off client\n"); + if (!level_client_init(PRIMARY_ELEMENT_IDX)) + g_printerr("Failed to initialize mesh generic level client\n"); + status = bt_shell_run(); From patchwork Fri Dec 3 16:02:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: daniele.biagetti@cblelectronics.com X-Patchwork-Id: 520565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0143C433EF for ; Fri, 3 Dec 2021 16:09:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382093AbhLCQNT (ORCPT ); Fri, 3 Dec 2021 11:13:19 -0500 Received: from smtp202-pc.aruba.it ([62.149.157.202]:36198 "EHLO smtp200-pc.aruba.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1382081AbhLCQMt (ORCPT ); Fri, 3 Dec 2021 11:12:49 -0500 Received: from danbia2MBL ([188.217.48.39]) by Aruba Outgoing Smtp with ESMTPSA id tB0vmxOChrBxFtB0xmsYOA; Fri, 03 Dec 2021 17:02:23 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aruba.it; s=a1; t=1638547343; bh=axnz2iXZOpsRaOM1yJe8Gz9PwCsF1ixzct8ePXQAx8s=; h=From:To:Subject:Date:MIME-Version:Content-Type; b=BqmIu831hcNeDB5KJ7yJoCmc8OIGu+YIgt40ukt2dfsOtxgB/fvljMJAwtuoRfY3g kfa8blE7NJWyAdYZaW3cD8Cl8LDYmbswFTdfN2n0bFP0eDf/74DCfgJuFU+/dOz2Vt kpGbbLUthM3AStzl0h+C9EATyOkUDE6kZK7puWe3HcPYz/fhMXMDaf+i8XMbmY+Q48 0/Fwaozn+pTD4c2tcyUyhsyuZLh4jIklexhLeUvty17qrPkiHlIIjJMLfYmjF7MWXD uhLY2bKUgFO0oaJJA8oASPQx8CuIbGe4i/0GRqwOpf9wxSIyBu3oho9oHARykGd+Lb ch5JeZ4NTIvUw== From: To: Subject: [PATCH 6/6] tools/mesh-gatt: Add generic power onoff client model Date: Fri, 3 Dec 2021 17:02:22 +0100 Message-ID: <000a01d7e85f$27fedbf0$77fc93d0$@cblelectronics.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdfoXpcU6cWukPw3RuyAQPiuJHNBOA== Content-Language: it X-CMAE-Envelope: MS4xfIzP7DPMWkNgiMxSkbALpDpmuMIEmBt/zojNoxfmwqPEPwtGDrNhgaAPnpd/ZPeKv76jU5Z5dXoneDns16bMxWehsuJVyK6wHB784HKyunulUAIELzqK XV0PeV86KTiUMnm8blqYiUeZkKCa6RNzPFUT3RNTlg00aycJxVstGgQvti4z9IS+zs/DADVvvMbY2/258vuQEgnm2LT2/x5hSVMTz488noHEh2NlcFVCsYtO Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- Makefile.tools | 4 +- tools/mesh-gatt/local_node.json | 6 +- tools/mesh-gatt/onpowerup-model.c | 250 ++++++++++++++++++++++++++++++ tools/mesh-gatt/onpowerup-model.h | 21 +++ tools/meshctl.c | 4 + 5 files changed, 283 insertions(+), 2 deletions(-) create mode 100644 tools/mesh-gatt/onpowerup-model.c create mode 100644 tools/mesh-gatt/onpowerup-model.h g_dbus_client_unref(client); diff --git a/Makefile.tools b/Makefile.tools index c0d2e27de..f9fecfe9d 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -333,7 +333,9 @@ tools_meshctl_SOURCES = tools/meshctl.c \ tools/mesh-gatt/onoff-model.h \ tools/mesh-gatt/onoff-model.c \ tools/mesh-gatt/level-model.h \ - tools/mesh-gatt/level-model.c + tools/mesh-gatt/level-model.c \ + tools/mesh-gatt/onpowerup-model.h \ + tools/mesh-gatt/onpowerup-model.c tools_meshctl_LDADD = gdbus/libgdbus-internal.la src/libshared-glib.la \ lib/libbluetooth-internal.la \ $(GLIB_LIBS) $(DBUS_LIBS) -ljson-c -lreadline diff --git a/tools/mesh-gatt/local_node.json b/tools/mesh-gatt/local_node.json index 462cd815d..2c332eb1c 100644 --- a/tools/mesh-gatt/local_node.json +++ b/tools/mesh-gatt/local_node.json @@ -36,7 +36,7 @@ { "elementIndex": 0, "location": "0001", - "models": ["0000", "0001", "1001", "1003"] + "models": ["0000", "0001", "1001", "1003", "1008"] } ] }, @@ -56,6 +56,10 @@ { "modelId": "1003", "bind": [1] + }, + { + "modelId": "1008", + "bind": [1] } ] } diff --git a/tools/mesh-gatt/onpowerup-model.c b/tools/mesh-gatt/onpowerup-model.c new file mode 100644 index 000000000..4ae7713e4 --- /dev/null +++ b/tools/mesh-gatt/onpowerup-model.c @@ -0,0 +1,250 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2017 Intel Corporation. All rights reserved. + * + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "src/shared/shell.h" +#include "src/shared/util.h" + +#include "tools/mesh-gatt/mesh-net.h" +#include "tools/mesh-gatt/keys.h" +#include "tools/mesh-gatt/net.h" +#include "tools/mesh-gatt/node.h" +#include "tools/mesh-gatt/prov-db.h" +#include "tools/mesh-gatt/util.h" +#include "tools/mesh-gatt/onpowerup-model.h" + +static uint8_t trans_id; +static uint16_t power_onoff_app_idx = APP_IDX_INVALID; + +static int client_bind(uint16_t app_idx, int action) +{ + if (action == ACTION_ADD) { + if (power_onoff_app_idx != APP_IDX_INVALID) { + return MESH_STATUS_INSUFF_RESOURCES; + } else { + power_onoff_app_idx = app_idx; + bt_shell_printf("OnPowerUp client model: new binding" + " %4.4x\n", app_idx); + } + } else { + if (power_onoff_app_idx == app_idx) + power_onoff_app_idx = APP_IDX_INVALID; + } + return MESH_STATUS_SUCCESS; +} + +static bool client_msg_recvd(uint16_t src, uint8_t *data, + uint16_t len, void *user_data) +{ + uint32_t opcode; + int n; + char s[10]; + + if (mesh_opcode_get(data, len, &opcode, &n)) { + len -= n; + data += n; + } else + return false; + + switch (opcode) { + default: + return false; + + case OP_GENERIC_POWER_ONOFF_STATUS: + bt_shell_printf("OnPowerUp Model Message received (%d) opcode %x\n", + len, opcode); + print_byte_array("\t",data, len); + if (len != 1) + break; + if(data[0] == 0){ + sprintf(s, "%s", "OFF"); + }else if(data[0] == 1){ + sprintf(s, "%s", "ON"); + }else if(data[0] == 2){ + sprintf(s, "%s", "RESUME"); + }else{ + sprintf(s, "%s", "?UNKNOWN"); + } + bt_shell_printf("Node %4.4x: OnPowerUp Status present = %s\n", src, s); + break; + } + return true; +} + + +static uint32_t target; +static uint32_t parms[8]; + +static uint32_t read_input_parameters(int argc, char *argv[]) +{ + uint32_t i; + + if (!argc) + return 0; + + --argc; + ++argv; + + if (!argc || argv[0][0] == '\0') + return 0; + + memset(parms, 0xff, sizeof(parms)); + + for (i = 0; i < sizeof(parms)/sizeof(parms[0]) && i < (unsigned) argc; + i++) { + sscanf(argv[i], "%x", &parms[i]); + if (parms[i] == 0xffffffff) + break; + } + + return i; +} + +static void cmd_set_node(int argc, char *argv[]) +{ + uint32_t dst; + char *end; + + dst = strtol(argv[1], &end, 16); + if (end != (argv[1] + 4)) { + bt_shell_printf("Bad unicast address %s: " + "expected format 4 digit hex\n", argv[1]); + target = UNASSIGNED_ADDRESS; + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } else { + bt_shell_printf("Controlling OnPowerUp for node %4.4x\n", dst); + target = dst; + set_menu_prompt("OnPowerUp", argv[1]); + return bt_shell_noninteractive_quit(EXIT_SUCCESS); + } +} + +static bool send_cmd(uint8_t *buf, uint16_t len) +{ + struct mesh_node *node = node_get_local_node(); + uint8_t ttl; + + if(!node) + return false; + + ttl = node_get_default_ttl(node); + + return net_access_layer_send(ttl, node_get_primary(node), + target, power_onoff_app_idx, buf, len); +} + +static void cmd_get_status(int argc, char *argv[]) +{ + uint16_t n; + uint8_t msg[32]; + struct mesh_node *node; + + if (IS_UNASSIGNED(target)) { + bt_shell_printf("Destination not set\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + node = node_find_by_addr(target); + + if (!node){ + bt_shell_printf("Warning: node %4.4x not found in database\n",target); + } + + n = mesh_opcode_set(OP_GENERIC_POWER_ONOFF_GET, msg); + + if (!send_cmd(msg, n)) { + bt_shell_printf("Failed to send \"GENERIC POWER ONOFF GET\"\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + +static void cmd_set(int argc, char *argv[]) +{ + uint16_t n; + uint8_t msg[32]; + struct mesh_node *node; + + if (IS_UNASSIGNED(target)) { + bt_shell_printf("Destination not set\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + node = node_find_by_addr(target); + + 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 && parms[0] != 2) { + bt_shell_printf("Bad arguments: Expecting \"0\" or \"1\" or \"2\"\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + n = mesh_opcode_set(OP_GENERIC_POWER_ONOFF_SET, msg); + msg[n++] = parms[0]; + msg[n++] = trans_id++; + + if (!send_cmd(msg, n)) { + bt_shell_printf("Failed to send \"GENERIC POWER ONOFF SET\"\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + +static const struct bt_shell_menu power_onoff_menu = { + .name = "power_onoff", + .desc = "Power OnOff (OnPowerUp) Model Submenu", + .entries = { + {"target", "", cmd_set_node, + "Set node to configure"}, + {"get", NULL, cmd_get_status, + "Get OnPowerUp status"}, + {"set", "<0/1/2>", cmd_set, + "Set OnPowerUp status (OFF/ON/RESTORE)"}, + {} }, +}; + +static struct mesh_model_ops client_cbs = { + client_msg_recvd, + client_bind, + NULL, + NULL +}; + +bool power_onoff_client_init(uint8_t ele) +{ + if (!node_local_model_register(ele, GENERIC_POWER_ONOFF_CLIENT_MODEL_ID, + &client_cbs, NULL)) + return false; + + bt_shell_add_submenu(&power_onoff_menu); + + return true; +} diff --git a/tools/mesh-gatt/onpowerup-model.h b/tools/mesh-gatt/onpowerup-model.h new file mode 100644 index 000000000..f8347d830 --- /dev/null +++ b/tools/mesh-gatt/onpowerup-model.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2017 Intel Corporation. All rights reserved. + * + * + */ + +#define GENERIC_POWER_ONOFF_SERVER_MODEL_ID 0x1006 +#define GENERIC_POWER_ONOFF_SETUP_SERVER_MODEL_ID 0x1007 +#define GENERIC_POWER_ONOFF_CLIENT_MODEL_ID 0x1008 + +#define OP_GENERIC_POWER_ONOFF_GET 0x8211 +#define OP_GENERIC_POWER_ONOFF_STATUS 0x8212 +#define OP_GENERIC_POWER_ONOFF_SET 0x8213 +#define OP_GENERIC_POWER_ONOFF_SET_UNACK 0x8214 + +void power_onoff_set_node(const char *args); +bool power_onoff_client_init(uint8_t ele); diff --git a/tools/meshctl.c b/tools/meshctl.c index 69f8d412f..bd4314790 100644 --- a/tools/meshctl.c +++ b/tools/meshctl.c @@ -49,6 +49,7 @@ #include "mesh-gatt/prov-db.h" #include "mesh-gatt/onoff-model.h" #include "mesh-gatt/level-model.h" +#include "mesh-gatt/onpowerup-model.h" /* String display constants */ #define COLORED_NEW COLOR_GREEN "NEW" COLOR_OFF @@ -2003,6 +2004,9 @@ int main(int argc, char *argv[]) if (!level_client_init(PRIMARY_ELEMENT_IDX)) g_printerr("Failed to initialize mesh generic level client\n"); + if (!power_onoff_client_init(PRIMARY_ELEMENT_IDX)) + g_printerr("Failed to initialize mesh generic power On/Off client\n"); + status = bt_shell_run();