From patchwork Tue Jan 5 03:12:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11998045 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAA9AC433E9 for ; Tue, 5 Jan 2021 03:13:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84C4D22573 for ; Tue, 5 Jan 2021 03:13:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728091AbhAEDNs (ORCPT ); Mon, 4 Jan 2021 22:13:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727716AbhAEDNs (ORCPT ); Mon, 4 Jan 2021 22:13:48 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2237C061795 for ; Mon, 4 Jan 2021 19:13:07 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id e74so54552235ybh.19 for ; Mon, 04 Jan 2021 19:13:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=KK6nLKsHQCELPyl1S4Arx6g2G/0sGXXhy1Tvx8l1irY=; b=EChvkFSH+/hC+LmKY5AT1KfK/ubaXNHvTiNyATxvqZn9i3i0Dh68FkTCeWxMt8yOqq bwupUDv2ffRc/rXg71wfzSZ73UybK6xnBDYzvAl7nlY2Pt2Oz97ZJhRvng1VVwOGzl3B jFIo8sLeLP77aEm+vclJtv253n0L5D4Bv4Zd9qEZmuoHUtdmle/Jvj7bsmJYtcVfc5I4 /7fPlrmQtDCpd9tY4L+FGtUjcdGhSBC99334dNCedbFGybRrIuo+DQNegPDuEJuBWT7F ebwTfESJ/woD9EZc45tBhecEgKaJ1v/puD4JnVh9F13HR2zS0++82O5oLwuxCFh446DI Jv9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=KK6nLKsHQCELPyl1S4Arx6g2G/0sGXXhy1Tvx8l1irY=; b=E3+BpDZaRPjpVElFIBfhC2FMG+UsfUjGJgIwWGUqt5QBnuvRWguWPAhY/WBdV/9KOK nN56XpNL8GaIVd9m2qWGxm9A/6Ek5H8towVrEfgBB0DQxHYikQVVOUfwsyv/YsdXpkNf 7Cev7IHi5UzQM1PtDjesN1faVFMt8doriX9pKYIfQ3UTMsORsC4Yagz/yVcC+t1fLdjh lMTc0JY3vxK3MYxm3xHNnKl4CKqNGuz87JttCn8qqLwkgEpM3G+9XYEUmeYcs+r9KCiQ sKxuss8glVpCkq1U7IuOlHqKi5xllnJ4jv9MOkQFaPfBPCU2vScF7vHerU3qDz8VRMEV wASQ== X-Gm-Message-State: AOAM530nvIJBuJlwwYeXwsxVczQ1E2SDiZUWDrHxxaLH0IbkfvkARYtt 2Y9XmLs5R+P4yFz3pIgDbNXt9T+FYChvterPvhoWRprpvqMZb4DMPXKSIbnt7eOX9H7sqIlNaq6 YERbepf4nQWj2KN1c7tqYyCPy2tv3EVD9UxfgwYPsQUk9gjcUjZ9Ah29msO9a8hpCNf7EpeHgnK 0p59gRQf0cOsw= X-Google-Smtp-Source: ABdhPJzRAqawhiQH5pKQ1pXiRfTUqx3sBnZlUvk8Y7/25yqJj7VyxmR6nRSZ780oyca/1YNvZGZNdrfUqvcz4e5bVA== Sender: "howardchung via sendgmr" X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:f693:9fff:fef4:4e45]) (user=howardchung job=sendgmr) by 2002:a25:7789:: with SMTP id s131mr111959638ybc.212.1609816386998; Mon, 04 Jan 2021 19:13:06 -0800 (PST) Date: Tue, 5 Jan 2021 11:12:54 +0800 Message-Id: <20210105111219.Bluez.v4.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v4 1/4] shared/mgmt: Add supports of parsing mgmt tlv list From: Howard Chung To: linux-bluetooth , luiz.dentz@gmail.com Cc: mcchou@chromium.org, apusaka@chromium.org, mmandlik@chromium.org, Howard Chung Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Response from Read System Default Configuration is a list of mgmt_tlv, which requires further processing to get the values of each parameters. This adds APIs for parsing response into mgmt_tlv_list, retrieving parameter from mgmt_tlv_list. Reviewed-by: apusaka@chromium.org --- Changes in v4: - Simply use free instead of mgmt_tlv_free Changes in v3: - Fix CheckBuild error Changes in v2: - Fix incompatible pointer type error in mgmt_tlv_list_load_from_buf src/shared/mgmt.c | 38 ++++++++++++++++++++++++++++++++++++++ src/shared/mgmt.h | 6 ++++++ 2 files changed, 44 insertions(+) diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c index 9ea9974f5535..dc8107846668 100644 --- a/src/shared/mgmt.c +++ b/src/shared/mgmt.c @@ -626,6 +626,44 @@ static void mgmt_tlv_to_buf(void *data, void *user_data) *buf_ptr += entry_size; } +struct mgmt_tlv_list *mgmt_tlv_list_load_from_buf(const uint8_t *buf, + uint16_t len) +{ + struct mgmt_tlv_list *tlv_list; + const uint8_t *cur = buf; + + if (!len || !buf) + return NULL; + + tlv_list = mgmt_tlv_list_new(); + + while (cur < buf + len) { + struct mgmt_tlv *entry = (struct mgmt_tlv *)cur; + + cur += sizeof(*entry) + entry->length; + if (cur > buf + len) + goto failed; + + if (!mgmt_tlv_add(tlv_list, entry->type, entry->length, + entry->value)) { + goto failed; + } + } + + return tlv_list; +failed: + mgmt_tlv_list_free(tlv_list); + + return NULL; +} + +void mgmt_tlv_list_foreach(struct mgmt_tlv_list *tlv_list, + mgmt_tlv_list_foreach_func_t callback, + void *user_data) +{ + queue_foreach(tlv_list->tlv_queue, callback, user_data); +} + unsigned int mgmt_send_tlv(struct mgmt *mgmt, uint16_t opcode, uint16_t index, struct mgmt_tlv_list *tlv_list, mgmt_request_func_t callback, diff --git a/src/shared/mgmt.h b/src/shared/mgmt.h index 319beb62f9eb..808bf4c7ff09 100644 --- a/src/shared/mgmt.h +++ b/src/shared/mgmt.h @@ -41,6 +41,12 @@ bool mgmt_tlv_add(struct mgmt_tlv_list *tlv_list, uint16_t type, uint8_t length, #define mgmt_tlv_add_fixed(_list, _type, _value) \ mgmt_tlv_add(_list, _type, sizeof(*(_value)), _value) +struct mgmt_tlv_list *mgmt_tlv_list_load_from_buf(const uint8_t *buf, + uint16_t len); +typedef void (*mgmt_tlv_list_foreach_func_t)(void *data, void *user_data); +void mgmt_tlv_list_foreach(struct mgmt_tlv_list *tlv_list, + mgmt_tlv_list_foreach_func_t callback, + void *user_data); unsigned int mgmt_send_tlv(struct mgmt *mgmt, uint16_t opcode, uint16_t index, struct mgmt_tlv_list *tlv_list, mgmt_request_func_t callback, From patchwork Tue Jan 5 03:12:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11998047 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50D8EC433E0 for ; Tue, 5 Jan 2021 03:14:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 225C422573 for ; Tue, 5 Jan 2021 03:14:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728137AbhAEDNw (ORCPT ); Mon, 4 Jan 2021 22:13:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727716AbhAEDNw (ORCPT ); Mon, 4 Jan 2021 22:13:52 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2255C061796 for ; Mon, 4 Jan 2021 19:13:11 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id w17so54437542ybl.15 for ; Mon, 04 Jan 2021 19:13:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=kiatny/Rcuc64s8UOi4ZGZPPONmshKs7gN1XYmzrd+4=; b=jo1eR4vPYZMe3ZOptORJvRBF5xJMnOlvUUTU+nPSw3tGe/t1vsxEnudXODbd5Jq111 eYTLanXBvjdd8pFxCKYn21R61OeCkJXSXo8n9TZBxOPSZkeloCBGwZTG4m3PdtaxUdY2 SQ9DYVYwPfviurVY1THCg2LXkGnkrsDoaSYoikJvd9Le9o1AdCLPNwXLcy1LE8op4oOo iP9APGtWxzGinTPqCc9b5EelOa0dt4MfVbpwj6WXH9NZMvpUHdNmfkSJ79LFjKYOZWGq md/cOygS6i5YfXdxH0+hSjXOm2vzBikXSD2mwZ3cmvMEjwSvYnXbJtB7TgLLT7ZizKPP TNPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=kiatny/Rcuc64s8UOi4ZGZPPONmshKs7gN1XYmzrd+4=; b=pkwgPIbMUbAfBQosSiTO6lN3KPMt5e4Tx6oDJuw7KldRCmwwqR7ZKDOTitKM8JPciq TjvDunrEmIRHOFpXExgvFo7t3O7BnO46H7kHHEfMTlInpsUfcFXSkJT7PLqMUSoNObvH gEsFY9LfDFdy7RreOvSR7v4frMI9+lhY7avhYibqqD1C6YY+6UuUhHGfph++jlhk/YzL d7Icx/uPowGDLVj68QKAumfvuApU+1MmOswAG5QyS336Ymdbtmce3koUjuUGiFxKWgcB sLadbJlaTLyGcGBaIqS38ciwSJqsO0KuRGo2J4YVfVO0VSlH7qmGI8O+0pO30c9CXqMg npTA== X-Gm-Message-State: AOAM530K6THQ7KgcmBH/GtQ4eH8FwDHPAEooWXChjE5Ym5nKI0jbpAxS YrpNj3ny92sC6w3cvRpVcQC/TS857cfjK87/i9PIk/DgHX8KdyrMef9b8fYc4zdstqW1dxx7kJV /E25DfcgbHgLRwMduC9SOyZJgAZM0JrdVwZPbtmup2no2pyCL69VzUiPOOQUKFzwcfLZ5ZuNTbK XE6DWEG0cDh5I= X-Google-Smtp-Source: ABdhPJxX6CLYQ+8iEUs6Zpd6S0eVqdWTf1WjnEerpfU1r8y8AKGYdjYxzZzP937IYZtGll0mFsVtKA39SNQTd2VrYg== Sender: "howardchung via sendgmr" X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:f693:9fff:fef4:4e45]) (user=howardchung job=sendgmr) by 2002:a25:2c58:: with SMTP id s85mr110965846ybs.366.1609816391125; Mon, 04 Jan 2021 19:13:11 -0800 (PST) Date: Tue, 5 Jan 2021 11:12:55 +0800 In-Reply-To: <20210105111219.Bluez.v4.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20210105111219.Bluez.v4.2.I0c07c297925f838138b42674ab244572e6ea361b@changeid> Mime-Version: 1.0 References: <20210105111219.Bluez.v4.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v4 2/4] btmgmt: Add command read-sysconfig From: Howard Chung To: linux-bluetooth , luiz.dentz@gmail.com Cc: mcchou@chromium.org, apusaka@chromium.org, mmandlik@chromium.org, Howard Chung Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Add command read-sysconfig in btmgmt Example usage: localhost ~ # btmgmt [mgmt]# read-sysconfig Type: 0x0000 Length: 02 Value: 0000 Type: 0x0001 Length: 02 Value: 0008 ... Type: 0x001f Length: 01 Value: 01 Reviewed-by: apusaka@chromium.org --- (no changes since v3) Changes in v3: - Removed unused variable in read_sysconfig_rsp tools/btmgmt.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index 2f7cb2efcc38..7d83d3ee6bd5 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -1752,6 +1752,52 @@ static void cmd_exp_debug(int argc, char **argv) } } +static void print_mgmt_tlv(void *data, void *user_data) +{ + const struct mgmt_tlv *entry = data; + char buf[256]; + + bin2hex(entry->value, entry->length, buf, sizeof(buf)); + print("Type: 0x%04x\tLength: %02hhu\tValue: %s", entry->type, + entry->length, buf); +} + +static void read_sysconfig_rsp(uint8_t status, uint16_t len, const void *param, + void *user_data) +{ + struct mgmt_tlv_list *tlv_list; + + if (status != 0) { + error("Read system configuration failed with status " + "0x%02x (%s)", status, mgmt_errstr(status)); + return; + } + + tlv_list = mgmt_tlv_list_load_from_buf(param, len); + if (!tlv_list) { + error("Unable to parse response of read system configuration"); + return; + } + + mgmt_tlv_list_foreach(tlv_list, print_mgmt_tlv, NULL); + mgmt_tlv_list_free(tlv_list); +} + +static void cmd_read_sysconfig(int argc, char **argv) +{ + uint16_t index; + + index = mgmt_index; + if (index == MGMT_INDEX_NONE) + index = 0; + + if (!mgmt_send(mgmt, MGMT_OP_READ_DEF_SYSTEM_CONFIG, index, + 0, NULL, read_sysconfig_rsp, NULL, NULL)) { + error("Unable to send read system configuration cmd"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } +} + static void auto_power_enable_rsp(uint8_t status, uint16_t len, const void *param, void *user_data) { @@ -5030,6 +5076,8 @@ static const struct bt_shell_menu main_menu = { cmd_expinfo, "Show experimental features" }, { "exp-debug", "", cmd_exp_debug, "Set debug feature" }, + { "read-sysconfig", NULL, + cmd_read_sysconfig, "Read System Configuration" }, {} }, }; From patchwork Tue Jan 5 03:12:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11998049 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64EBDC433DB for ; Tue, 5 Jan 2021 03:14:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A50222581 for ; Tue, 5 Jan 2021 03:14:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728175AbhAEDOR (ORCPT ); Mon, 4 Jan 2021 22:14:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728138AbhAEDOQ (ORCPT ); Mon, 4 Jan 2021 22:14:16 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7801C061798 for ; Mon, 4 Jan 2021 19:13:15 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id q11so54735350ybm.21 for ; Mon, 04 Jan 2021 19:13:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=lXQ0LpCr8+V+7Lii7uhFuJpkcYXzYIJ/ONcFeoVEIR4=; b=jcmsbc72OuqdaSQeaTfO8rvp9crZv/yEAZ0FIvsIePK4nDA9dzzdlv/EtP2eR/nWZ/ fZIly9qtXrfVsf9zLMIL72EE9EiOXnb4hr4BxLPehWGlPK3hNMc4Fj9yfnLOPVMcLxsW ARYiMbRNd7Rj0h5x5MCVXGIzCdUO59TWvT1BTkSUZ0BMTUjABWvQzUeSuYasYmfIdYdj khr2uKVQJaC2iiWQXGvBk9cyosx9Ia7LuDfUKRrzsjHejDpr/KjsrG7C+Pbt8gMasUzz 3zLALoOKmoAHDaX7/5qWj0IOjB9SR6uzRqQ2hlX28BHmeN0FVS93afDkjuObQKFmvgb7 NM0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=lXQ0LpCr8+V+7Lii7uhFuJpkcYXzYIJ/ONcFeoVEIR4=; b=NW/zuiwBpQCe59KnvPQdxma02yMamMW6pmWmZdpUCz+2GULcu8FCnJO56d+crL9OhP vptqbWgk/TvCDky6Wf00YYHHigQRRdCIHgXqEOjKvRP4ubG+mJBNhs3bHq0BupNPnAVT o2S1YZTeaxIC5aE5G745V5NIvbkaw5wyS4B0+xqFDZB2ZyuAPoQaTHYk3R+xqQqURomx CEfnUnXm4z3orX9OwtvmZ6BSb7+vZCAFn68p1bpSXbtTxZGP9hLlW+qvXRJkNwORnnZj fxIjvyRHFDjuir+47qezqE0q/x68e6vtS/yOUAKXOLsfn5oDlZvRKDjrbm9aj+zXj8KC dL0Q== X-Gm-Message-State: AOAM533oVjg1qm8PE6+1oSkE1Jh8IBlSVTU/q7xp/YtnHd/w0ec5G64S j9IEZ5yDuj4V8SpbQoZaCbqDtZlTRcnoRVGCtiVJFgIja5iA5SMZIzSzK2hWrGZ33e3A3jajVcA C65TnL/1ghondduhSn5g5s4D2qIKT/H7Ja8khlcsMDT7ntCpoP1HsAgoqpOdfKztTmcN8iyELAY 899zIwfrOLkho= X-Google-Smtp-Source: ABdhPJwDMPE5mxFkAdIEPsydvbToi3occBJKcP34/aUse6cI2g26/JOpXpPQhXbPZIK5rNFr8VeA1/88PRHN27GGbg== Sender: "howardchung via sendgmr" X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:f693:9fff:fef4:4e45]) (user=howardchung job=sendgmr) by 2002:a25:2e07:: with SMTP id u7mr107298310ybu.393.1609816394868; Mon, 04 Jan 2021 19:13:14 -0800 (PST) Date: Tue, 5 Jan 2021 11:12:56 +0800 In-Reply-To: <20210105111219.Bluez.v4.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20210105111219.Bluez.v4.3.Idca009971ca95228a3fa7232ef648f18ff64d185@changeid> Mime-Version: 1.0 References: <20210105111219.Bluez.v4.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v4 3/4] btmgmt: Add command set-sysconfig From: Howard Chung To: linux-bluetooth , luiz.dentz@gmail.com Cc: mcchou@chromium.org, apusaka@chromium.org, mmandlik@chromium.org, Howard Chung Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Add command set-sysconfig in btmgmt Example usage: [mgmt]# set-sysconfig -h Parameters: -v ... e.g.: set-sysconfig -v 001a:2:1234 001f:1:00 [mgmt]# set-sysconfig -v 8:2:abcd 1:02:0100 0016:2:0600 Reviewed-by: apusaka@chromium.org --- (no changes since v2) Changes in v2: - Replace hard tabs with soft tabs in commit messages tools/btmgmt.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index 7d83d3ee6bd5..850268b4c322 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -1798,6 +1798,113 @@ static void cmd_read_sysconfig(int argc, char **argv) } } +static bool parse_mgmt_tlv(const char *input, uint16_t *type, uint8_t *length, + uint8_t *value) +{ + int i, value_starting_pos; + + if (sscanf(input, "%4hx:%1hhu:%n", type, length, + &value_starting_pos) < 2) { + return false; + } + + input += value_starting_pos; + + if (*length * 2 != strlen(input)) + return false; + + for (i = 0; i < *length; i++) { + if (!sscanf(input + i * 2, "%2hhx", &value[i])) + return false; + } + + return true; +} + +static void set_sysconfig_rsp(uint8_t status, uint16_t len, const void *param, + void *user_data) +{ + if (status != MGMT_STATUS_SUCCESS) { + error("Could not set default system configuration with status " + "0x%02x (%s)", status, mgmt_errstr(status)); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + print("Set default system configuration success"); + + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + +static bool set_sysconfig(int argc, char **argv) +{ + struct mgmt_tlv_list *tlv_list = NULL; + int i; + uint16_t index, type; + uint8_t length; + uint8_t value[256] = {}; + bool success = false; + + index = mgmt_index; + if (index == MGMT_INDEX_NONE) + index = 0; + + tlv_list = mgmt_tlv_list_new(); + if (!tlv_list) { + error("tlv_list failed to init"); + goto failed; + } + + for (i = 0; i < argc; i++) { + if (!parse_mgmt_tlv(argv[i], &type, &length, value)) { + error("failed to parse"); + goto failed; + } + + if (!mgmt_tlv_add(tlv_list, type, length, value)) { + error("failed to add"); + goto failed; + } + } + + if (!mgmt_send_tlv(mgmt, MGMT_OP_SET_DEF_SYSTEM_CONFIG, index, + tlv_list, set_sysconfig_rsp, NULL, NULL)) { + error("Failed to send \"Set Default System Configuration\"" + " command"); + goto failed; + } + + success = true; + +failed: + if (tlv_list) + mgmt_tlv_list_free(tlv_list); + + return success; +} + +static void set_sysconfig_usage(void) +{ + bt_shell_usage(); + print("Parameters:\n\t-v ...\n" + "e.g.:\n\tset-sysconfig -v 001a:2:1234 001f:1:00"); +} + +static void cmd_set_sysconfig(int argc, char **argv) +{ + bool success = false; + + if (strcasecmp(argv[1], "-v") == 0 && argc > 2) { + argc -= 2; + argv += 2; + success = set_sysconfig(argc, argv); + } + + if (!success) { + set_sysconfig_usage(); + bt_shell_noninteractive_quit(EXIT_FAILURE); + } +} + static void auto_power_enable_rsp(uint8_t status, uint16_t len, const void *param, void *user_data) { @@ -5078,6 +5185,8 @@ static const struct bt_shell_menu main_menu = { cmd_exp_debug, "Set debug feature" }, { "read-sysconfig", NULL, cmd_read_sysconfig, "Read System Configuration" }, + { "set-sysconfig", "<-v|-h> [options...]", + cmd_set_sysconfig, "Set System Configuration" }, {} }, }; From patchwork Tue Jan 5 03:12:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11998051 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77D85C433E6 for ; Tue, 5 Jan 2021 03:14:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52E7E22582 for ; Tue, 5 Jan 2021 03:14:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728163AbhAEDOR (ORCPT ); Mon, 4 Jan 2021 22:14:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728139AbhAEDOQ (ORCPT ); Mon, 4 Jan 2021 22:14:16 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65AD4C06179A for ; Mon, 4 Jan 2021 19:13:19 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id p21so24576142qke.6 for ; Mon, 04 Jan 2021 19:13:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=+kuRzAf5tlJa1UqazyMjV+Q4SL+lpI6Q88s7q7eUe+E=; b=tc/tN88xOqh1XVkjPWh1y7QVBnzHcdj8nk9tTaJHuH8CesNyqa5y2OzlmU8R1w9PXJ Rc+g8jKZ8WSafa6LJbaGChmt7Q3qZTO63dqMqM2FTu6kGvgCp/2W188ibsxz3EIePt3x eKXIr66LVygsF59Kz+Bvl1gu1rQqQT2pUumW475ADFmpzgDCsE1Ydzb4FMnSObAS/4N7 +Mb632ApqS821mxbJSxH0pOBYXrGIYFl9SLyhzY5wJ6OllTbM07eW0vr+w/0ZUHLWg/6 ZACoQ8PYGVslsaI2GInS4c4HcFxKKhP5ZWbxcc+LkvW2xPTmV08RC10U//51szF1t4j4 M86g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+kuRzAf5tlJa1UqazyMjV+Q4SL+lpI6Q88s7q7eUe+E=; b=TdMBlu9/JsqZJxZUWqDk0PKv4H60dl/EgvNXOKzq36jjnv1qPtrodMz8kcTMNWk3AX 5buWrAOxf/ijZZ4ZtWb5ULwmEALK6OQ+h7mnMHtOzs7FFLTMTP7UaIvwqfj6gYM3otPL Z5rrC/T0kT/pkLQ9IGsnG3w1Br53bzTEyevHvBggNwX5bOu5jHYkl3aW3bIeXlfpTSx4 C4R1cVcMiL6R2QHSKt5S22efCJzmeVFFlLNC8gYjmufdQZEpzE85CuXsmpjb5pFuzGv4 O0yZVj6xGr0vsAvCaoGj0LbNco9Cvi1vxKVbIksKQwNmWdvLzmeeiFQvQu7WITltdPhI SiLQ== X-Gm-Message-State: AOAM530BYMpwBdx9zgty6kriUb67MdIwSpoI5AVDWmWeQ39ozqTikZBr AQ99SO+6Oqm3lpdYKo94j2cooWLakz82VmgltpCcWvW/VyzBf4FSOyyzmXpzASyKA3uIgQjI4C5 J5JFF1AR8pqYvgQWcRnikWSGWCwsnQE557BMWYE5pKir+7EIG0fwj5iF2CUR7JWoOpMDQ4G/mjK IJJBxvDue/V2s= X-Google-Smtp-Source: ABdhPJya8bkWC8owYStigAV/hpkqFN/AdF1Q0J97L302XDeeydzF8KrdDO4NC1IRsIS4mXfGg3AsYtlPCtfoey9zcQ== Sender: "howardchung via sendgmr" X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:f693:9fff:fef4:4e45]) (user=howardchung job=sendgmr) by 2002:ad4:5904:: with SMTP id ez4mr79765528qvb.30.1609816398456; Mon, 04 Jan 2021 19:13:18 -0800 (PST) Date: Tue, 5 Jan 2021 11:12:57 +0800 In-Reply-To: <20210105111219.Bluez.v4.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20210105111219.Bluez.v4.4.I43884adadc00a5095dd03d2261a71dc2ba80d986@changeid> Mime-Version: 1.0 References: <20210105111219.Bluez.v4.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v4 4/4] shared/mgmt: Fix memory leak in mgmt_tlv_list From: Howard Chung To: linux-bluetooth , luiz.dentz@gmail.com Cc: mcchou@chromium.org, apusaka@chromium.org, mmandlik@chromium.org, Howard Chung Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch freed the mgmt_tlv properly in mgmt_tlv_list_free. Reviewed-by: apusaka@chromium.org Reviewed-by: mcchou@chromium.org --- Changes in v4: - Simply use free instead of mgmt_tlv_free Changes in v2: - Fix incompatible pointer type error of mgmt_tlv_free src/shared/mgmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c index dc8107846668..3e9b9ee26472 100644 --- a/src/shared/mgmt.c +++ b/src/shared/mgmt.c @@ -595,7 +595,7 @@ static void mgmt_tlv_free(struct mgmt_tlv *entry) void mgmt_tlv_list_free(struct mgmt_tlv_list *tlv_list) { - queue_destroy(tlv_list->tlv_queue, NULL); + queue_destroy(tlv_list->tlv_queue, free); free(tlv_list); }