From patchwork Wed May 26 05:13:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 448921 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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 CB00FC47082 for ; Wed, 26 May 2021 05:13:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BE23613D3 for ; Wed, 26 May 2021 05:13:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230384AbhEZFOq (ORCPT ); Wed, 26 May 2021 01:14:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230291AbhEZFOp (ORCPT ); Wed, 26 May 2021 01:14:45 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 863E5C061574 for ; Tue, 25 May 2021 22:13:13 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id i5so24604923pgm.0 for ; Tue, 25 May 2021 22:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=S5qSqx3TwuZ8VsmUQSyplqhBBlTtHbqLkNIGiOXodxw=; b=fTP39yXqqzvXM0GK4pQGyOpTF+SJJzxNyTuplT5txEw8iUhh+aPIDYj+/mH1cautGK tE+2Hxd8YysEEMD30tioOc610IIP0UPTmSqhH9AmBMCSQ0SEI+x0SOpjFQcQlnW0JL3m 6RaJGBcIlOSEWyBA/rpul/33jQ0nuCUR0ixG1BBcDQ+mTTvt41MAtWZJ/lNrn5M37RCq UKefwwVpexaimJ1KJts68IqHYU5ezWIkMAayFA6F4WFZVse5Eo1xuarOq78dh8FjGvdp Z9h4b5RrCp8Un+mt2Y+pDzHE5Wa93DzpYB21/tw8h/YGG091KejS3nutgnduvihv+w8C ME2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=S5qSqx3TwuZ8VsmUQSyplqhBBlTtHbqLkNIGiOXodxw=; b=WWXTiAoKcCKYbgTdNyyPC8hJCTj6e/Yhpu4Np8zGOkVdDk1HMjWmVKRzAyv76kaNkC Mkfx9BGz+67YeaHcBuNz0+OVwgzoCkAP52D/LJjnjTa6G+y+xo7WQqm73FMbCSiDNsgr JzTnymF9hiwP3g4hhuF8VgWqBVdRDWCe+PjiK2dx9D1QixZj4fIqzILQU3paafP4O3oc cHXqKY1CY2/7c0jFA7AQelA06wE7Ez5tEAGYQxQ+x1x+K3Gs3km+voRoT4JRZd7weLs1 vSNRrws08Bml0vdbFTfyF3bItezznxPTQZSWKb5VSqmXbqfFstrQ3TgxOybklJfnN7ii 70FQ== X-Gm-Message-State: AOAM533D6+obiShVJ64mxYWikSmdjSn8yNMcdXhlpd/sndcJ8EX2KDqw vTNXJmLpKRLndfA1DtoFPp9NjheZIwb9FA== X-Google-Smtp-Source: ABdhPJwllc2xGqHVnSqwPoD57B4NCA8ecPHSS/gaQ5P5qsJuLQKm5/ZLTdFGUqxdh8U/m2WczUKm/Q== X-Received: by 2002:a63:b545:: with SMTP id u5mr22822391pgo.261.1622005992600; Tue, 25 May 2021 22:13:12 -0700 (PDT) Received: from han1-mobl3.intel.com ([2601:1c0:6a01:d830::e853]) by smtp.gmail.com with ESMTPSA id h8sm13865944pfv.60.2021.05.25.22.13.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 22:13:11 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [PATCH V2 1/4] tools/btmgmt: Add device flags commands Date: Tue, 25 May 2021 22:13:07 -0700 Message-Id: <20210526051310.423630-1-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch adds commands for get/set device flags mgmt ops. Usage: get-flags [-t type]
-t type Address Type 0 BR/EDR 1 LE Public 2 LE Random set-flags [-f flags] [-t type]
-t type Address Type 0 BR/EDR 1 LE Public 2 LE Random -f flags Device flag. 1 Remote Wake Enable --- tools/btmgmt.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index bf3b460d0..a6ac026dc 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -1000,6 +1000,24 @@ static void advertising_removed(uint16_t index, uint16_t len, print("hci%u advertising_removed: instance %u", index, ev->instance); } +static void flags_changed(uint16_t index, uint16_t len, const void *param, + void *user_data) +{ + const struct mgmt_ev_device_flags_changed *ev = param; + char addr[18]; + + if (len < sizeof(*ev)) { + error("Too small (%u bytes) %s event", len, __func__); + return; + } + + ba2str(&ev->addr.bdaddr, addr); + print("hci%u device_flags_changed: %s (%s)", index, addr, + typestr(ev->addr.type)); + print(" supp: 0x%08x curr: 0x%08x", + ev->supported_flags, ev->current_flags); +} + static void advmon_added(uint16_t index, uint16_t len, const void *param, void *user_data) { @@ -2110,6 +2128,156 @@ static void cmd_auto_power(int argc, char **argv) } } +static void get_flags_rsp(uint8_t status, uint16_t len, const void *param, + void *user_data) +{ + const struct mgmt_rp_get_device_flags *rp = param; + + if (status != 0) { + error("Get device flags failed with status 0x%02x (%s)", + status, mgmt_errstr(status)); + bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + print("Supported Flags: 0x%08x", rp->supported_flags); + print("Current Flags: 0x%08x", rp->current_flags); + bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + +static struct option get_flags_options[] = { + { "help", 0, 0, 'h' }, + { "type", 1, 0, 't' }, + { 0, 0, 0, 0 } +}; + +static void cmd_get_flags(int argc, char **argv) +{ + struct mgmt_cp_get_device_flags cp; + uint8_t type = BDADDR_BREDR; + char addr[18]; + int opt; + uint16_t index; + + while ((opt = getopt_long(argc, argv, "+t:h", get_flags_options, + NULL)) != -1) { + switch (opt) { + case 't': + type = strtol(optarg, NULL, 0); + break; + case 'h': + bt_shell_usage(); + optind = 0; + return bt_shell_noninteractive_quit(EXIT_SUCCESS); + default: + bt_shell_usage(); + optind = 0; + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + } + + argc -= optind; + argv += optind; + optind = 0; + + if (argc < 1) { + bt_shell_usage(); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + index = mgmt_index; + if (index == MGMT_INDEX_NONE) + index = 0; + + memset(&cp, 0, sizeof(cp)); + str2ba(argv[0], &cp.addr.bdaddr); + cp.addr.type = type; + + ba2str(&cp.addr.bdaddr, addr); + print("Get device flag of %s (%s)", addr, typestr(cp.addr.type)); + + if (mgmt_send(mgmt, MGMT_OP_GET_DEVICE_FLAGS, index, sizeof(cp), &cp, + get_flags_rsp, NULL, NULL) == 0) { + error("Unable to send Get Device Flags command"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } +} + +static void set_flags_rsp(uint8_t status, uint16_t len, const void *param, + void *user_data) +{ + if (status != 0) { + error("Set device flags failed with status 0x%02x (%s)", + status, mgmt_errstr(status)); + bt_shell_noninteractive_quit(EXIT_FAILURE); + } + bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + +static struct option set_flags_options[] = { + { "help", 0, 0, 'h' }, + { "type", 1, 0, 't' }, + { "flags", 1, 0, 'f' }, + { 0, 0, 0, 0 } +}; + +static void cmd_set_flags(int argc, char **argv) +{ + struct mgmt_cp_set_device_flags cp; + uint8_t type = BDADDR_BREDR; + uint32_t flags = 0; + char addr[18]; + int opt; + uint16_t index; + + while ((opt = getopt_long(argc, argv, "+f:t:h", set_flags_options, + NULL)) != -1) { + switch (opt) { + case 'f': + flags = strtol(optarg, NULL, 0); + break; + case 't': + type = strtol(optarg, NULL, 0); + break; + case 'h': + bt_shell_usage(); + optind = 0; + return bt_shell_noninteractive_quit(EXIT_SUCCESS); + default: + bt_shell_usage(); + optind = 0; + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + } + + argc -= optind; + argv += optind; + optind = 0; + + if (argc < 1) { + bt_shell_usage(); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + index = mgmt_index; + if (index == MGMT_INDEX_NONE) + index = 0; + + memset(&cp, 0, sizeof(cp)); + str2ba(argv[0], &cp.addr.bdaddr); + cp.addr.type = type; + cp.current_flags = flags; + + ba2str(&cp.addr.bdaddr, addr); + print("Set device flag of %s (%s)", addr, typestr(cp.addr.type)); + + if (mgmt_send(mgmt, MGMT_OP_SET_DEVICE_FLAGS, index, sizeof(cp), &cp, + set_flags_rsp, NULL, NULL) == 0) { + error("Unable to send Set Device Flags command"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + +} + /* Wrapper to get the index and opcode to the response callback */ struct command_data { uint16_t id; @@ -5197,6 +5365,8 @@ static void register_mgmt_callbacks(struct mgmt *mgmt, uint16_t index) advertising_added, NULL, NULL); mgmt_register(mgmt, MGMT_EV_ADVERTISING_REMOVED, index, advertising_removed, NULL, NULL); + mgmt_register(mgmt, MGMT_EV_DEVICE_FLAGS_CHANGED, index, + flags_changed, NULL, NULL); mgmt_register(mgmt, MGMT_EV_ADV_MONITOR_ADDED, index, advmon_added, NULL, NULL); mgmt_register(mgmt, MGMT_EV_ADV_MONITOR_REMOVED, index, advmon_removed, @@ -5381,6 +5551,10 @@ static const struct bt_shell_menu main_menu = { cmd_read_sysconfig, "Read System Configuration" }, { "set-sysconfig", "<-v|-h> [options...]", cmd_set_sysconfig, "Set System Configuration" }, + { "get-flags", "[-t type]
", + cmd_get_flags, "Get device flags" }, + { "set-flags", "[-f flags] [-t type]
", + cmd_set_flags, "Set device flags" }, {} }, }; From patchwork Wed May 26 05:13:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 448304 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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 AD174C2B9F7 for ; Wed, 26 May 2021 05:13:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CF8B613C3 for ; Wed, 26 May 2021 05:13:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230075AbhEZFOp (ORCPT ); Wed, 26 May 2021 01:14:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbhEZFOo (ORCPT ); Wed, 26 May 2021 01:14:44 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11131C061756 for ; Tue, 25 May 2021 22:13:14 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id q16so36121pls.6 for ; Tue, 25 May 2021 22:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=H2zwyia3p7d2uxe0ZBO4miRasBmJH8+968BsSYNruX4=; b=UX5Wv+u1n8fHxMG7kbR+dwhEgLGL764zJzx8iMvpgX3iKdoXKNXhPkv6ChzWcBWtVt xydigNLBlb7HX1ycNfalyiUDxSxCOHhg9qLJVP55YFZEwuKjEk0g084lv4E29gVyzokK m55XHO0IKJ7yNy3PuWVy3iD0QeQc1HhtgIkZmalL84RbGj5DH8Nmr5Job50CNWqoUWRc 3OdskZ1kk12y/4hJObiNW5EBDRVV7dtnwu6ZGZHe6b2TbbZvTeRSTX7AQWhkPa+6iimo kCte5OknhO8UYq984PY7lrZXoOG7Cev7EgCUDTgBJA8g3LOJjiMZ1H2n2+J7uGMYqXWu DypQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=H2zwyia3p7d2uxe0ZBO4miRasBmJH8+968BsSYNruX4=; b=c39k8RF2FSoQzQ8FXxCvCceYvzsQnLuPsT3cmEJI5dKe5S6LaOcJkntGxbrx/KxC6j BQWToUN6DNsKZ6e+VlHpg4f4k5oE5n13iytMvVI3IbX9k/hEZZF/oOsFrrp7a1A/Loce fFKStnnns7HFWoVVitIN/atNW7oiQmJ8Cv4HPru7NMKNw7ME6NBOHgBIk+6hRZSkBYUE 7DYMbapX4raWlQIlnISqjQzKcvMtAiiJlsMTsnfmteRoaAQH+TXv47zjOsbzxY+panJp yfoytB9ZxLlkPZR8Z+aH716okiKNNK98v4t3bYHdzWEOtelEigapwr/IVGuOTGZBXM81 5mEw== X-Gm-Message-State: AOAM5329qeHE8H17sDakwE73UBRdMJhAG+pyQxzlK8X5U46jGXSyLhTG OfdHo1CQiIz3DFCTrG3rdlI+hQD5rpIJHA== X-Google-Smtp-Source: ABdhPJxsf4h8dhEkw47Bo7A3grQU15jRl65ZRME91E+ZA5mR53+x6TLQ0ZFzlstZrKyRluuU0pBTfA== X-Received: by 2002:a17:90a:aa0a:: with SMTP id k10mr34879994pjq.33.1622005993460; Tue, 25 May 2021 22:13:13 -0700 (PDT) Received: from han1-mobl3.intel.com ([2601:1c0:6a01:d830::e853]) by smtp.gmail.com with ESMTPSA id h8sm13865944pfv.60.2021.05.25.22.13.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 22:13:13 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [PATCH V2 2/4] lib: Align mgmt header with document Date: Tue, 25 May 2021 22:13:08 -0700 Message-Id: <20210526051310.423630-2-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210526051310.423630-1-hj.tedd.an@gmail.com> References: <20210526051310.423630-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch updates the mgmt header to align with the mgmt api document (doc/mgmt-api.txt) --- lib/mgmt.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/mgmt.h b/lib/mgmt.h index a85f891c5..0a6349321 100644 --- a/lib/mgmt.h +++ b/lib/mgmt.h @@ -1087,11 +1087,13 @@ static const char *mgmt_op[] = { "Set PHY Configuration", "Set Blocked Keys", "Set Wideband Speech", - "Read Security Information", /* 0x0048 */ + "Read Controller Capabilities Information", /* 0x0048 */ "Read Experimental Features Information", "Set Experimental Feature", "Read Default System Configuration", "Set Default System Configuration", + "Read Default Runtime Configuration", + "Set Default Runtime Configuration", "Get Device Flags", "Set Device Flags", /* 0x0050 */ "Read Advertisement Monitor Features", @@ -1143,6 +1145,8 @@ static const char *mgmt_ev[] = { "Extended Controller Information Changed", "PHY Configuration Changed", "Experimental Feature Changed", + "Default System Configuration Changed", /* 0x0028 */ + "Default Runtime Configuration Changed", "Device Flags Changed", "Advertisement Monitor Added", /* 0x002b */ "Advertisement Monitor Removed", @@ -1172,6 +1176,7 @@ static const char *mgmt_status[] = { "Blocked through rfkill", "Already Paired", "Permission Denied", + "Connection Not Established", }; #ifndef NELEM From patchwork Wed May 26 05:13:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 448303 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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 844BAC2B9F7 for ; Wed, 26 May 2021 05:13:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63385613CD for ; Wed, 26 May 2021 05:13:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230397AbhEZFPB (ORCPT ); Wed, 26 May 2021 01:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230291AbhEZFOq (ORCPT ); Wed, 26 May 2021 01:14:46 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02B6DC061756 for ; Tue, 25 May 2021 22:13:15 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id q6so181380pjj.2 for ; Tue, 25 May 2021 22:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=tuQ9nKR0cuSGFqJeNxh6e/A49jphmCAZQX2vjqtzuuA=; b=cnTmwR4gQztrYqp4GWoiQv3/+XQh/krfS715N7hjTXj1Ews649XxtWGwpHaDNcIByo ZvIsZyR2q0y13YLo8E3UNYkxa21l3XUHxxcWPIkbHWl+SFWlGE5vJ87N+LTby5f56kmr RescCVTV1sbXcvBdJ82gcpx9aMx3sIB8axM6K9JYT/zzxaht00Yoqp+4WsRJQF/n/vCS isKL9X07rXiUZzBJ7PIbN0RbbyMGYR6tygaSdhbPxts6JYC6+01aBmBF2nRDOZHC6Euw CfRHnA8R0lJYkiB3rtEkJQya2NUFoNhiVFHhfxTlvYkO5HVrsDtpClDufCecBjTWsWA1 jseA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tuQ9nKR0cuSGFqJeNxh6e/A49jphmCAZQX2vjqtzuuA=; b=tOWfN1Vkdg/F9stmmJ4QoHyNI5I400HERFrbzdhgevKy8ecXmrbibka4U8DIRoHU2v KHSeQD1d0BZgQgBdITSzj3a6nC/x9eOrIjoj+zMnkhD33HyuTbmoTlVpBAov6GONBh7c esN5ld7GGLVIZojYBAjm2fsya+G0y6Iacvs+zUsYxVHYyQYmL3svJjSZNK3NhxXh0Nx6 7lbGisdTFsbvXzI0lN1soiAsyjO+vcAjMXuNabRBbXnAoFl8tLj155YxYJBhdxzv61A4 wKvBFfMQ4gJA6/tnVq5M9kzs6ErGSyWaCdYG7W7CUA9q0KZcVerALh9wyb0+3ooXQ9mk 6mPg== X-Gm-Message-State: AOAM533kvCVLmgyQEXmRWavrQVzq1W8Lv4gBNTmt2hDhNubWOez9fM1J U9DQmD7Q++2hA6H7rxQ87O8W0101SpagLA== X-Google-Smtp-Source: ABdhPJxRThdEg5ydjHjuBa/G/3CurSvEkfIRaLOvcLrb+2WUORLuscQTRunyDGPdIEhWKLvHwybJNw== X-Received: by 2002:a17:90a:549:: with SMTP id h9mr2162116pjf.158.1622005994416; Tue, 25 May 2021 22:13:14 -0700 (PDT) Received: from han1-mobl3.intel.com ([2601:1c0:6a01:d830::e853]) by smtp.gmail.com with ESMTPSA id h8sm13865944pfv.60.2021.05.25.22.13.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 22:13:13 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [PATCH V2 3/4] tools/mgmt-tester: Print hexdump if mgmt event parameters not match Date: Tue, 25 May 2021 22:13:09 -0700 Message-Id: <20210526051310.423630-3-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210526051310.423630-1-hj.tedd.an@gmail.com> References: <20210526051310.423630-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch displays the hexdump of expected and received mgmt event parameters. --- tools/mgmt-tester.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c index c9de770c1..767e010a6 100644 --- a/tools/mgmt-tester.c +++ b/tools/mgmt-tester.c @@ -6780,6 +6780,9 @@ static bool verify_alt_ev(const void *param, uint16_t length) if (test->expect_alt_ev_param && memcmp(test->expect_alt_ev_param, param, length)) { tester_warn("Event parameters do not match"); + util_hexdump('>', param, length, print_debug, ""); + util_hexdump('!', test->expect_alt_ev_param, length, + print_debug, ""); return false; } From patchwork Wed May 26 05:13:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 448920 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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 23345C47082 for ; Wed, 26 May 2021 05:13:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC7A6613CD for ; Wed, 26 May 2021 05:13:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230419AbhEZFPB (ORCPT ); Wed, 26 May 2021 01:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230366AbhEZFOq (ORCPT ); Wed, 26 May 2021 01:14:46 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5C8DC061574 for ; Tue, 25 May 2021 22:13:15 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id y202so77262pfc.6 for ; Tue, 25 May 2021 22:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=V9FyyF9jdSeK5S3rBQkL/uwGCuTX2AyYnA3Dlag4pLU=; b=UugGpP2oZDST6ydnEIlcE+mtcrln3MaHc9maNyssOuoAcGdbFa9tSt71nJhPImzx/V pRloNgvV854VrJkf055zkFJzUq7CTXqvFC5jKqjuF1wzpbf830oykh+q7w5p66V40WCR TGWuRhyt4fW3EgDHeOtqTuAtgfsHo+t75CSWBSEE22BDLhm1fSeETZQ/OBP2oLeeKHv7 097CdUf2RM/+nLnNynCTgscbAee4xLkH1G/EzIutTNEK7K71cwP72VapmUg4GKiPU43M 7pDQAMCtdwR7fj0r5J0RnAFou1H/zyAhxrwVKZevNCNvhWxMULxApHIw42pffw4XKEaf auwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V9FyyF9jdSeK5S3rBQkL/uwGCuTX2AyYnA3Dlag4pLU=; b=Nbilu5iccasGL4QQ3HXMoH7pGR5A+ugWIiZTxSYZmE2n7ZvLTUqkVK8k2M+9rE9wD7 3y0tBXND9sWL3g10cuYKuO8j8Za34cz6xVaws+T/8vSf0YlgsQOfISe/lNw5QBm5Dtng CglaevJd5wTGub0gkJeDC+AXLEx4XZMcanFdzWWqxyvLLDB0YwtD5Mh31s7LGA5j18II HrQaS5Myw2yA6VAqNbve4mHKwfS1gl61BulTQiaYIxTrzRIja1rblpoVvVWLmFQ+Bnkt uTV4cYDpiBB+bccghq8SYs+l00q1T6Ew4zqF4OmNA+0NzaMSEBZqE25prjJjrELroneT xX1w== X-Gm-Message-State: AOAM531vbBDPyFdgWWDU/8RU/dohXcaXGUadOw5dm7UanW8RCEnF7NsN RkGCL49QslBGwnzMFZXmRmuq2fpEgypMRQ== X-Google-Smtp-Source: ABdhPJwC5hCzIUnuG/gXpqGiUq0/fLrYxxwqI+H4PwuehJk9zqdD6SkMMWT5SqEU/7ZXbirZ9/zntg== X-Received: by 2002:a65:68d4:: with SMTP id k20mr11376463pgt.442.1622005995223; Tue, 25 May 2021 22:13:15 -0700 (PDT) Received: from han1-mobl3.intel.com ([2601:1c0:6a01:d830::e853]) by smtp.gmail.com with ESMTPSA id h8sm13865944pfv.60.2021.05.25.22.13.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 May 2021 22:13:14 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [PATCH V2 4/4] tools/mgmt-tester: Add test cases for get/set device flags Date: Tue, 25 May 2021 22:13:10 -0700 Message-Id: <20210526051310.423630-4-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210526051310.423630-1-hj.tedd.an@gmail.com> References: <20210526051310.423630-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch adds test cases for get/set device flags commands. --- tools/mgmt-tester.c | 182 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c index 767e010a6..4550d6e9c 100644 --- a/tools/mgmt-tester.c +++ b/tools/mgmt-tester.c @@ -8990,6 +8990,140 @@ static void setup_phy_configuration(const void *test_data) NULL, NULL); } +static const uint8_t get_dev_flags_param[] = { + 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */ + 0x00, /* Type */ +}; + +static const uint8_t get_dev_flags_rsp_param[] = { + 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */ + 0x00, /* Type */ + 0x01, 0x00, 0x00, 0x00, /* Supported Flages */ + 0x00, 0x00, 0x00, 0x00, /* Current Flages */ +}; + +static const struct generic_data get_dev_flags_success = { + .send_opcode = MGMT_OP_GET_DEVICE_FLAGS, + .send_param = get_dev_flags_param, + .send_len = sizeof(get_dev_flags_param), + .expect_status = MGMT_STATUS_SUCCESS, + .expect_param = get_dev_flags_rsp_param, + .expect_len = sizeof(get_dev_flags_rsp_param), +}; + +static const uint8_t get_dev_flags_param_fail_1[] = { + 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */ +}; + +static const struct generic_data get_dev_flags_fail_1 = { + .send_opcode = MGMT_OP_GET_DEVICE_FLAGS, + .send_param = get_dev_flags_param_fail_1, + .send_len = sizeof(get_dev_flags_param_fail_1), + .expect_status = MGMT_STATUS_INVALID_PARAMS, +}; + +static void setup_get_dev_flags(const void *test_data) +{ + struct test_data *data = tester_get_data(); + unsigned char param[] = { 0x01 }; + const unsigned char *add_param; + size_t add_param_len; + + tester_print("Powering on controller (with added device)"); + + if (data->hciemu_type == HCIEMU_TYPE_LE) { + add_param = add_device_success_param_2; + add_param_len = sizeof(add_device_success_param_2); + } else { + add_param = add_device_success_param_1; + add_param_len = sizeof(add_device_success_param_1); + } + + mgmt_send(data->mgmt, MGMT_OP_ADD_DEVICE, data->mgmt_index, + add_param_len, add_param, NULL, NULL, NULL); + + mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index, + sizeof(param), param, + setup_powered_callback, NULL, NULL); +} + +static const uint8_t set_dev_flags_param[] = { + 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */ + 0x00, /* Type */ + 0x01, 0x00, 0x00, 0x00, /* Current Flages */ +}; + +static const uint8_t set_dev_flags_rsp_param[] = { + 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */ + 0x00, /* Type */ +}; + +static const uint8_t dev_flags_changed_param[] = { + 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */ + 0x00, /* Type */ + 0x01, 0x00, 0x00, 0x00, /* Supported Flages */ + 0x01, 0x00, 0x00, 0x00, /* Current Flages */ +}; + +static const struct generic_data set_dev_flags_success = { + .send_opcode = MGMT_OP_SET_DEVICE_FLAGS, + .send_param = set_dev_flags_param, + .send_len = sizeof(set_dev_flags_param), + .expect_status = MGMT_STATUS_SUCCESS, + .expect_param = set_dev_flags_rsp_param, + .expect_len = sizeof(set_dev_flags_rsp_param), + .expect_alt_ev = MGMT_EV_DEVICE_FLAGS_CHANGED, + .expect_alt_ev_param = dev_flags_changed_param, + .expect_alt_ev_len = sizeof(dev_flags_changed_param), +}; + +static const uint8_t set_dev_flags_param_fail_1[] = { + 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */ + 0x00, /* Type */ +}; + +static const struct generic_data set_dev_flags_fail_1 = { + .send_opcode = MGMT_OP_SET_DEVICE_FLAGS, + .send_param = set_dev_flags_param_fail_1, + .send_len = sizeof(set_dev_flags_param_fail_1), + .expect_status = MGMT_STATUS_INVALID_PARAMS, +}; + +static const uint8_t set_dev_flags_param_fail_2[] = { + 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */ + 0x00, /* Type */ + 0x03, 0x00, 0x00, 0x00, /* Current Flages */ +}; + +static const struct generic_data set_dev_flags_fail_2 = { + .send_opcode = MGMT_OP_SET_DEVICE_FLAGS, + .send_param = set_dev_flags_param_fail_2, + .send_len = sizeof(set_dev_flags_param_fail_2), + .expect_status = MGMT_STATUS_INVALID_PARAMS, + .expect_param = set_dev_flags_rsp_param, + .expect_len = sizeof(set_dev_flags_rsp_param), +}; + +static const uint8_t set_dev_flags_param_fail_3[] = { + 0x11, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */ + 0x00, /* Type */ + 0x01, 0x00, 0x00, 0x00, /* Current Flages */ +}; + +static const uint8_t set_dev_flags_rsp_param_fail_3[] = { + 0x11, 0x34, 0x56, 0x78, 0x9a, 0xbc, /* Address */ + 0x00, /* Type */ +}; + +static const struct generic_data set_dev_flags_fail_3 = { + .send_opcode = MGMT_OP_SET_DEVICE_FLAGS, + .send_param = set_dev_flags_param_fail_3, + .send_len = sizeof(set_dev_flags_param_fail_3), + .expect_status = MGMT_STATUS_INVALID_PARAMS, + .expect_param = set_dev_flags_rsp_param_fail_3, + .expect_len = sizeof(set_dev_flags_rsp_param_fail_3), +}; + static bool power_off(uint16_t index) { int sk, err; @@ -11010,5 +11144,53 @@ int main(int argc, char *argv[]) NULL, test_command_generic); + /* MGMT_OP_GET_DEVICE_FLAGS + * Success + */ + test_bredrle50("Get Device Flags - Success", + &get_dev_flags_success, + setup_get_dev_flags, + test_command_generic); + + /* MGMT_OP_GET_DEVICE_FLAGS + * Fail - Invalid parameter + */ + test_bredrle50("Get Device Flags - Invalid Parameter", + &get_dev_flags_fail_1, + setup_get_dev_flags, + test_command_generic); + + /* MGMT_OP_SET_DEVICE_FLAGS + * Success + */ + test_bredrle50("Set Device Flags - Success", + &set_dev_flags_success, + setup_get_dev_flags, + test_command_generic); + + /* MGMT_OP_SET_DEVICE_FLAGS + * Invalid Parameter - Missing parameter + */ + test_bredrle50("Set Device Flags - Invalid Parameter 1", + &set_dev_flags_fail_1, + setup_get_dev_flags, + test_command_generic); + + /* MGMT_OP_SET_DEVICE_FLAGS + * Invalid Parameter - Not supported value + */ + test_bredrle50("Set Device Flags - Invalid Parameter 2", + &set_dev_flags_fail_2, + setup_get_dev_flags, + test_command_generic); + + /* MGMT_OP_SET_DEVICE_FLAGS + * Device not exist + */ + test_bredrle50("Set Device Flags - Device not found", + &set_dev_flags_fail_3, + setup_get_dev_flags, + test_command_generic); + return tester_run(); }