From patchwork Mon Dec 28 10:04:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11990979 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 63D6CC433E0 for ; Mon, 28 Dec 2020 10:06:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3804B229C4 for ; Mon, 28 Dec 2020 10:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727083AbgL1KFs (ORCPT ); Mon, 28 Dec 2020 05:05:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727034AbgL1KFr (ORCPT ); Mon, 28 Dec 2020 05:05:47 -0500 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78100C061794 for ; Mon, 28 Dec 2020 02:05:07 -0800 (PST) Received: by mail-qt1-x84a.google.com with SMTP id v9so5096349qtw.12 for ; Mon, 28 Dec 2020 02:05: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=5IY1P928LNisrCvz2O0RipAgV64DbONq524mIao+F9M=; b=N9G9W+f9J8bK97YqALbb8POIwecntpsDCOiEnWFnrrC9gerAtUNxzwbHz3u3KUN3oW bbkM33uE07ZYHxC1LFLMcQGqQOKI1jqgWCk19J3zXE4Y05PioOaUrjuQTR3TXdsqzYG2 QV4YqUFSTYMt4rVzyJzGVzdHM4+18ds18jEdQEr6zbY8gl/CHZv3iOzwmG6e2aIjjIza UBnG8JpuIL54P9/SJfGZUyHO7nvVN14Va/+JSICoO52rt56qxnWrL2PlCZuyvNZqj9de lv/TkX2a45Rc6xyDnHLIqHEH2r1Zwak9niCSp1bNbNcjBRdILXuG/yVu2zfWm08TKA9q rTBw== 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=5IY1P928LNisrCvz2O0RipAgV64DbONq524mIao+F9M=; b=qxGp64eQakMH67DQ6uF2rvYjOZOx+Y3F31pBuNIPlV7OMycW4DH/noOKKzgW1Xj3rN VCcGpCcSzgpyLSduqcqcf/xeI54vxrfe6n5MZ6527RqM12RdwI2h3sM6DSlw4t2qeqCc z3RX0+OEDuw3cQREJVnqUjrBEhPvE0MWuRqSL7HyhpxiOrs6+HPwsr6Vf+zUNqcQlzLY dsgA9KwLPn9QNyq0OL9DA72kXue2a3jwmsthx94XecMkCtv6C9z7yqBlrwoiZrNer2Am 3s4ntDTevjROPBtHCgA6XxTm4ODhk4FcckqqE0miM1G5CQ8/+iDnrz9KPud4ybJRN3s1 DXWw== X-Gm-Message-State: AOAM533iLkCmyqjdmbEvTMb13vcAyE44TDR9h80VV20oLQEftRKYOBPs MKixjH9seMna/+avBjXzkE2DVGsX3TuR9Cs5BG5RTxBw8RNiVrtbgrnej+zn7sXZa1QEmw1FsjB ipNIjqvFzWHoAjCIQsWUWMzhoCyWnf0eB3TNnuIogzOYL39Tcro1Kuo4hRF/z7fUbFs/KwswUKI 6P1K+FFD6zN3E= X-Google-Smtp-Source: ABdhPJyBSMAMNfm8+80WvQMdORzrkNpT+E8k6aYXdw1K09f5Etszt4Zdg15KaGp3HNXLFVcp0uHLIP0I69HRGZDcig== 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:4ee7:: with SMTP id dv7mr46258220qvb.43.1609149906509; Mon, 28 Dec 2020 02:05:06 -0800 (PST) Date: Mon, 28 Dec 2020 18:04:55 +0800 Message-Id: <20201228180429.Bluez.v2.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v2 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, mmandlik@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 --- 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 Mon Dec 28 10:04:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11990977 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 7D569C433DB for ; Mon, 28 Dec 2020 10:06:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D0D122A84 for ; Mon, 28 Dec 2020 10:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727138AbgL1KFw (ORCPT ); Mon, 28 Dec 2020 05:05:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727094AbgL1KFv (ORCPT ); Mon, 28 Dec 2020 05:05:51 -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 2EE6CC061795 for ; Mon, 28 Dec 2020 02:05:11 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id x74so7762228qkb.12 for ; Mon, 28 Dec 2020 02:05: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=J2n6YIvt4zqJQtx4TNVo84THrt9CDungO41tQh0sK+g=; b=F3FHdEawCo80i2i9MW7UY5w4rH0BhVxOBWmGcGwr7NOny587TsXw2RuT+FnXcUk8jv 2Y9rwuIqJP0nNKGsb7ZetXh5iD9vn5VHS+2LtLUGwY7+iLi2Pkjv5NLTTYZSDat42+qz 8+KW+bY9AiTaI3hyf1FH+WGcW8I9lRezgGEKTE0RWYfj5j5V3KIIkiZHSIkf3BLy66VX 2YVi2prnZhuFtu4g0bQ+d1gOx8b6E0yJYntkLjnkqtYaXY8H/fOCTB/a0HhYZJmVoZHw P1Lrym+G/GPWv9Q9NsGqIOt2fRl2jc7dwxQ62J/EQvBPR2tAvdvgCmnIBRTFSyFFNIk9 CbYg== 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=J2n6YIvt4zqJQtx4TNVo84THrt9CDungO41tQh0sK+g=; b=FkWCnucbW67iYIZx4Vs6sDQzGQ4dB2N4HvElHUxuHv6PJo+50WH+KcPfqnqg2VFYXh F15S26Lo9N7sKNmxy0siSVu6qLW/DnreW6PieqP3jsnrNiQmWedT7uEupQfxa+RtvCve t7ZIqodBp1HifcPC+ZGFuaUKJgHoz8Zk7YKy9M+mG257kz/2H5i9PVJ8nLDfuwpURfd0 efVV9lAMFNqpwuMBztXKrys3Xs8LzYVHLqnSL8PtUKWrbJgVdYfsiWz3TWTQuXSVoo7w 2AP5MQBPZijJhya4PsV3QEHHtSGsommESHQoOt2d1rHBwX8NDRmJ3tPLFuJjmUydUmDR 6Fbg== X-Gm-Message-State: AOAM532EWXiCPvUfkuYSj1+6PCoj701MnvVVzz2vlxOHoGXY0sr1Gu2Q 5ptwE73SViFM/OiQnMpHylaPDV5L4FkLa9LoLRgldtZkRVsKD0K5D7QrZjjGS3VrJB11T4Upcqy ggI7ET9IerxOUOHQMa/bRIADRp6bdQE7+LdFkCM9RLW3PmkhFG68g4HHC9N9wsXNWiB0A3IUqCj sJub7VhMqkrwg= X-Google-Smtp-Source: ABdhPJwn/CXbEm2cIsswgkwQk5B3SLAVfXIkFYtlpwYfDPzUIdmQGekZo86ZUhwwJr8JIiYGmCzbeGOY7BmnUjBZ1Q== 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:a0c:fd8f:: with SMTP id p15mr37474076qvr.48.1609149910290; Mon, 28 Dec 2020 02:05:10 -0800 (PST) Date: Mon, 28 Dec 2020 18:04:56 +0800 In-Reply-To: <20201228180429.Bluez.v2.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20201228180429.Bluez.v2.2.I0c07c297925f838138b42674ab244572e6ea361b@changeid> Mime-Version: 1.0 References: <20201228180429.Bluez.v2.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v2 2/4] btmgmt: Add command read-sysconfig From: Howard Chung To: linux-bluetooth , luiz.dentz@gmail.com Cc: mcchou@chromium.org, mmandlik@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 --- (no changes since v1) 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 10:04:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11990983 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 8C7D7C433E6 for ; Mon, 28 Dec 2020 10:06:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6067A2242A for ; Mon, 28 Dec 2020 10:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727166AbgL1KFz (ORCPT ); Mon, 28 Dec 2020 05:05:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727158AbgL1KFz (ORCPT ); Mon, 28 Dec 2020 05:05:55 -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 C7384C061796 for ; Mon, 28 Dec 2020 02:05:14 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id b123so17494313ybh.17 for ; Mon, 28 Dec 2020 02:05:14 -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=HzQbJfLng4nTdocg+2ktdAuB1zoBAkZF5kF7IpbEKGg=; b=JFv7fBgaq2FthsbHpLKlyMQuO8rHJYScMzqQ91tz8I6KSsD/AUq2zp7jq+DS4YrK2x VhCZBkcUBmDkwSFpCvlv8Z+5UvmfHol3BtD/hiitIpoBwq182vzsrgLC0XotTTwiU4Xa h2FNZ2EsRI3ipwcopE5SrML1Z85vAqsuKG8Mcz6KdXTww32Nb3EEjQteFSxcATh7MJKA BvAlfzKQhI6ZgSrcl/fzJFMUOhxb+5/wdCLuxlE9lrPhyMsjyDrW2mmyha7fa+zyMAeO x/d9r+tbTwSW+MlnksTXwEqJOXw08NIb0fdzZYHvulP3VXzkXJWy/LWkZtofCNX+JSZr XAKg== 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=HzQbJfLng4nTdocg+2ktdAuB1zoBAkZF5kF7IpbEKGg=; b=FED/qxZkIO/TqLILzSWBl11a8g8BoJQvT5e/s6QCw59gZyLkvxMNn/8aGPU1EwWpWQ 59EVuHUz42UG21CXjFDamGTBdhG4OaHzeXgS+ssrGxvIHjEYBPxPY8Ij1Pl4t9p+MxUZ hUu3WxPBiQMB9gr7h+8kJJXPsyqp1IybQ8L0bT+LW5G17rfgV3+SOoJ16tKJnHf9X3GE 86RK5DO0T1hKjbM6HJF6efkuNUaeFkvfnMZp4sSrxJOMiRWlYqryAo/DYdSBg4SpWt7F QH4+62EKY0159fYTzf9Y1/MqgZfKo9E2e7P4JzpyC+hHAGT1V7GO0cyUEQvNZT5TB4ul YNjQ== X-Gm-Message-State: AOAM530LLCzONH+Xn7/PA1MhB2fzYRZzcelPDVGwicNM6cBrY4JTTw9V Y9dfYlbo3QAId7PiovECwuFjRYBrAiueWQCHhL3GeYOy1bMlyg9XOEYgzPEJ5m3sVQSov7Nj/S4 hMGMRpQ334aejn8FGXIW04dMK+NnFdCfowkbwl9opwfQKZTd+5+5qQxEpjCgLeM/BhQII2Z779i LewfK4gyd+fWg= X-Google-Smtp-Source: ABdhPJxtTDmy/GlTIyOHtSfqTwPQxLQCcFwEQyMGPqNajBooiBUuGea09h/o4QgW7L+cmbrCcj2A007GUpaJ55SzBg== 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:2643:: with SMTP id m64mr66305216ybm.221.1609149913965; Mon, 28 Dec 2020 02:05:13 -0800 (PST) Date: Mon, 28 Dec 2020 18:04:57 +0800 In-Reply-To: <20201228180429.Bluez.v2.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20201228180429.Bluez.v2.3.Idca009971ca95228a3fa7232ef648f18ff64d185@changeid> Mime-Version: 1.0 References: <20201228180429.Bluez.v2.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v2 3/4] btmgmt: Add command set-sysconfig From: Howard Chung To: linux-bluetooth , luiz.dentz@gmail.com Cc: mcchou@chromium.org, mmandlik@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 --- 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 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 10:04:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11990981 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 A07BEC433E9 for ; Mon, 28 Dec 2020 10:06:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74FA0221F0 for ; Mon, 28 Dec 2020 10:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727170AbgL1KF7 (ORCPT ); Mon, 28 Dec 2020 05:05:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727167AbgL1KF6 (ORCPT ); Mon, 28 Dec 2020 05:05:58 -0500 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98290C061798 for ; Mon, 28 Dec 2020 02:05:18 -0800 (PST) Received: by mail-qv1-xf49.google.com with SMTP id f7so8914563qvr.4 for ; Mon, 28 Dec 2020 02:05:18 -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=SvJkmW8trmd30n6OPTE0R++9r6zKxsd0lzJkBum7ukc=; b=IgzhkxAVYzoA3f8UsY5mMZNNiDfp4nJZaOSsx0ZpwQIhkTeZMDHB3gK7XcyTfm4mPM YA4P7yzo/dZEqonv1DQX+49Nx/WJO4gaPh7MkDb7tVkZvq8vjFIXEMGGJiapguncyDgm ww4058KxQ/CyAp1bbHYzrNpQgkkt1xg7j1YzCRbE1HrfMy13QKbeQ+IULAOgfyqHYKMM JI3Up8T4LQJ4rfCVCda20JVOQtPrpmXsIRPOOiv8Q6MTFD9ORnMG4exnThyQxZNibCG/ VfivwIxO/Q2ZWsAWoR1fF5cOp87yJhEXCrQQmCeO3BIGca0cTLnJopoe/LsR/VrNu1Gn Wbvg== 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=SvJkmW8trmd30n6OPTE0R++9r6zKxsd0lzJkBum7ukc=; b=GT/G6fftVm2uEt813Bk9ZtSDqQ9SszYK+PgtQJ0vqazmvBRVrppROhnLXuOYPJbQ4t CDIQwk9j/QkjTpwGfEwdJhSKzlSdMaeRtSkbjOcpJZ2pebLTa6eciCICNDQBmtJ2qf7g pwErpVLP7GA25sxf6i+GFFzDzIynrx4ln6Sqt5X24zIV8MAmrB36lS0qcCpndHn2L9G9 3RTcO/EkGSCuJ/vhH6DQYTjuuKPPghsySZiTrMqtlUF0r2CAvEwKWQ4prvx/ExVmuhXB ac2pAs8qAVmuj6NUGMuWiYsIX08tDBNikUHwhzisVZQqdPVuawk9SMpuc8Zgpe0eAvj/ l+RQ== X-Gm-Message-State: AOAM533ADt6+N182ISxga4HVYrigBh+wmYbyVY8rOF0qZ328Ilgnww6b ADGSUHJlyXNnbJf0lzREUsTolA6IIlePAycYpjzWM/us+yLjftnm4/CaaZg7stZo70d7Hi/f4tM E+HkyTBxkMvuZSvzLZ9mcQ9cZrC7ZlilbW4QF0SFBt5eX16wiYQiP7CGeTjVvp7A9bcziVxbSuw wLUj3ZzI/TO58= X-Google-Smtp-Source: ABdhPJzroEoHfBGg7a7H3VLq0N7g56N4FsjLSJYGBKZyJZZT14U3fQiKEyKmbNYWreIanUwSlbOFUFoyrswQ5sywsg== 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:a0c:f283:: with SMTP id k3mr46508393qvl.48.1609149917733; Mon, 28 Dec 2020 02:05:17 -0800 (PST) Date: Mon, 28 Dec 2020 18:04:58 +0800 In-Reply-To: <20201228180429.Bluez.v2.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20201228180429.Bluez.v2.4.I43884adadc00a5095dd03d2261a71dc2ba80d986@changeid> Mime-Version: 1.0 References: <20201228180429.Bluez.v2.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v2 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, mmandlik@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 --- Changes in v2: - Fix incompatible pointer type error of mgmt_tlv_free src/shared/mgmt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c index dc8107846668..0d0c957709d7 100644 --- a/src/shared/mgmt.c +++ b/src/shared/mgmt.c @@ -588,14 +588,15 @@ static struct mgmt_tlv *mgmt_tlv_new(uint16_t type, uint8_t length, return entry; } -static void mgmt_tlv_free(struct mgmt_tlv *entry) +static void mgmt_tlv_free(void *data) { + struct mgmt_tlv *entry = data; free(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); }