From patchwork Tue Dec 7 22:55:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Biagetti X-Patchwork-Id: 521673 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 22CFBC433FE for ; Tue, 7 Dec 2021 22:56:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242397AbhLGW7l (ORCPT ); Tue, 7 Dec 2021 17:59:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238015AbhLGW7l (ORCPT ); Tue, 7 Dec 2021 17:59:41 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49E8CC061746 for ; Tue, 7 Dec 2021 14:56:10 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id r25so1868881edq.7 for ; Tue, 07 Dec 2021 14:56:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zMhEOw0YdYVet9Z96+RsKHt4qzb6riidkXliwvhchQg=; b=EOWfKICnIN5GRuJOvOchuroxDdVyHB3K6lIE5XMKHXspoUDHFI3qjxgBhe9ITbYiUQ UwhXTwZfJB5ai2UM1jBbHVizB7a41TQne4JkvLHtof353tHybQNssFYPIQffz284DUzc Fwc2OrXcOqBQUrF/6rpjBelnEQaHDf8u1HXZgpALYdLoBA/Duchfi/GrpRjkCMCCfjzg 2iMZ/qDrRoZqYcI8eX15sxS2iL7CpbMhkrsF772oD3ouG4KBmA1NX5qt8FL637OHphHB v7UnkcI426Y6FmPqtBwgRZf3waXTTdAyHah3UGHOnPLfqN0iGjnHcR9OSwrA1+IOFDCt A6JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zMhEOw0YdYVet9Z96+RsKHt4qzb6riidkXliwvhchQg=; b=64ammtkryrxuETZsXpSu43tfrOIqXpIa0V7WN9GHRDYII1v+yQm58H8fWBgXKWwnpP YLJOAD8J3+q/C9S6Ar9hoGaq1xJW6JRPLz0IgnJqzYtpAWRllUj7q2zxr59Iv+vvtNId 2D+sqSWX4LhnrTQfQM6KtJgluGXOFP6S3j9gNTH/4cmP1TdmYNigt3E8UQBJ4dw1p6vH 94VaVvtMJeGXh9bWEv9d5gks/SL003pUx+50bywhniy0Vm0VBQRBOnPEMnQx0rqW2Iy8 dBO+8tCoc//05VL2YZ/uwbm10drzAJ5/utr8cYXb93XCVRp3+Co+vHKNy1V6gXW2gg+z r7vw== X-Gm-Message-State: AOAM531lahB5vSChM23DjE70rc8fdgoPCIIB49lDE6Mqix5iTlLCrfJr +onfmMI2Q15zXfAVa0oC8cJtANCnEOo= X-Google-Smtp-Source: ABdhPJy6heo16+68KbeTWtWrFgTk/c8iX4AOEP8td1cxEX2XtZxtY24jsf4e3dwlfOWivw5/+CvB9Q== X-Received: by 2002:a17:906:58c8:: with SMTP id e8mr2839217ejs.444.1638917768922; Tue, 07 Dec 2021 14:56:08 -0800 (PST) Received: from aspire.cbl.vpn (net-188-217-49-100.cust.vodafonedsl.it. [188.217.49.100]) by smtp.gmail.com with ESMTPSA id ho30sm489468ejc.30.2021.12.07.14.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 14:56:08 -0800 (PST) From: Daniele Biagetti X-Google-Original-From: Daniele Biagetti To: linux-bluetooth@vger.kernel.org Cc: Daniele Biagetti Subject: [PATCH BlueZ 1/6] tools/mesh-gatt: Add onoff set unack message to onoff client model Date: Tue, 7 Dec 2021 23:55:59 +0100 Message-Id: <20211207225604.35156-2-daniele.biagetti@cblelectronics.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com> References: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com> MIME-Version: 1.0 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(-) 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++; @@ -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"}, {} }, }; From patchwork Tue Dec 7 22:56:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Biagetti X-Patchwork-Id: 525138 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 06838C433EF for ; Tue, 7 Dec 2021 22:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242399AbhLGW7n (ORCPT ); Tue, 7 Dec 2021 17:59:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238015AbhLGW7m (ORCPT ); Tue, 7 Dec 2021 17:59:42 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 754B4C061574 for ; Tue, 7 Dec 2021 14:56:11 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id z5so1949485edd.3 for ; Tue, 07 Dec 2021 14:56:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yHTPc3cESSW0P5EddWkkzAEgsNh8NzxLBf/zHbglCUY=; b=AoTvx1ObzSjrsmidfnGGNw5DMfgftd3ifJC+568GwpV4N42oUUryqUsRMPy6Ju9Xmq yeSg8iot1ehMF5WAitCZqdV8aVVsUVkRXHqCCn+1zuEFDpv7lr+86yd6nOy7iB4wrwX/ QlEOa4L/i0+ndanpVwkN2LobnWdkjijmvLe9lV7y5Pofua7X8+2NSRXZOtxiQWHh9d/p 178HDouRDNB8bznOF43D/ONlCzE3zePNTveI1exWd0r0bODWCVRwCmvu6Hnac8FFfGvU AtsVJWEhJNgqZS0sZml7y0NNx4FVbxApYvXknUE6iKlico3dybiL6N7agNfdbb4B24zE x4wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yHTPc3cESSW0P5EddWkkzAEgsNh8NzxLBf/zHbglCUY=; b=MrL3tod3QTr2c9PelqSgfAowBmVdOOQF3tFhyZkDnz0aFXrtfzm3wZk1mJB0kP9znd dLDUqFvsL61xBJ+I1yzzj6nViuOdULH6YJpy3j22q3wC6QjKXNX0Fy3V7mChtMOfGIj5 DSWiduNPKy0VQLCUVcWE9ersqs6vpN46VtIvJgSupN4G894RiF1qJ/S2dbAptn0Fo8rN RPUPVvJjcaYADT6CL7BHSTmBuq56s/JOiHv5xKsy7CYlKhvxtfTruBWFTlvyQ32zOkDQ pdO5EkVRwmjweDH/TZBw/gq2Mj1aqfinLwPgLO1L/+iDt+NxD5jT/2T6tUhqzsOatvy8 p4UA== X-Gm-Message-State: AOAM530wU6qaNzczZh75Np5s4Sub2nopzcz2E5dQpK1lj2KCVCRI3vPL yBYBX/Ks/rUybPDcwFDdGiFsqtFYPKE= X-Google-Smtp-Source: ABdhPJxElm/bZNV6AV3XaFxMwrLlkwxkSwE18+hpmv5KB0jhl8MNLj4Tuap+ZsYaD8LHuDdd9XlmUA== X-Received: by 2002:a50:e0c9:: with SMTP id j9mr13604127edl.336.1638917770044; Tue, 07 Dec 2021 14:56:10 -0800 (PST) Received: from aspire.cbl.vpn (net-188-217-49-100.cust.vodafonedsl.it. [188.217.49.100]) by smtp.gmail.com with ESMTPSA id ho30sm489468ejc.30.2021.12.07.14.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 14:56:09 -0800 (PST) From: Daniele Biagetti X-Google-Original-From: Daniele Biagetti To: linux-bluetooth@vger.kernel.org Cc: Daniele Biagetti Subject: [PATCH BlueZ 2/6] tools/mesh-gatt: Fix status messages processing Date: Tue, 7 Dec 2021 23:56:00 +0100 Message-Id: <20211207225604.35156-3-daniele.biagetti@cblelectronics.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com> References: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com> MIME-Version: 1.0 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(-) 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 + bt_shell_printf("%s\n", s); + break; } From patchwork Tue Dec 7 22:56:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Biagetti X-Patchwork-Id: 521672 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 DEA10C433F5 for ; Tue, 7 Dec 2021 22:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242401AbhLGW7n (ORCPT ); Tue, 7 Dec 2021 17:59:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242400AbhLGW7n (ORCPT ); Tue, 7 Dec 2021 17:59:43 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45ECEC061574 for ; Tue, 7 Dec 2021 14:56:12 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id w1so1888595edc.6 for ; Tue, 07 Dec 2021 14:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mTxRFAKeAsHwDITQiCzTJ+Q6rYIr9mXEv3r5v8AK5ls=; b=Y4TFbbe7J04AGJ039hKDma4pK9DePv28yLyP3L2DkaOiEwGGJJ8q4w+sYXNPDc3zIp xYJiajnmyAl8dAJ+oy12CnmDNneL6sN/uQ5KYvUetqkhKm2EYFjvOUschJ3VsPlHW3Zz 9OBYzH48JYKP91yu9nShUyK/bTglVevoYpsWNn+x0F183uNPEB3A+m3e/u+uEs0Pp2gk vDb/RbqKpwy78nkObHOw1TB2XvRMQOveVxkodtx57s3bXvfCzoE2KOplZYDdi+wUFGzX /rVSgh2L798qQ14XhhuGoyPXkyExYdks4lPO60vXv2PuRmdt+TG4/GnRFkyrpFltBKaM uYqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mTxRFAKeAsHwDITQiCzTJ+Q6rYIr9mXEv3r5v8AK5ls=; b=XuYxfh2zrKHfi3UQNVoq9TRUDDjEqk/ifQJGxWnVhog/+E+SWtSOc89+2eIJxinfYw m61Kb1Ws2sPmvsfg95o0YqLeqcNDmPxaFB/8fbmPHGZwzc/v1zJ+JqsIlrXP03LZiTW9 38Eyzq9hoXeQtCr/Bvd1+Ud3PTKDziCxPYNUV1TsDUXuUP0Csy5y6YzfaY12Wjcu+OS8 592njDRF4gN0lQXz9eqsUa+K6D5PdrOohHtsLZ/6bZaa2aYXx68srEYnGceUssOeVaQU FUHgsxR98YA5pXynxWkpi/CxucM4nUQ02WLH8CMlM6whj3ttX7k9rGus2V8oN0CADiLM 5O3w== X-Gm-Message-State: AOAM533Ubtk+4coYCEyZa3hIt4kIEPqCT1EMmWe7iI1HUfgoS32O6wOV ZsYd5JFGBclW5JSG2eUJMKBaHDiIy+I= X-Google-Smtp-Source: ABdhPJwvfUnI1ZoYk/CyTUW/jyHpZsFRqXWAg1RAYt7KCXI45URu7nuh0HSgJtG2lsiar1byY1ChdQ== X-Received: by 2002:a05:6402:90e:: with SMTP id g14mr13910565edz.49.1638917770855; Tue, 07 Dec 2021 14:56:10 -0800 (PST) Received: from aspire.cbl.vpn (net-188-217-49-100.cust.vodafonedsl.it. [188.217.49.100]) by smtp.gmail.com with ESMTPSA id ho30sm489468ejc.30.2021.12.07.14.56.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 14:56:10 -0800 (PST) From: Daniele Biagetti X-Google-Original-From: Daniele Biagetti To: linux-bluetooth@vger.kernel.org Cc: Daniele Biagetti Subject: [PATCH BlueZ 3/6] tools/mesh-gatt: Fix unwanted return in onoff client model Date: Tue, 7 Dec 2021 23:56:01 +0100 Message-Id: <20211207225604.35156-4-daniele.biagetti@cblelectronics.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com> References: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com> MIME-Version: 1.0 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(-) 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); @@ -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) && From patchwork Tue Dec 7 22:56:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Biagetti X-Patchwork-Id: 525137 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 0616AC4332F for ; Tue, 7 Dec 2021 22:56:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242407AbhLGW7p (ORCPT ); Tue, 7 Dec 2021 17:59:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242400AbhLGW7o (ORCPT ); Tue, 7 Dec 2021 17:59:44 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28A4CC061574 for ; Tue, 7 Dec 2021 14:56:13 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id y13so1752310edd.13 for ; Tue, 07 Dec 2021 14:56:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yZi0bAN+7dNGL/Dc4WYuqpEaP070jZnR5ZkGoeW86hg=; b=k2aj/xZLtIkUDQzYmT6e/7r0ZnfmbSwdbDjj1gIi3cfRluk8Oj6q0RNTsHXzTCzY9w GGYQe0/cGK4bQIgJfL5eRJgSB5jkYs7/x97YY06ed/MU4bPVBtGjmEiVJ6DN+pf5u51k Nq3ozqfYC3Fz7wnzvL+oBC97SpCZlX4KO3eJuvJcDyragbAElXGm/yTeVFbGTA+qxNDY 8B0R5ET27YIMZQd5Kga2l0w5dCYjrdmBea8isIaYu09+24vLhjjNO7VocXx3VaGBgoAc mkZTwidGXdQssmhTitF3b5RoedovLprARxRjHdSFPW8WU4iH5pvl3rBTTdPmpmBRZvJC sF/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yZi0bAN+7dNGL/Dc4WYuqpEaP070jZnR5ZkGoeW86hg=; b=N35Cph5KIS8M8BNvgceiRvUPWw0YmrQExHpiWEY618sPhprWeowvjlLenP9oTCiYHd EOIDFm//Xm4QONSbJNv5cN1SS9rBGCtLF2CiTXVKSwwpwQ8EB/xHlPR3imCRp5zRm0KP oW+LQHR73G4E0lX+rKTwUzeYuTaOiZoT97B3eK/gaMswfHDqCjYNeqRy0PCbdTgcj4HU Q+Y6PJ1c0FQR0ZUEfGODO+SOdqb6Oco+4GR+sm2CR9uUJqaXnT9uD4TZd0U+AjW5g5B2 eDgj3VWCIUEDT3JEo0EjIwDX5FXTq17x/y9/bXSpk6CxCR7SRiTbl9zCatw2Dk79GW16 QsmA== X-Gm-Message-State: AOAM531FkiSvCIyor+tuT7Zdv6NvWzcrKFr3EZNa0T7LkWlMOH4sWwWU yLh2e4y4aUFiaI2MH9jzMQQ27G/ynmE= X-Google-Smtp-Source: ABdhPJy+6chSGzmmO3M95ZzZx0gSSdlxOKF2i4TBVGdQRJCqzaoNxwyBnmFD9TKWzLN6bsgMH6FFmQ== X-Received: by 2002:a17:906:5501:: with SMTP id r1mr2843823ejp.212.1638917771797; Tue, 07 Dec 2021 14:56:11 -0800 (PST) Received: from aspire.cbl.vpn (net-188-217-49-100.cust.vodafonedsl.it. [188.217.49.100]) by smtp.gmail.com with ESMTPSA id ho30sm489468ejc.30.2021.12.07.14.56.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 14:56:11 -0800 (PST) From: Daniele Biagetti X-Google-Original-From: Daniele Biagetti To: linux-bluetooth@vger.kernel.org Cc: Daniele Biagetti Subject: [PATCH BlueZ 4/6] tools/mesh-gatt: Add subscription delete message to config client model Date: Tue, 7 Dec 2021 23:56:02 +0100 Message-Id: <20211207225604.35156-5-daniele.biagetti@cblelectronics.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com> References: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- tools/mesh-gatt/config-client.c | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) 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[]) { 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"}, {} }, From patchwork Tue Dec 7 22:56:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Biagetti X-Patchwork-Id: 521671 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 A0F0BC433EF for ; Tue, 7 Dec 2021 22:56:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242402AbhLGW7p (ORCPT ); Tue, 7 Dec 2021 17:59:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242406AbhLGW7p (ORCPT ); Tue, 7 Dec 2021 17:59:45 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11312C061574 for ; Tue, 7 Dec 2021 14:56:14 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id y12so1771299eda.12 for ; Tue, 07 Dec 2021 14:56:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kDtncV0X18jLkh0djRbT0CuZQuqr8VeMjw0GoDi905E=; b=SmZ7NVB3n9e3GvG/yRZlLFIbryI37phuIs2NUxPrMv+dZ73gSjN9FscE0a2cZQz/XT RM81MIFFbf8XZ1XVVPcXgicRxchKSY65FV8qyGQkEyYyE2OrVmOA1KPy8/nvClTIlJUS U+rtx9U0AH+hwuawwU1GRRQbITnFmFrdqiGgtg75GYUrYAEszExYY9AhCxf0ubg7PRjk eocq94shSUAwNdMQboVgrado6BoGYh/sUSHuH9tSyiCQ5lCIznqKm/d0x+PeLg7cs+SJ 6dMVMCSV33k4fNfT4oNMhuHm0iGtgMZ7IxiPod9ccnFFlYA6/nV4/Zp7RSqh85GGSlU9 9dSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kDtncV0X18jLkh0djRbT0CuZQuqr8VeMjw0GoDi905E=; b=p7/okRmno5k6H3F0utyBAVKfXu0dD6PhfyNJSS8iU0/EJ9NxFhFvuMallWFOx2uaCj bNqdmE2AOxgvKOLYb0KpeqNG6Mmv30UhMZn3JpdOtmPsuDhX/0EXK30dMlPYWpryLfXN 8UYvKGORGo8V2d4kM28faATUpw41UzYfqQ56x11r4mVp+8XQTb9UdWV0aw4+hVWqC5B0 OuzgEDs+f5e80qkjPVsCUb4wNSPnct0eqBIY2DhJd4zPKNyA0C4DCY4gQ6dGzuvOO55E jXKPkLEvAzFsi6MvZsQDX3Fk3nbyvTPcZROpv7Gm2ydAzCL0QbDPpgT17joMbsWM4Wci zLuA== X-Gm-Message-State: AOAM533fXMSuxf3xI8N5nQEmQ5l77TZTw691Kmac3If8SZ/NnfrWnDoM pcSmuXibCOJmgj3rYMJowA/BY/9VlIc= X-Google-Smtp-Source: ABdhPJxkPDL8RwUEnSP1ujHHocHB8yCik+tT0SwzLgFGPU0MCUAyVdGzCcLEFBm8PNQeHRM60aMRzQ== X-Received: by 2002:a05:6402:42d5:: with SMTP id i21mr13502005edc.373.1638917772616; Tue, 07 Dec 2021 14:56:12 -0800 (PST) Received: from aspire.cbl.vpn (net-188-217-49-100.cust.vodafonedsl.it. [188.217.49.100]) by smtp.gmail.com with ESMTPSA id ho30sm489468ejc.30.2021.12.07.14.56.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 14:56:12 -0800 (PST) From: Daniele Biagetti X-Google-Original-From: Daniele Biagetti To: linux-bluetooth@vger.kernel.org Cc: Daniele Biagetti Subject: [PATCH BlueZ 5/6] tools/mesh-gatt: Add generic level model support Date: Tue, 7 Dec 2021 23:56:03 +0100 Message-Id: <20211207225604.35156-6-daniele.biagetti@cblelectronics.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com> References: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com> MIME-Version: 1.0 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 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(); g_dbus_client_unref(client); From patchwork Tue Dec 7 22:56:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Biagetti X-Patchwork-Id: 525136 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 A3D57C433F5 for ; Tue, 7 Dec 2021 22:56:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242418AbhLGW7q (ORCPT ); Tue, 7 Dec 2021 17:59:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242406AbhLGW7q (ORCPT ); Tue, 7 Dec 2021 17:59:46 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6BD4C061574 for ; Tue, 7 Dec 2021 14:56:14 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id y13so1752491edd.13 for ; Tue, 07 Dec 2021 14:56:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k29Yask3mdkR+7G6OrLgpmlSD3gqpf13sdN5hx+HlFE=; b=ZIzngSvU3CyHtCRQ1WiShIo6swOZ7nHsWzEHlDLdOGG/vHkALMDaqNEb+ro8EVthtH TTKO7gSFOtiuNgdLbMkoHu85YdVdp6Bv+N/h/2VuTI4ReRYLBJBIyjDnWDWWC4g8bSKx WWfhdtiZX/B7hqQdvOqeNnf5n/xT7EVxO7aW4hKfaX6LTJ+IaluMCsa7DaT5zTizkDpE WtN19+4IIRVbI5CALjmqIlppL0juCBtr9gEL39STnwDcRXijI0mnlrBlnHAApUpamcyQ lfBk/gBNC4sbqkmbrN0M65oHSfbGFNOrTMU7VgJ3//ATrVkmKNhYZTecKVFG2VLXuJsZ i3ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k29Yask3mdkR+7G6OrLgpmlSD3gqpf13sdN5hx+HlFE=; b=VgJidpWzbHglvrZHnSGJpyKrxcvyRwNNHb+mQfHiL2FHGixSDGLEgtSac0jgWkTIsE KShF/Qykt6EOX4o/xMHPPUinXC8kTQvpyAoZeO4qGHIKxFdq/VIKeyPaBT4x8ZwJib5k 5LdnzZN3CffPkJsyryerSczm7E++rRSTSRao/yWKhV/1wka6p/c0UgzNHkSQ8yt7wd6l CAKyNehjhX9laom/h90qQ9dGi26k4sl/gVhObR91R6lpIDF4iTsQ+qFjrOV9/KPqfKMp mZBj0Gh1UWklUBY7abNHS50Ln5Wogs7shTjBiBl8fy3PrNvfpn4jGY6aj9FOaI3191EN Yf1w== X-Gm-Message-State: AOAM530jIZPNCGrQShm65Vcvz8X619/Vl3bzOqCvpcaNoBBOB3CYuqVJ 7GgnsmOKGlYmWSD2I8m5EodAsi7760g= X-Google-Smtp-Source: ABdhPJwHILBP+anZvlM58PnbBKyH80RnBVx4a3WlKmPyRVCWdoZGp5aVWtwQvwEws0Oqs557WSQlKw== X-Received: by 2002:a17:907:96aa:: with SMTP id hd42mr2876952ejc.385.1638917773492; Tue, 07 Dec 2021 14:56:13 -0800 (PST) Received: from aspire.cbl.vpn (net-188-217-49-100.cust.vodafonedsl.it. [188.217.49.100]) by smtp.gmail.com with ESMTPSA id ho30sm489468ejc.30.2021.12.07.14.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 14:56:13 -0800 (PST) From: Daniele Biagetti X-Google-Original-From: Daniele Biagetti To: linux-bluetooth@vger.kernel.org Cc: Daniele Biagetti Subject: [PATCH BlueZ 6/6] tools/mesh-gatt: Add generic power onoff client model Date: Tue, 7 Dec 2021 23:56:04 +0100 Message-Id: <20211207225604.35156-7-daniele.biagetti@cblelectronics.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com> References: <20211207225604.35156-1-daniele.biagetti@cblelectronics.com> MIME-Version: 1.0 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 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(); g_dbus_client_unref(client);