From patchwork Mon Dec 28 06:46:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11990867 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.3 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 87920C433DB for ; Mon, 28 Dec 2020 06:47:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A638207BC for ; Mon, 28 Dec 2020 06:47:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726279AbgL1GrF (ORCPT ); Mon, 28 Dec 2020 01:47:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbgL1GrF (ORCPT ); Mon, 28 Dec 2020 01:47:05 -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 BA10FC061794 for ; Sun, 27 Dec 2020 22:46:24 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id g67so16776550ybb.9 for ; Sun, 27 Dec 2020 22:46:24 -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=RYhpAf+NP/aVS5zt+P6Vcn8Y/nE+I/qnyuAeKN2+35Y=; b=vZRsC6QkLbNN+AO9CHe/roMDBhL0vWFY2XlLhAkFVkjIH67AU/e85XfzNq+j+GTJeN m6XCtXbKuK+i7gl5DIULFg56eTLszZD4r1xO+ISaKYG7YrVdHpAcwWYOWXS5pY67c/f5 AZhccmls5fMiN0K/x96apZpxTLC959q3M7mQcG36+mWZSJh9k8UMeI6fI9tO2eSQ5YQY 5Ox/6MTar6CoM+e5g2/SJNnPyNo2+a27+vKxtbrXWGXInN5SCJon8U+IZp7JuHwqg4Gw fApoI3QJKETvdLw8siMVeTDeuZrWESI972BtsRAh20QYmp/3uNTNtrFMDPCVMqTgxGeX MhoA== 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=RYhpAf+NP/aVS5zt+P6Vcn8Y/nE+I/qnyuAeKN2+35Y=; b=UJu8/GhNLkL7wD/FLBdGJscE8eEq/tbOC9qrkBVV6Y0DP4J5p0pO4GoxykMjo/8N6Z x3WutkXHjNU7ctdWMpuiwsWGtmKbzDUEEh2TrU0h1Z6cTFBbZy/WdDXctXKHF5EThxIx aBDv0a/mN0+28qMrS7YIrdar12tCERXMeexY70icnkybeDsEDS91NhiW7vGp2Gai9bTW PZJNhFkJfpuKmcSHUJGYBdcUAr2hoV0EkfO66fSM20CSVPMD0PPDpOjip3OroCbk8Nx9 /xKrhpCrogznmVN7bIQYmprtcqZYYbz1neKsI+9/dRFtOjxQER4Z/6FnjrppqgWVqt77 Pa7A== X-Gm-Message-State: AOAM530Dr5G0HXNm5himIeckYubJ/s94kLKTNs3LXAUcCfLgGd11fQKX ACix1+RqJeTZiZw6A7lCjUG3uLW8RHLyKgcQGClFeKP7/aCDOreWBBl+fGv/z8lcwgrbut0Hv9p hPbs2u0nZ/IBgtgw9Hc8G9a1Z/CG3do3iNA52fEjphRK2Br8YwxF5QHhByMFZw6TnGRXsBIWdx0 3+uwZtn8wGDs4= X-Google-Smtp-Source: ABdhPJxIRrHvKZXqz5/q9j+jV4zCETHhrIOgPYY+T3/HuOhnL3LM8EJl92Xml2NwUjtppA9GkFSg8D0MkIGUd5m/vA== 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:3741:: with SMTP id e62mr62070623yba.298.1609137983834; Sun, 27 Dec 2020 22:46:23 -0800 (PST) Date: Mon, 28 Dec 2020 14:46:10 +0800 Message-Id: <20201228144543.Bluez.v1.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v1 1/4] shared/mgmt: Add supports of parsing mgmt tlv list From: Howard Chung To: linux-bluetooth , luiz.dentz@gmail.com Cc: mmandlik@chromium.org, mcchou@chromium.org, apusaka@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 --- 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..bdc4bdd9e66b 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 = 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 Mon Dec 28 06:46:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11990869 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.3 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 A11C7C433E0 for ; Mon, 28 Dec 2020 06:47:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71447207C9 for ; Mon, 28 Dec 2020 06:47:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726338AbgL1GrM (ORCPT ); Mon, 28 Dec 2020 01:47:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726292AbgL1GrM (ORCPT ); Mon, 28 Dec 2020 01:47:12 -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 21FC9C061795 for ; Sun, 27 Dec 2020 22:46:32 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id n205so16682018ybf.20 for ; Sun, 27 Dec 2020 22:46:32 -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=LC6KJs6vajpeJsp5rgqNYIF+TrIBrc+h9wkJUlDzBSY=; b=mrErIfReCZAw+wNBMefjU1dGD5mVHKJiP6G3uSqDixBGTIEPxB6lhQPA1c9vxhv/Ab f41JXJZf5QBUwCVJXrCKv+I79Tv+brooRhzUYtMPi5LL3FV88U+MOBwJVKv9zw4QsD8o Prvn1OVMg9zYVaXnMZFtK5/3S/+Xrby7pvt1XtG6cyY59oEp6HMaOpQjFWYDvwbIdgVB I0INTmlPxdw38ZN5P6f2Y0TAK699PVDEELc0e75ORkk5ejgT+8FKI4A/JNSobJ8jKHIJ WKUTTu0J0Px/MF7w5jmxeL4LyI9eLm8WmdEb4MB78We6iyrx5gyKu7pmCDdJIsMB/auI Zeqg== 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=LC6KJs6vajpeJsp5rgqNYIF+TrIBrc+h9wkJUlDzBSY=; b=Pa3TfWxU/2eKvL9joYOuFtACD/S/J74ChEnnrWO3XE1ACLifsgMjXt7ccOOOCOKqQi 2NK1+covDrdz30yrqOOVJKB9zugw7Z9zarInqSE3SLfhiAbI75CCA3fl7l0I4//HIwrO kiSAF2bXu8/0vKTSV5CSzuJ8GOd15rEmuNfjiilITTzU0Or+UOq7TsNEeKXhKDYeLloq o3FLFN0kzl4NAnILE0tzkmuwp3b0inN2xi1u5D+WXgOVSP85CAA3qGQs2H72Xp1A832b B8TqRNYLp9UwwwZkC8So8oq4nAn7rD4BOEOkAdyJ4wfB/3dLsx1B3UWx9qgPF7WF2XpD eDnw== X-Gm-Message-State: AOAM531fVGgN8aCRm+pA0yi9ZIdX0NsFKm+rw2K/5mSXD1qwhV9KhipI gJWa68cQEckN3wMIGGq2drTAPvhA78zUVbFoBaBwlniatWxarP9Hv2R1d3laBZCRCFQy0gFSENM sP1GpyB3aTrQfhrA2W3XqxaqsIJhtwsHe6f46xXulp2QBcpLve9vJVIyJMIGkbQRCX2QTjmbh9j FnTj33CPE8qJY= X-Google-Smtp-Source: ABdhPJzge/LmM0XGsn4bgF7Uj7Cos2JkuZvxtSvgJ4IxD6plUv31S/4ltt3G1fNu6Nb17qipkKhhdoFqVv4hKqxeqw== 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:ad93:: with SMTP id z19mr61939262ybi.486.1609137991351; Sun, 27 Dec 2020 22:46:31 -0800 (PST) Date: Mon, 28 Dec 2020 14:46:11 +0800 In-Reply-To: <20201228144543.Bluez.v1.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20201228144543.Bluez.v1.2.I0c07c297925f838138b42674ab244572e6ea361b@changeid> Mime-Version: 1.0 References: <20201228144543.Bluez.v1.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v1 2/4] btmgmt: Add command read-sysconfig From: Howard Chung To: linux-bluetooth , luiz.dentz@gmail.com Cc: mmandlik@chromium.org, mcchou@chromium.org, apusaka@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 --- tools/btmgmt.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index 2f7cb2efcc38..c766de862a12 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -1752,6 +1752,53 @@ 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; + struct mgmt_tlv *entry; + + 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 +5077,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 Mon Dec 28 06:46:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11990873 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.3 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 BD0D0C433E6 for ; Mon, 28 Dec 2020 06:47:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A417221E5 for ; Mon, 28 Dec 2020 06:47:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726360AbgL1GrQ (ORCPT ); Mon, 28 Dec 2020 01:47:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726292AbgL1GrQ (ORCPT ); Mon, 28 Dec 2020 01:47: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 D773BC061796 for ; Sun, 27 Dec 2020 22:46:35 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id o9so16741492yba.4 for ; Sun, 27 Dec 2020 22:46:35 -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=Ag1yJexuyuOZgLeTCzJRi8FXYTblNlW6uzMyNzlTnww=; b=h8X6USyV/YZhm4fjNxWFThAs8jOCMDVBObpbnHxJf2KrnKDKt1reJPfsUq2p45UtWz pdmL/MPtEfKS2Gj+yl8oMPm1ODxqjmjg9/ns9jMaTGRJUQ6oO0p85KQQIEd10PQOhrT8 5F2fNsqdszO+SNqvaIblWl5DaWP7Q6qPhe7bjeH0JNA7j8qElc0iCx8SrZ41NTT8khRn yHWh9UCOabamz0LdNstOhEJDT2Ukco1HqKfKPVFYtwJT3NQSA06RPDO6gfJU+e3lfyJJ +NfHYWNMKSHT1JkhqtcySTrn1ldXauJYRuqrurlBqWvn+pV7Q0YVUpGGUnOdHCgKmOtD Y+DA== 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=Ag1yJexuyuOZgLeTCzJRi8FXYTblNlW6uzMyNzlTnww=; b=Et+FMqOu/dkJz14ZDpTOKum+PDtQ1m5csAg19pFSfkwKV6oJLDP5yzlPTpJboHcsbW MEYj47PHVn5IjI2jwSvxJoHEfB1t7uYb7A/nKbwzkrwSinZIGc+Zc2Bfrgq0ifVnlPR0 FxvCg2Kj5SLqVSJ7P8Mn1F4FY6ztT3fjrJikKLy/9EJ6EI4pbmTVyJf6LGDJ05lS41hj m7qDL9SLqhBzTMHoJgQo3PT468LyTUYWciQGNmGZw5rfC3V7wlOOyKVM8BM+bxYOdrgc OBAXVmDfOWhXF7fvZwOBlc6dadB9ojTIIjT6GuzYKiSyrKa1Qv4p/hCv72ZcUeFJ9dTt yYTA== X-Gm-Message-State: AOAM530LRNNUjKh/+MgrlODvOEOd09OG78pFMKpVvRzAWlHdrrmzK6TM szhCp+MlnsIvdQhjm+ciaUl4MciKN5MXyidBTeeEjFcV2KB55iIVGjX6C7AChLK2KaBWf3zf0WI Emg5I/FsJQQsyW+h7M8XbvWFtwds/f39EoAG+t0xMmFDbtOwtNFFhvNQ0Iq8Q10g2glDl0k9BZd TSs4xXXjSPxTE= X-Google-Smtp-Source: ABdhPJysQRh+HsX8ZKcc35eLkxFGATxRVcygztn/Yyje+upM7weYzWbj0Nff2n9sJ49ASx4xsGh5EX8Ev7zaQ7u2Rg== 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:9906:: with SMTP id z6mr34353327ybn.238.1609137995074; Sun, 27 Dec 2020 22:46:35 -0800 (PST) Date: Mon, 28 Dec 2020 14:46:12 +0800 In-Reply-To: <20201228144543.Bluez.v1.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20201228144543.Bluez.v1.3.Idca009971ca95228a3fa7232ef648f18ff64d185@changeid> Mime-Version: 1.0 References: <20201228144543.Bluez.v1.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v1 3/4] btmgmt: Add command set-sysconfig From: Howard Chung To: linux-bluetooth , luiz.dentz@gmail.com Cc: mmandlik@chromium.org, mcchou@chromium.org, apusaka@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 --- tools/btmgmt.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index c766de862a12..4cc94efe3f1a 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -1799,6 +1799,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) { @@ -5079,6 +5186,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 Mon Dec 28 06:46:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11990871 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.3 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 CA6E8C433E9 for ; Mon, 28 Dec 2020 06:47:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A36C2207BC for ; Mon, 28 Dec 2020 06:47:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726408AbgL1GrU (ORCPT ); Mon, 28 Dec 2020 01:47:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726363AbgL1GrT (ORCPT ); Mon, 28 Dec 2020 01:47:19 -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 71C67C061798 for ; Sun, 27 Dec 2020 22:46:39 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id w8so16705215ybj.14 for ; Sun, 27 Dec 2020 22:46:39 -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=EyC5xIrBqlSQLTjiRSrDM2FtzhrjMO/QlB5tdJsMwFo=; b=Ea9TNGe+6udK0VenKGDFdt7HfSAxnSq9AkO8jQCvYXO1dDQFntSXmaZ3XpLzjPJhK7 S1SqZ78WIjaUGRFwLJC6kJKUfgNP73ft8wzNYaNtbBYN1l13Eg1Aucd1XNXoTNBBzE+U 5qskxxWmuXJKnM7DfpfGTSBlkUdOLDJWfHg9YGf0xh8DLZ1XMABINkJ9CK4xPFXXp4T6 RiZZ2/GYsVQrMfbTmx2aIxdPy5gJroWbh4gdqk7Ls8tB5H2LIZJ+DDAw6i4ZSszKmzSw LpWLdblZxAK0NWFQm81qqhZ4KqdpxlF0LA4Dg8x5g3sAIrN2DAHvpLHKlrirHx+skml7 T/BA== 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=EyC5xIrBqlSQLTjiRSrDM2FtzhrjMO/QlB5tdJsMwFo=; b=m2TMVAtvLFeDs3yOomatF0VlzTZV3q6sF16+WLlJ9OlytkWdgduSbtYBgVJO2V+SML c5OVTNHzJJJvcVTBmXCKhpa76sdjZ2HuoYWXs5DEJhrolQ18l6OPF7OXgWv+8oyck+P1 tqsC5k+MQW7Sfs7fU7Do9lGXKoQhT2dGx5M3Q4J/C45QwYr0uKzoZq8BfBSL7LJMgPOo Iwe1yIlzHs/Iwyy6599FE5KMFJyhi+QZWXboZZ8uXyj6k5Cdu2wOBbQ10w35xatuQymk 9Hdk4UAhs4DT0ZFjsTo1Nz2M6qbpiKRgMJKxY3hjLAP7Oy4rK+7BMr9VOfJrB8OzMQYp bYqg== X-Gm-Message-State: AOAM533QMJE9wsppZA6nKrBkBumXSF/cuIE6YlBWHkUYWkWPehOT0378 UTswfd3+97HmDSZ1dN0EQjbCefErONffrRK435U/DjU3LjmRXP2/VFo63kIQBcFD2vUQ7qIoMk2 r+xLYGqKzDyTDnK9/1kCnz+pv4ytTYRJ9V45rDFPA8VtEwcDj0cJ7GaiRAJcSZb2wY6/Yy3EGkT 5OpPOIWvj+Z7E= X-Google-Smtp-Source: ABdhPJyQcHvcDiRzfvkqJ7btVG6Wbf8wsOfIKpp1AcSS3Re4HJKDFdCHOjYILECfwWVRAqhKDvTJtlxPCWjXRCxRFg== 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:8050:: with SMTP id a16mr38915877ybn.146.1609137998689; Sun, 27 Dec 2020 22:46:38 -0800 (PST) Date: Mon, 28 Dec 2020 14:46:13 +0800 In-Reply-To: <20201228144543.Bluez.v1.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20201228144543.Bluez.v1.4.I43884adadc00a5095dd03d2261a71dc2ba80d986@changeid> Mime-Version: 1.0 References: <20201228144543.Bluez.v1.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v1 4/4] shared/mgmt: Fix memory leak in mgmt_tlv_list From: Howard Chung To: linux-bluetooth , luiz.dentz@gmail.com Cc: mmandlik@chromium.org, mcchou@chromium.org, apusaka@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 --- 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 bdc4bdd9e66b..19b5466f9071 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, mgmt_tlv_free); free(tlv_list); }