From patchwork Mon Dec 28 11:34:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11991137 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 DFBC9C433E0 for ; Mon, 28 Dec 2020 11:35:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B69AB229C5 for ; Mon, 28 Dec 2020 11:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727340AbgL1LfH (ORCPT ); Mon, 28 Dec 2020 06:35:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727326AbgL1LfG (ORCPT ); Mon, 28 Dec 2020 06:35:06 -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 63DE3C061794 for ; Mon, 28 Dec 2020 03:34:26 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id o8so2661216ybq.22 for ; Mon, 28 Dec 2020 03:34:26 -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=9+Ok8zSmlezPRnyzRhNvndhpVlA8+TsAwmdpm3q9p2A=; b=Q66faswxutm9FPnqP/QeVfjxOEsP5VUXAL/eWgXNnftbDuhssGiTe5KMn+tFVn6LpE frk++JLTPNE1yPs3N+l6QIfz6e+2zYtZN0isrXxZuHpt0GZ90r5NvIq2eaOQx0CKzpsB z6YqGLAThfMAcUl0uRK91wskRcwKGeIWSM0Y15vq129MBGGXHN0XQOaYOOhiXtetXJH+ FrfyTq9vDkJQ2OGYTuxvjbzf9IvRbjZh3Qg7sLxgbXIR75E0Qwoj5HQdtULQYIHbQjq9 oCEUBaKDwPn28yXyKZeEq+vjDk/0Sndf6k2pvjLdjR+CeS5BwwqDuIgmVvRKI+DIoH+6 mZ2A== 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=9+Ok8zSmlezPRnyzRhNvndhpVlA8+TsAwmdpm3q9p2A=; b=i41TXSXjVHHHPMRy6D0BF5pQ/qnLubFUhyC6cuRUCC4UcigFG4wSCJH3aQqbWcgKZX NUKm+3HEmrOVvcn0NbX6iKpQsYYrOPqGmauPK16gwTwkR2PEygLMC0PnXmL3hQg1ATKO XdwdibCUvCwmf0B0Mt+OS8t4NG1KQwE4oH2FtvnJTef14M5MUqJtWjDNC7cRVCEz6PA4 E1cSpqPn1Vw9gUm9w+CYWukLO/gsB7uEJ7WOCf75QpptXI/SOtft31Y17LOUqcjdUB6a RxOLehS9vFW0YfdXF6QgqK9Ba4dpktAXLb4z5tH+ny+GgXXrUSGCQJ9ddTSpsFNbsgp4 80wQ== X-Gm-Message-State: AOAM532D5C7ZIaWPG68tzkCAX3pII7J2DAQwF2oLiGQx5DXvsEoDeRKW DBYWygOGkdTulTxOwSxw8Cy6oPpHruLNpHpfRyi4PPV2IRuCybKMAc/nYWTSoMWX75BmcNAYh8D r1ecIi/h2LISB7q92EDRpMmarns0E/FEif88gyQp6Bl6AIaRGi0erInFGqH6XYlnuiVGN9pSvUd 9Y7EhNQ2wUnPc= X-Google-Smtp-Source: ABdhPJzeuw+1BG8LcaoB9eieMGOyVQkEnzN+tnHSZBSgZtr0ggg5sQal9zMHPll1olJ1PLtplcXsQ96diCz7D3Fqgw== 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:42cc:: with SMTP id p195mr63071571yba.59.1609155265399; Mon, 28 Dec 2020 03:34:25 -0800 (PST) Date: Mon, 28 Dec 2020 19:34:17 +0800 Message-Id: <20201228193351.Bluez.v3.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v3 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 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 Mon Dec 28 11:34:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11991139 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 05684C433E6 for ; Mon, 28 Dec 2020 11:35:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF535229C5 for ; Mon, 28 Dec 2020 11:35:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727368AbgL1LfL (ORCPT ); Mon, 28 Dec 2020 06:35:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727329AbgL1LfK (ORCPT ); Mon, 28 Dec 2020 06:35:10 -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 0BB3DC061795 for ; Mon, 28 Dec 2020 03:34:30 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id w8so17901023ybj.14 for ; Mon, 28 Dec 2020 03:34:30 -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=BOm5gEp4j3FyKr6ZvMW0OV+Cysy570CCnAgSDPu/Tro=; b=jhdiNwODOertvzE6In7+J1WQa/6nUtMnWw+V8kFDHvIm5wKSm/JxaUmB5wDfA2km6R ker0W1SMJgMovET/PZ5UewyqfqmvmYCf0J/f+rZzpIrFlWyF2vtgu1uGsANGMYAqDcjv ztpUI0zJc+mv441ar9/Kf9YVr7LCiW14mMs/oHr68LPQ6SMmynpWezIAYUlbk7gEicUd 1sXevHSpR8ZgwOAw3zelqDyXqqhocUJnAnM0Ox6ZrwiVDGvN5zfIPDyNOTDLqFp2e32B xUbPmeR4L5DvTrLZnS3twZY+3r6mXA+AzL3el7rMlEvbLqDULkLEXsP9e/DIFThKKlim CSMA== 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=BOm5gEp4j3FyKr6ZvMW0OV+Cysy570CCnAgSDPu/Tro=; b=hK7DXS7URdsOx5B046v6WLH3NaoA8vqobGRfSX7TbutUppvtMHDIfmkMVyenpW7vA8 pU+dpeXuOahyDcJVlf58In42OZVQ1B/XRNRjafvpguGeFEo5gQnvZMmKZuE2Oml0WuLd R8AGryDk6L93L460S+X/zI4rYXXkNFmffAQQ873myQMuAkGoQmZb/79kRewM6A7RJUN2 m38HCCgI8lvb20VQnKmIIQxx04zbzswzoNcszYAayYThDOJXMrOqz/kCz2QIKCWNRjTB JINddkRa2pDEXaFNDTTLNbI0C7gGSpv74SDKC/n15TQufDCoszQhk5X9MwsHX3VbGxNy /vnQ== X-Gm-Message-State: AOAM532TJK9N19TDY6OtBFP36ZJFj8jZM9IdT6VjpOJn/BIxGRTD6UKg PtsIRsHVae78Azscb2ZECXcfkgkyGDKpn8nNz5aXXB1hTCsZVxK9mYoxqYeZE/eFhnK1fZzaox1 ZrA4Cjj9oBm9maqTFUxXzd3xcGxD/X57XSIeErjYL4nuu9jBzZ3kRWj+ypDuGMt4+6hVtd4n0AO hm6hMXgDUQEXA= X-Google-Smtp-Source: ABdhPJyjFA654Q02vGiZnkfsZvIeihVbeGAk94A6ZQCHLgXv5RIw9MIxGluqvSjSPeQRP1kGIjNyoSIaybXge74orA== 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:ba08:: with SMTP id t8mr11057795ybg.316.1609155269239; Mon, 28 Dec 2020 03:34:29 -0800 (PST) Date: Mon, 28 Dec 2020 19:34:18 +0800 In-Reply-To: <20201228193351.Bluez.v3.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20201228193351.Bluez.v3.2.I0c07c297925f838138b42674ab244572e6ea361b@changeid> Mime-Version: 1.0 References: <20201228193351.Bluez.v3.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v3 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 --- 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 Mon Dec 28 11:34:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11991141 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 7BAAAC433E0 for ; Mon, 28 Dec 2020 11:35:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5207A229C5 for ; Mon, 28 Dec 2020 11:35:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727373AbgL1LfO (ORCPT ); Mon, 28 Dec 2020 06:35:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727341AbgL1LfO (ORCPT ); Mon, 28 Dec 2020 06:35:14 -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 B9F37C061796 for ; Mon, 28 Dec 2020 03:34:33 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id e74so17882056ybh.19 for ; Mon, 28 Dec 2020 03:34:33 -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=myFfZUu8s8GYQLY65kKyMRa28LeNcv0Q7GATY8BEH92poZljuTlD1gSciltE5ZaZo6 qxzqYmLU9xAfy1ygBQ75TV8vZ9QMsjGnJ9TYxyL92Bhu98/AqJ0c/ZfA78xhRH5Gh4IN I3rkJmoqnMPW7Yys2+cvIkzhO5XQ+csFg3wK4ZmHxRwr1lUFYXDevqMuGIKqhoFyZ04L 8eIJA0r727eACaDKSquc94v5QWkJJpvV9KALmHOhUjvbaJSiCgLibQnC7pc7ISqbLCCz aS7QV3imUCKXPLyBy3zkaqpuVIti6HK9cbAhZRZNL2auEAl/Z4ti799nNPQ+mc0XxyS9 da4A== 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=PMyqhc6MJVvGtxYuryiWjb9DY1n+I4149fwxs8gUbA8bi6TUDnhmpI3WXUp2q57yUn CvAh/UMi5jFEXhBZkCEnsuouaKoAfv4KhEa2ijh+ybiBGR5fubULphEQ7ol3C6i3T9QB EtZZqmRwHBjPhNl3kuKg8d4sW2XiVGd+SsyPVO721KnV30e5L9Fpk9Rx23Yow3phz27o AspqlJKnyb6ZHfrqZzvFNnW6gdU9fZ/C8JwSvDRlSbb+oTG1jCIwr9F6T0qT5cenbweq hkpZMTj25KqS1j36lrxTpO1nqzLGqWT8751kUXefqLIMblCUozqXLOcZiPn7AcJffWA2 U0kQ== X-Gm-Message-State: AOAM533J9DvYKkyosstSNLmTivrkB+BKePNHmy4rxpSZ1Cc9MHzpUR7E xRaiTTlchde4qeYJhl8+3ODwdqQ/yNCNucjL8Y1Xtpcs4vfwBTHFbmx+7TqINu7kEgjLTyUnAWk Cb+CzPnoOcDAJe9JJLly3E69mj3JuGMz4ma6rFY8jlef9sb+l5rCW/XsI6OBQTFGZCuKFigSG/z fRNEaN2ygLvAs= X-Google-Smtp-Source: ABdhPJxuObMKa+iif9y93CVtystxym1ahJPO2A167er9xTEh8x+4kpTGAZQfQtxD8ogXvIH2wTOG7MB/TMY8w7P6NA== 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:8249:: with SMTP id d9mr60901214ybn.41.1609155272939; Mon, 28 Dec 2020 03:34:32 -0800 (PST) Date: Mon, 28 Dec 2020 19:34:19 +0800 In-Reply-To: <20201228193351.Bluez.v3.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20201228193351.Bluez.v3.3.Idca009971ca95228a3fa7232ef648f18ff64d185@changeid> Mime-Version: 1.0 References: <20201228193351.Bluez.v3.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v3 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 --- (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 Mon Dec 28 11:34:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Howard Chung X-Patchwork-Id: 11991143 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 09071C433E0 for ; Mon, 28 Dec 2020 11:35:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D42FC229C5 for ; Mon, 28 Dec 2020 11:35:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727375AbgL1LfS (ORCPT ); Mon, 28 Dec 2020 06:35:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727329AbgL1LfR (ORCPT ); Mon, 28 Dec 2020 06:35:17 -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 70524C061798 for ; Mon, 28 Dec 2020 03:34:37 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id g17so17930619ybh.5 for ; Mon, 28 Dec 2020 03:34:37 -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=D6yQ0aeiUTF84rpACa7tV0EEPiv+8c73o+8fQ16hv50=; b=DON27MLoCDLCsJFbTf51DMjkvUbLoK87r8WSuIUp+tymFX3tLE1SipNYsjfK9UPrtJ QEI/jHkuntSq8SEEdaIUe+kIg5feZRWlGz4Z4kbQA1VG7EgNQeRAl8od679KG5snkYl9 ORER+yo51+mG7gV1DMP9YSl/8JF0PYfmuXrq1BNkocemZMtyzJ9n+hZg/yIP4g6ZOBwR DLBtIHVwjuW2Osc6k0PkWFaDVT39Qr9qp/d0H5anQLcKWknklZmgu9luJaZXdjpqWb3S CF94845spOA/CaiKhbM7xui7nKmG7wvE1lgukswysudUThgGAi9fIhyHCBJNZWY1rH09 H5Qg== 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=D6yQ0aeiUTF84rpACa7tV0EEPiv+8c73o+8fQ16hv50=; b=ZPawr6lHbwOxWW8M0NrnbvP7mRGEJTlxNM1ootR4wHdImKCdO+e+ZNZ9pM8SbIChgE 5W4aGl6MjwC8xXqv4Ay47fetYIaSSwjsIVOJsSP9n2krE09w3B9SWIA1B4JGOvbjRHfw /6OPtsBV2Rx57PhyOSSA2U9I7rd1GUjeR1+WOLgYMBQxcHlOYBUVihozJK+O2bW2j5h5 mqwFxDjzPD+LhOLDrjf6kRGbaqAVGRQvg8E94yrs7Zl/u2cs7H2dELBt+Dn15PV/FH5W eNVz8b0poKnsDjU33poa8hG3Rgus8ab39cnQy4mGANKxixD+7k3vC9gnNRfOPyK+E43t PO6g== X-Gm-Message-State: AOAM530Nc8VFRKPNqn9KXnLdH2nh8zBSV5Bz2Ecd/h6kL2oMFfH6p7ZY w5bjwwwg5FijoFtmI4VWF7rPLiFaIR7jJbCbEZ5X0UuFRRxfeLOXskw4tLfw36b/jKjja2zRhA/ AXQHXnvMTf5f+svj0PXLBlEq2ypMqaYHCq6eiwRy9cRMqNBftUnQKlJiwB/lb6PrBB/iuYo4Uaj SZglCEJIZt1Ko= X-Google-Smtp-Source: ABdhPJzXp1AQgvSZVHLR3o5TvRqXC/OcYSfi+Wu0w3H3EYWD+P15juQfjif2C/Gn/0Iuej9iZq2inYy9OZHibed0Hg== 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:aa88:: with SMTP id t8mr62078374ybi.292.1609155276643; Mon, 28 Dec 2020 03:34:36 -0800 (PST) Date: Mon, 28 Dec 2020 19:34:20 +0800 In-Reply-To: <20201228193351.Bluez.v3.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> Message-Id: <20201228193351.Bluez.v3.4.I43884adadc00a5095dd03d2261a71dc2ba80d986@changeid> Mime-Version: 1.0 References: <20201228193351.Bluez.v3.1.Ie32770d0eed2e7739ce9d17d920766fb6aee8583@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [Bluez PATCH v3 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 --- (no changes since v2) 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); }