From patchwork Tue Sep 7 11:25:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "K, Kiran" X-Patchwork-Id: 508000 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=-9.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS,UNWANTED_LANGUAGE_BODY,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 877ABC433F5 for ; Tue, 7 Sep 2021 11:20:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FEA161100 for ; Tue, 7 Sep 2021 11:20:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245127AbhIGLWB (ORCPT ); Tue, 7 Sep 2021 07:22:01 -0400 Received: from mga14.intel.com ([192.55.52.115]:50899 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239767AbhIGLWB (ORCPT ); Tue, 7 Sep 2021 07:22:01 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10099"; a="219856267" X-IronPort-AV: E=Sophos;i="5.85,274,1624345200"; d="scan'208";a="219856267" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2021 04:20:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,274,1624345200"; d="scan'208";a="448960453" Received: from intel-lenovo-legion-y540-15irh-pg0.iind.intel.com ([10.224.186.95]) by orsmga002.jf.intel.com with ESMTP; 07 Sep 2021 04:20:33 -0700 From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: ravishankar.srivatsa@intel.com, chethan.tumkur.narayan@intel.com, tedd.an@intel.com, luiz.von.dentz@intel.com, michaelfsun@google.com, Kiran K Subject: [PATCH v2 1/3] tools/sco-tester: add test cases to get offload codecs Date: Tue, 7 Sep 2021 16:55:54 +0530 Message-Id: <20210907112556.11848-1-kiran.k@intel.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Add a test case to query offload codecs supported over sco --- Notes: changes in v2: - Fix unused variables lib/bluetooth.h | 18 +++++++++++ tools/sco-tester.c | 76 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/lib/bluetooth.h b/lib/bluetooth.h index 9ab033ec41a4..0fcf412c6c6b 100644 --- a/lib/bluetooth.h +++ b/lib/bluetooth.h @@ -140,6 +140,24 @@ struct bt_voice { #define BT_SCM_PKT_STATUS 0x03 +#define BT_CODEC 19 +struct bt_codec { + uint8_t id; + uint16_t cid; + uint16_t vid; + uint8_t data_path_id; + uint8_t num_caps; + struct codec_caps { + uint8_t len; + uint8_t data[]; + } caps[]; +} __attribute__((packed)); + +struct bt_codecs { + uint8_t num_codecs; + struct bt_codec codecs[]; +} __attribute__((packed)); + /* Connection and socket states */ enum { BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */ diff --git a/tools/sco-tester.c b/tools/sco-tester.c index 2b8dc0d4a8f8..0c4d9d76e4df 100644 --- a/tools/sco-tester.c +++ b/tools/sco-tester.c @@ -38,6 +38,7 @@ struct test_data { enum hciemu_type hciemu_type; unsigned int io_id; bool disable_esco; + bool enable_codecs; }; struct sco_client_data { @@ -124,6 +125,18 @@ static void index_removed_callback(uint16_t index, uint16_t length, tester_post_teardown_complete(); } +static void enable_codec_callback(uint8_t status, uint16_t length, + const void *param, void *user_data) +{ + if (status != MGMT_STATUS_SUCCESS) { + tester_warn("Failed to enable codecs"); + tester_setup_failed(); + return; + } + + tester_print("Enabled codecs"); +} + static void read_index_list_callback(uint8_t status, uint16_t length, const void *param, void *user_data) { @@ -202,7 +215,7 @@ static void test_data_free(void *test_data) free(data); } -#define test_sco_full(name, data, setup, func, _disable_esco) \ +#define test_sco_full(name, data, setup, func, _disable_esco, _enable_codecs) \ do { \ struct test_data *user; \ user = malloc(sizeof(struct test_data)); \ @@ -212,16 +225,20 @@ static void test_data_free(void *test_data) user->io_id = 0; \ user->test_data = data; \ user->disable_esco = _disable_esco; \ + user->enable_codecs = _enable_codecs; \ tester_add_full(name, data, \ test_pre_setup, setup, func, NULL, \ test_post_teardown, 2, user, test_data_free); \ } while (0) #define test_sco(name, data, setup, func) \ - test_sco_full(name, data, setup, func, false) + test_sco_full(name, data, setup, func, false, false) #define test_sco_11(name, data, setup, func) \ - test_sco_full(name, data, setup, func, true) + test_sco_full(name, data, setup, func, true, false) + +#define test_offload_sco(name, data, setup, func) \ + test_sco_full(name, data, setup, func, false, true) static const struct sco_client_data connect_success = { .expect_err = 0 @@ -281,6 +298,25 @@ static void setup_powered(const void *test_data) mgmt_send(data->mgmt, MGMT_OP_SET_LE, data->mgmt_index, sizeof(param), param, NULL, NULL, NULL); + if (data->enable_codecs) { + /* a6695ace-ee7f-4fb9-881a-5fac66c629af */ + static const uint8_t uuid[16] = { + 0xaf, 0x29, 0xc6, 0x66, 0xac, 0x5f, 0x1a, 0x88, + 0xb9, 0x4f, 0x7f, 0xee, 0xce, 0x5a, 0x69, 0xa6, + }; + + struct mgmt_cp_set_exp_feature cp; + + memset(&cp, 0, sizeof(cp)); + memcpy(cp.uuid, uuid, 16); + cp.action = 1; + + tester_print("Enabling codecs"); + + mgmt_send(data->mgmt, MGMT_OP_SET_EXP_FEATURE, data->mgmt_index, + sizeof(cp), &cp, enable_codec_callback, NULL, NULL); + } + mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index, sizeof(param), param, setup_powered_callback, NULL, NULL); @@ -308,6 +344,37 @@ static void test_socket(const void *test_data) tester_test_passed(); } +static void test_codecs_getsockopt(const void *test_data) +{ + int sk, err; + socklen_t len; + char buffer[255]; + + sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO); + if (sk < 0) { + tester_warn("Can't create socket: %s (%d)", strerror(errno), + errno); + tester_test_failed(); + return; + } + + len = sizeof(buffer); + memset(buffer, 0, len); + + err = getsockopt(sk, SOL_BLUETOOTH, BT_CODEC, buffer, &len); + if (err < 0) { + tester_warn("Can't get socket option : %s (%d)", + strerror(errno), errno); + tester_test_failed(); + goto end; + } + + tester_test_passed(); + +end: + close(sk); +} + static void test_getsockopt(const void *test_data) { int sk, err; @@ -599,5 +666,8 @@ int main(int argc, char *argv[]) test_sco_11("SCO mSBC 1.1 - Failure", &connect_failure, setup_powered, test_connect_transp); + test_offload_sco("Basic SCO Get Socket Option - Offload - Success", + NULL, setup_powered, test_codecs_getsockopt); + return tester_run(); } From patchwork Tue Sep 7 11:25:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "K, Kiran" X-Patchwork-Id: 507603 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=-11.8 required=3.0 tests=BAYES_00, 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 15F76C433EF for ; Tue, 7 Sep 2021 11:20:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9F93610FF for ; Tue, 7 Sep 2021 11:20:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343546AbhIGLWC (ORCPT ); Tue, 7 Sep 2021 07:22:02 -0400 Received: from mga14.intel.com ([192.55.52.115]:50899 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244382AbhIGLWB (ORCPT ); Tue, 7 Sep 2021 07:22:01 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10099"; a="219856271" X-IronPort-AV: E=Sophos;i="5.85,274,1624345200"; d="scan'208";a="219856271" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2021 04:20:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,274,1624345200"; d="scan'208";a="448960473" Received: from intel-lenovo-legion-y540-15irh-pg0.iind.intel.com ([10.224.186.95]) by orsmga002.jf.intel.com with ESMTP; 07 Sep 2021 04:20:36 -0700 From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: ravishankar.srivatsa@intel.com, chethan.tumkur.narayan@intel.com, tedd.an@intel.com, luiz.von.dentz@intel.com, michaelfsun@google.com, Kiran K Subject: [PATCH v2 2/3] tools/sco-tester: Add a test case for setting offload codec Date: Tue, 7 Sep 2021 16:55:55 +0530 Message-Id: <20210907112556.11848-2-kiran.k@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210907112556.11848-1-kiran.k@intel.com> References: <20210907112556.11848-1-kiran.k@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Add a test case to set codec for HFP offload use case --- Notes: changes in v2: - No changes tools/sco-tester.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tools/sco-tester.c b/tools/sco-tester.c index 0c4d9d76e4df..67ea4769ef2b 100644 --- a/tools/sco-tester.c +++ b/tools/sco-tester.c @@ -375,6 +375,43 @@ end: close(sk); } +static void test_codecs_setsockopt(const void *test_data) +{ + int sk, err; + char buffer[255]; + struct bt_codecs *codecs; + + sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO); + if (sk < 0) { + tester_warn("Can't create socket: %s (%d)", strerror(errno), + errno); + tester_test_failed(); + return; + } + + memset(buffer, 0, sizeof(buffer)); + + codecs = (void *)buffer; + + codecs->codecs[0].id = 0x05; + codecs->num_codecs = 1; + codecs->codecs[0].data_path_id = 1; + codecs->codecs[0].num_caps = 0x00; + + err = setsockopt(sk, SOL_BLUETOOTH, BT_CODEC, codecs, sizeof(buffer)); + if (err < 0) { + tester_warn("Can't set socket option : %s (%d)", + strerror(errno), errno); + tester_test_failed(); + goto end; + } + + tester_test_passed(); + +end: + close(sk); +} + static void test_getsockopt(const void *test_data) { int sk, err; @@ -669,5 +706,8 @@ int main(int argc, char *argv[]) test_offload_sco("Basic SCO Get Socket Option - Offload - Success", NULL, setup_powered, test_codecs_getsockopt); + test_offload_sco("Basic SCO Set Socket Option - Offload - Success", + NULL, setup_powered, test_codecs_setsockopt); + return tester_run(); } From patchwork Tue Sep 7 11:25:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "K, Kiran" X-Patchwork-Id: 507999 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=-11.8 required=3.0 tests=BAYES_00, 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 F0F14C433FE for ; Tue, 7 Sep 2021 11:20:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D9C9761100 for ; Tue, 7 Sep 2021 11:20:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343632AbhIGLWD (ORCPT ); Tue, 7 Sep 2021 07:22:03 -0400 Received: from mga14.intel.com ([192.55.52.115]:50899 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245597AbhIGLWC (ORCPT ); Tue, 7 Sep 2021 07:22:02 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10099"; a="219856281" X-IronPort-AV: E=Sophos;i="5.85,274,1624345200"; d="scan'208";a="219856281" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2021 04:20:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,274,1624345200"; d="scan'208";a="448960502" Received: from intel-lenovo-legion-y540-15irh-pg0.iind.intel.com ([10.224.186.95]) by orsmga002.jf.intel.com with ESMTP; 07 Sep 2021 04:20:38 -0700 From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: ravishankar.srivatsa@intel.com, chethan.tumkur.narayan@intel.com, tedd.an@intel.com, luiz.von.dentz@intel.com, michaelfsun@google.com, Kiran K Subject: [PATCH v2 3/3] tools/sco-tester: add a test case for offload SCO connect Date: Tue, 7 Sep 2021 16:55:56 +0530 Message-Id: <20210907112556.11848-3-kiran.k@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210907112556.11848-1-kiran.k@intel.com> References: <20210907112556.11848-1-kiran.k@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Add a test case for offload SCO connect with codec type set to mSBC --- Notes: * changes in v2: - No change tools/sco-tester.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tools/sco-tester.c b/tools/sco-tester.c index 67ea4769ef2b..b341fa49f792 100644 --- a/tools/sco-tester.c +++ b/tools/sco-tester.c @@ -675,6 +675,52 @@ end: close(sk); } +static void test_connect_offload_msbc(const void *test_data) +{ + struct test_data *data = tester_get_data(); + const struct sco_client_data *scodata = data->test_data; + int sk, err; + int len; + char buffer[255]; + struct bt_codecs *codecs; + + sk = create_sco_sock(data); + if (sk < 0) { + tester_test_failed(); + return; + } + + len = sizeof(buffer); + memset(buffer, 0, len); + + codecs = (void *)buffer; + + codecs->codecs[0].id = 0x05; + codecs->num_codecs = 1; + codecs->codecs[0].data_path_id = 1; + codecs->codecs[0].num_caps = 0x00; + + err = setsockopt(sk, SOL_BLUETOOTH, BT_CODEC, codecs, sizeof(buffer)); + if (err < 0) { + tester_warn("Can't set socket option : %s (%d)", + strerror(errno), errno); + tester_test_failed(); + goto end; + } + err = connect_sco_sock(data, sk); + + tester_warn("Connect returned %s (%d), expected %s (%d)", + strerror(-err), -err, + strerror(scodata->expect_err), scodata->expect_err); + + if (-err != scodata->expect_err) + tester_test_failed(); + else + tester_test_passed(); + +end: + close(sk); +} int main(int argc, char *argv[]) { tester_init(&argc, &argv); @@ -709,5 +755,8 @@ int main(int argc, char *argv[]) test_offload_sco("Basic SCO Set Socket Option - Offload - Success", NULL, setup_powered, test_codecs_setsockopt); + test_offload_sco("eSCO mSBC - Offload - Success", + &connect_success, setup_powered, test_connect_offload_msbc); + return tester_run(); }