From patchwork Wed Feb 19 00:36:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11390137 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 414FC924 for ; Wed, 19 Feb 2020 00:36:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 218122173E for ; Wed, 19 Feb 2020 00:36:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BtMuvT9c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726768AbgBSAgP (ORCPT ); Tue, 18 Feb 2020 19:36:15 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35574 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726488AbgBSAgP (ORCPT ); Tue, 18 Feb 2020 19:36:15 -0500 Received: by mail-pf1-f193.google.com with SMTP id i19so275466pfa.2 for ; Tue, 18 Feb 2020 16:36:15 -0800 (PST) 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=qLc+IK/svMCyoYP1PI6eZ6YUgNngu6dPFpoGFYUhDKE=; b=BtMuvT9cmd69kq+Zb7xXgC9oatbRb3D3CubZceYAT+cDnvNy14fMfnAKcjiJLLGY/8 yo5ikyqnfRvzkt+qDNiZsL/35umhm50zBiiVCh2Izxnhz1apFD+V7Ftte+uO3IW6Wqf+ dYBPGkpfBtJ4UAj23CH0wi/E/pWUOXXU0zkSg3Sm92trJU3RQe/guVYbz44kDCQ42Fwy K2AKjYo+ofJGuCg47KczVf66zW6u8gtvruYApAf9AM1DcvU+EHcp7mb7/HeevTWsI6dp XCmzCNepkGNYKgfvSdLoUFuzHSro0NkxRtZLkgZpUk+nkzJsUI5H+cz+YZPfe0l9k1a9 Jotg== 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=qLc+IK/svMCyoYP1PI6eZ6YUgNngu6dPFpoGFYUhDKE=; b=IWcD4PQ+XAnYSZIxabgsq+3kttr8v9FDYm+1oE5zZjzbWJmkolKsRTm/lJZxqMDnkk S5CbTQ99iIcMPfeHiXteHym7oTkG7Ll6tN4NRkH8QV18YK+ac5VAoAVsiWVF0WgFejnS kQbHizEC03+Z0825/3upEG6UGIZknMGVsybDEssf/VQLEI6BXJZd+wyjlgPgAL7GjKbd ADka3TG6SkoxjIweJlEFaEJNG5EyMaZb0LO+1d7VwArA81Qjs+aDTrfCOTkAccPQ/4eD PSxoY1dHfIsJTps4d0IqKNSCFy73USVY4ex158CMALUT05lIw5hUZzhiscVOELDy8jyx eRpA== X-Gm-Message-State: APjAAAU40pOVw1OCsYa/T8lHT2LAymtUWgXJyh1HEjIyMFXAtm5N1F7t 7yKYu/nx4mBXi59IcSamG/v92IzAcH0= X-Google-Smtp-Source: APXvYqziBbTrfcGMpXunx/1LwbCJ+DnJCh8zqsD3nqKsFdcCiylHUR1F0yvUZ+WupBih+oWjgKJNfw== X-Received: by 2002:a63:ea4b:: with SMTP id l11mr6743939pgk.93.1582072574325; Tue, 18 Feb 2020 16:36:14 -0800 (PST) Received: from localhost.localdomain ([192.102.209.42]) by smtp.gmail.com with ESMTPSA id v184sm180569pfc.67.2020.02.18.16.36.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 16:36:13 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/4] lib: Add definition to BT_PHY Date: Tue, 18 Feb 2020 16:36:09 -0800 Message-Id: <20200219003612.14599-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds the definition to BT_PHY socket options along with the possible bitfields for the return value. --- lib/bluetooth.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/bluetooth.h b/lib/bluetooth.h index 756dce164..d14217eac 100644 --- a/lib/bluetooth.h +++ b/lib/bluetooth.h @@ -123,6 +123,24 @@ struct bt_voice { #define BT_VOICE_TRANSPARENT 0x0003 #define BT_VOICE_CVSD_16BIT 0x0060 +#define BT_PHY 14 + +#define BT_PHY_BR_1M_1SLOT 0x00000001 +#define BT_PHY_BR_1M_3SLOT 0x00000002 +#define BT_PHY_BR_1M_5SLOT 0x00000004 +#define BT_PHY_EDR_2M_1SLOT 0x00000008 +#define BT_PHY_EDR_2M_3SLOT 0x00000010 +#define BT_PHY_EDR_2M_5SLOT 0x00000020 +#define BT_PHY_EDR_3M_1SLOT 0x00000040 +#define BT_PHY_EDR_3M_3SLOT 0x00000080 +#define BT_PHY_EDR_3M_5SLOT 0x00000100 +#define BT_PHY_LE_1M_TX 0x00000200 +#define BT_PHY_LE_1M_RX 0x00000400 +#define BT_PHY_LE_2M_TX 0x00000800 +#define BT_PHY_LE_2M_RX 0x00001000 +#define BT_PHY_LE_CODED_TX 0x00002000 +#define BT_PHY_LE_CODED_RX 0x00004000 + /* Connection and socket states */ enum { BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */ From patchwork Wed Feb 19 00:36:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11390139 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A18B6924 for ; Wed, 19 Feb 2020 00:36:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 83AD124654 for ; Wed, 19 Feb 2020 00:36:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XZC2iTZI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726823AbgBSAgU (ORCPT ); Tue, 18 Feb 2020 19:36:20 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36947 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbgBSAgU (ORCPT ); Tue, 18 Feb 2020 19:36:20 -0500 Received: by mail-pf1-f196.google.com with SMTP id p14so11557037pfn.4 for ; Tue, 18 Feb 2020 16:36:19 -0800 (PST) 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=FLPHeBxLvQ+N7tcXSpzXq1fSpXUzn67KKlPMXOk6+ss=; b=XZC2iTZIYtOT47i3A4Trba+tu8M5299HIMqoxiYhhqhfa7ImaORt71dr/sRcjX3T8Y Y4Zv9hECmVdd56DWfoWHO4XhI5JDkxH+R/4JJwLaXHQDybH6Rr+WL8x82TYI9EjM4YBD SKruJF5DDNjkxn/57YGeakJnN0dIQX1VFnJpfYJ1TenbvA7/EozfVNC3PwPP/xYxXthN WBIZT5/oneHQAEFyqEeD2yKQGGDadK65thpEnXXK8/BEhGTJPJ/XNSm/kToe2iSmB5v4 xlqgrGF/sfODONZ8K3+yj+Nu2yXMYxEOvttOQdcg7rmDd5+VpBy2XCOM4gy6XJ7dHz2V kAqg== 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=FLPHeBxLvQ+N7tcXSpzXq1fSpXUzn67KKlPMXOk6+ss=; b=VdKvPZv4ijyEFcILBsw567jFo6bKxOK/ol7zuW1s4mqpy1zwY7hUo90PfmABJKPotZ hLD/MTlVRdMTPsbynL+57tzalEKB8gVDDLf0JdQ2A5hBXq5W3UCod1QWz3ylBtlz5co1 lpzJSq4gv7Mb5ZVEsXKGxGQMDOFX1ueXmlRdd27Dnz/cALMi2URIAdiRL5FhfB265Q7F HSYn+O1V8iTmkp840me1aJkvDD5+dMQ7amrQfuLNN/arBDsXD/SryMbhots4/bF6PZk7 S8kVYGNqvsI+OUdM+7hZqHT1xykJ5oLNCfm9CU5cygvi65Ah2MfAOQR6xamCAMbqL/g9 SxAg== X-Gm-Message-State: APjAAAXAZz/rCiAPTf6fdwsh3jI8gGjRFqdQaG0greIxIVXPqKFloT4q WmsdhLGZO1RVenmvy+dY2JfbJMIg4U4= X-Google-Smtp-Source: APXvYqz8E/7b17bimeu1mR9QpzYqy7r9czDhTV+wd5qJOYz4+LO0w5hhZ/sUMuZthDrXGIFBE+mY1Q== X-Received: by 2002:aa7:99c6:: with SMTP id v6mr625129pfi.187.1582072579008; Tue, 18 Feb 2020 16:36:19 -0800 (PST) Received: from localhost.localdomain ([192.102.209.42]) by smtp.gmail.com with ESMTPSA id v184sm180569pfc.67.2020.02.18.16.36.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 16:36:14 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/4] btio: Add BT_IO_PHY option Date: Tue, 18 Feb 2020 16:36:10 -0800 Message-Id: <20200219003612.14599-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200219003612.14599-1-luiz.dentz@gmail.com> References: <20200219003612.14599-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds BT_IO_PHY option which can be used to read the underline packet types/PHY in use by the link layer. --- btio/btio.c | 37 ++++++++++++++++++++++++++++++++++++- btio/btio.h | 1 + 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/btio/btio.c b/btio/btio.c index af2276db9..db37b99da 100644 --- a/btio/btio.c +++ b/btio/btio.c @@ -881,6 +881,7 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err, case BT_IO_OPT_DEST_CHANNEL: case BT_IO_OPT_HANDLE: case BT_IO_OPT_CLASS: + case BT_IO_OPT_PHY: default: g_set_error(err, BT_IO_ERROR, EINVAL, "Unknown option %d", opt); @@ -968,6 +969,17 @@ static int get_priority(int sock, uint32_t *prio) return 0; } +static int get_phy(int sock, uint32_t *phy) +{ + socklen_t len; + + len = sizeof(*phy); + if (getsockopt(sock, SOL_BLUETOOTH, BT_PHY, phy, &len) < 0) + return -errno; + + return 0; +} + static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1, va_list args) { @@ -979,7 +991,7 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1, uint16_t handle = 0; socklen_t len; gboolean flushable = FALSE, have_dst = FALSE; - uint32_t priority; + uint32_t priority, phy; if (!get_src(sock, &src, sizeof(src), err)) return FALSE; @@ -1147,6 +1159,13 @@ parse_opts: } *(va_arg(args, uint32_t *)) = priority; break; + case BT_IO_OPT_PHY: + if (get_phy(sock, &phy) < 0) { + ERROR_FAILED(err, "get_phy", errno); + return FALSE; + } + *(va_arg(args, uint32_t *)) = phy; + break; case BT_IO_OPT_INVALID: case BT_IO_OPT_SOURCE_TYPE: case BT_IO_OPT_CHANNEL: @@ -1194,6 +1213,7 @@ static gboolean rfcomm_get(int sock, GError **err, BtIOOption opt1, socklen_t len; uint8_t dev_class[3]; uint16_t handle = 0; + uint32_t phy; if (!get_src(sock, &src, sizeof(src), err)) return FALSE; @@ -1287,6 +1307,13 @@ static gboolean rfcomm_get(int sock, GError **err, BtIOOption opt1, } memcpy(va_arg(args, uint8_t *), dev_class, 3); break; + case BT_IO_OPT_PHY: + if (get_phy(sock, &phy) < 0) { + ERROR_FAILED(err, "get_phy", errno); + return FALSE; + } + *(va_arg(args, uint32_t *)) = phy; + break; case BT_IO_OPT_SOURCE_TYPE: case BT_IO_OPT_DEST_TYPE: case BT_IO_OPT_KEY_SIZE: @@ -1338,6 +1365,7 @@ static gboolean sco_get(int sock, GError **err, BtIOOption opt1, va_list args) socklen_t len; uint8_t dev_class[3]; uint16_t handle = 0; + uint32_t phy; len = sizeof(sco_opt); memset(&sco_opt, 0, len); @@ -1385,6 +1413,13 @@ static gboolean sco_get(int sock, GError **err, BtIOOption opt1, va_list args) } memcpy(va_arg(args, uint8_t *), dev_class, 3); break; + case BT_IO_OPT_PHY: + if (get_phy(sock, &phy) < 0) { + ERROR_FAILED(err, "get_phy", errno); + return FALSE; + } + *(va_arg(args, uint32_t *)) = phy; + break; case BT_IO_OPT_SOURCE_TYPE: case BT_IO_OPT_DEST_TYPE: case BT_IO_OPT_DEFER_TIMEOUT: diff --git a/btio/btio.h b/btio/btio.h index 2dce9f0c1..41a017acb 100644 --- a/btio/btio.h +++ b/btio/btio.h @@ -56,6 +56,7 @@ typedef enum { BT_IO_OPT_FLUSHABLE, BT_IO_OPT_PRIORITY, BT_IO_OPT_VOICE, + BT_IO_OPT_PHY, } BtIOOption; typedef enum { From patchwork Wed Feb 19 00:36:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11390141 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1675D924 for ; Wed, 19 Feb 2020 00:36:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E3ADB24654 for ; Wed, 19 Feb 2020 00:36:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ix71fk6u" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726840AbgBSAgV (ORCPT ); Tue, 18 Feb 2020 19:36:21 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:42587 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbgBSAgV (ORCPT ); Tue, 18 Feb 2020 19:36:21 -0500 Received: by mail-pf1-f193.google.com with SMTP id 4so11547756pfz.9 for ; Tue, 18 Feb 2020 16:36:21 -0800 (PST) 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=ZjHaeiv7PtAZatXJnomiWi3pVfqwNeZCImTARyOK0Xo=; b=Ix71fk6ujxY8j1j++eOKOWS70ho2kZ1tB0+LcxFxUuY1dm/EVYDy39NqA8C+8s8C0p jPwCM4Nsp/cApMOgm7wN7SunR1bSofL6s9EV4y5zqwtH5/QKzc4+YVjlzGOMxxaA//F9 3YpkEUhBBI7a7mCeTb+sdQVYhr+5zrr3SBkuRj7hmaXM7jJ8qncmfDX13Feh2AB1rHLH LAXj6BKuzqQFSvkTN7nom74ADUOLwxv6r4j5+Aszqmyra9zMMyPh5PX8VG6JnQtqOw0R jIrKmSv+G0gK6Rb1lG/PS/laiUl9fXDLK6dIwEsG6UgFIMWZgq7CrJYzCoV7uosbU8Nk +ubQ== 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=ZjHaeiv7PtAZatXJnomiWi3pVfqwNeZCImTARyOK0Xo=; b=H7qaaIcfIkFzzXyi1bw6VM4f2Mm/yVlsGMrbOSdpYltqI03X6xzeZ0WUUex7HQjeVe oM7gBZ2y2RDyDpntZAlt3Vwsvo98CiPavTVchtHzGqedg5ma2wSV/wq8wOvzTe7zI8SO JwjzO0nZEmKoDg5c4GyFVyty/kYgDntADs1sWzrVBY89nOAie+mseRCrUp8VyypXkeZM PWOgdjlZZgu1jmTnrKCLnxB+pR2QmLExeISFEyAcS/CIe9N7nuXTjdgZBI4Lbhlnp0tW GTTSkmo5zspJvDT9ouWRr/mdcyULtn8wHdLr4AflXD+GRrhFMTHcQ9TQPiWxSiciklVy 1wSg== X-Gm-Message-State: APjAAAUYLjxDokkYINM7O2ZKBQGcNWsk9qEVhhLcayqKxn3wVZovKJX+ sEse2QGVuMgx4qezSoYeWXDh3tc/ngo= X-Google-Smtp-Source: APXvYqyqWnKcmtgTMjBzxa3Q91hOVW8u8vxdbx8IDZh5Yx957rPNGa5dLBPfKx0h05ep4XlANiDfMA== X-Received: by 2002:a62:870e:: with SMTP id i14mr6148337pfe.192.1582072580080; Tue, 18 Feb 2020 16:36:20 -0800 (PST) Received: from localhost.localdomain ([192.102.209.42]) by smtp.gmail.com with ESMTPSA id v184sm180569pfc.67.2020.02.18.16.36.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 16:36:19 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 3/4] l2test: Add support to BT_PHY Date: Tue, 18 Feb 2020 16:36:11 -0800 Message-Id: <20200219003612.14599-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200219003612.14599-1-luiz.dentz@gmail.com> References: <20200219003612.14599-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This makes l2test attempt to read BT_PHY socket option and print out the supported packet types/PHY: l2test[7282]: Connected to XX:XX:XX:XX:XX:XX (bredr, psm 4113, dcid 64) l2test[7282]: Local device XX:XX:XX:XX:XX:XX (bredr, psm 4113, scid 64) l2test[7282]: Options [imtu 672, omtu 672, flush_to 65535, mode 0, handle 256, class 0x000000, priority 0, rcvbuf 212992] l2test[7282]: Supported PHY: 0x000001ff BR1M1SLOT BR1M3SLOT BR1M5SLOT EDR2M1SLOT EDR2M3SLOT EDR2M5SLOT EDR3M1SLOT EDR3M3SLOT EDR3M5SLOT --- tools/l2test.c | 209 +++++++++++++++++++++++-------------------------- 1 file changed, 96 insertions(+), 113 deletions(-) diff --git a/tools/l2test.c b/tools/l2test.c index e787c2ce2..8c6e08646 100644 --- a/tools/l2test.c +++ b/tools/l2test.c @@ -49,6 +49,7 @@ #include "lib/l2cap.h" #include "src/shared/util.h" +#include "monitor/display.h" #define NIBBLE_TO_ASCII(c) ((c) < 0x0a ? (c) + 0x30 : (c) + 0x57) @@ -306,14 +307,105 @@ static int setopts(int sk, struct l2cap_options *opts) sizeof(opts->imtu)); } +bool use_color(void) +{ + return false; +} + +static const struct bitfield_data phy_table[] = { + { 0, "BR1M1SLOT" }, + { 1, "BR1M3SLOT" }, + { 2, "BR1M5SLOT" }, + { 3, "EDR2M1SLOT" }, + { 4, "EDR2M3SLOT" }, + { 5, "EDR2M5SLOT" }, + { 6, "EDR3M1SLOT" }, + { 7, "EDR3M3SLOT" }, + { 8, "EDR3M5SLOT" }, + { 9, "LE1MTX" }, + { 10, "LE1MRX" }, + { 11, "LE2MTX" }, + { 12, "LE2MRX" }, + { 13, "LECODEDTX" }, + { 14, "LECODEDRX" }, + {}, +}; + +static int print_info(int sk, struct l2cap_options *opts) +{ + struct sockaddr_l2 addr; + socklen_t optlen; + struct l2cap_conninfo conn; + int prio, phy; + char ba[18]; + + /* Get connection information */ + memset(&conn, 0, sizeof(conn)); + optlen = sizeof(conn); + + if (getsockopt(sk, SOL_L2CAP, L2CAP_CONNINFO, &conn, &optlen) < 0) { + syslog(LOG_ERR, "Can't get L2CAP connection information: " + "%s (%d)", strerror(errno), errno); + return -errno; + } + + if (getsockopt(sk, SOL_SOCKET, SO_PRIORITY, &prio, &optlen) < 0) { + syslog(LOG_ERR, "Can't get socket priority: %s (%d)", + strerror(errno), errno); + return -errno; + } + + /* Check for remote address */ + memset(&addr, 0, sizeof(addr)); + optlen = sizeof(addr); + + if (getpeername(sk, (struct sockaddr *) &addr, &optlen) < 0) { + syslog(LOG_ERR, "Can't get socket name: %s (%d)", + strerror(errno), errno); + return -errno; + } + + ba2str(&addr.l2_bdaddr, ba); + syslog(LOG_INFO, "Connected to %s (%s, psm %d, dcid %d)", ba, + get_lookup_str(bdaddr_types, addr.l2_bdaddr_type), + addr.l2_psm, addr.l2_cid); + + /* Check for socket address */ + memset(&addr, 0, sizeof(addr)); + optlen = sizeof(addr); + + if (getsockname(sk, (struct sockaddr *) &addr, &optlen) < 0) { + syslog(LOG_ERR, "Can't get socket name: %s (%d)", + strerror(errno), errno); + return -errno; + } + + ba2str(&addr.l2_bdaddr, ba); + syslog(LOG_INFO, "Local device %s (%s, psm %d, scid %d)", ba, + get_lookup_str(bdaddr_types, addr.l2_bdaddr_type), + addr.l2_psm, addr.l2_cid); + + syslog(LOG_INFO, "Options [imtu %d, omtu %d, flush_to %d, mode %d, " + "handle %d, class 0x%02x%02x%02x, priority %d, rcvbuf %d]", + opts->imtu, opts->omtu, opts->flush_to, opts->mode, + conn.hci_handle, conn.dev_class[2], conn.dev_class[1], + conn.dev_class[0], prio, rcvbuf); + + + if (!getsockopt(sk, SOL_BLUETOOTH, BT_PHY, &phy, &optlen)) { + syslog(LOG_INFO, "Supported PHY: 0x%08x", phy); + print_bitfield(2, phy, phy_table); + } + + return 0; +} + static int do_connect(char *svr) { struct sockaddr_l2 addr; struct l2cap_options opts; - struct l2cap_conninfo conn; socklen_t optlen; int sk, opt; - char ba[18]; /* Create socket */ sk = socket(PF_BLUETOOTH, socktype, BTPROTO_L2CAP); @@ -451,64 +543,8 @@ static int do_connect(char *svr) goto error; } - /* Get connection information */ - memset(&conn, 0, sizeof(conn)); - optlen = sizeof(conn); - - if (getsockopt(sk, SOL_L2CAP, L2CAP_CONNINFO, &conn, &optlen) < 0) { - syslog(LOG_ERR, "Can't get L2CAP connection information: %s (%d)", - strerror(errno), errno); - goto error; - } - - if (priority > 0 && setsockopt(sk, SOL_SOCKET, SO_PRIORITY, &priority, - sizeof(priority)) < 0) { - syslog(LOG_ERR, "Can't set socket priority: %s (%d)", - strerror(errno), errno); - goto error; - } - - if (getsockopt(sk, SOL_SOCKET, SO_PRIORITY, &opt, &optlen) < 0) { - syslog(LOG_ERR, "Can't get socket priority: %s (%d)", - strerror(errno), errno); - goto error; - } - - /* Check for remote address */ - memset(&addr, 0, sizeof(addr)); - optlen = sizeof(addr); - - if (getpeername(sk, (struct sockaddr *) &addr, &optlen) < 0) { - syslog(LOG_ERR, "Can't get socket name: %s (%d)", - strerror(errno), errno); - goto error; - } - - ba2str(&addr.l2_bdaddr, ba); - syslog(LOG_INFO, "Connected to %s (%s, psm %d, scid %d)", ba, - get_lookup_str(bdaddr_types, addr.l2_bdaddr_type), - addr.l2_psm, addr.l2_cid); - - /* Check for socket address */ - memset(&addr, 0, sizeof(addr)); - optlen = sizeof(addr); - - if (getsockname(sk, (struct sockaddr *) &addr, &optlen) < 0) { - syslog(LOG_ERR, "Can't get socket name: %s (%d)", - strerror(errno), errno); + if (print_info(sk, &opts) < 0) goto error; - } - - ba2str(&addr.l2_bdaddr, ba); - syslog(LOG_INFO, "Local device %s (%s, psm %d, scid %d)", ba, - get_lookup_str(bdaddr_types, addr.l2_bdaddr_type), - addr.l2_psm, addr.l2_cid); - - syslog(LOG_INFO, "Options [imtu %d, omtu %d, flush_to %d, " - "mode %d, handle %d, class 0x%02x%02x%02x, priority %d, rcvbuf %d]", - opts.imtu, opts.omtu, opts.flush_to, opts.mode, conn.hci_handle, - conn.dev_class[2], conn.dev_class[1], conn.dev_class[0], opt, - rcvbuf); omtu = (opts.omtu > buffer_size) ? buffer_size : opts.omtu; imtu = (opts.imtu > buffer_size) ? buffer_size : opts.imtu; @@ -524,10 +560,8 @@ static void do_listen(void (*handler)(int sk)) { struct sockaddr_l2 addr; struct l2cap_options opts; - struct l2cap_conninfo conn; socklen_t optlen; int sk, nsk, opt; - char ba[18]; /* Create socket */ sk = socket(PF_BLUETOOTH, socktype, BTPROTO_L2CAP); @@ -677,62 +711,11 @@ static void do_listen(void (*handler)(int sk)) } } - /* Get connection information */ - memset(&conn, 0, sizeof(conn)); - optlen = sizeof(conn); - - if (getsockopt(nsk, SOL_L2CAP, L2CAP_CONNINFO, &conn, &optlen) < 0) { - syslog(LOG_ERR, "Can't get L2CAP connection information: %s (%d)", - strerror(errno), errno); - if (!defer_setup) { - close(nsk); - goto error; - } - } - - if (priority > 0 && setsockopt(nsk, SOL_SOCKET, SO_PRIORITY, - &priority, sizeof(priority)) < 0) { - syslog(LOG_ERR, "Can't set socket priority: %s (%d)", - strerror(errno), errno); + if (print_info(nsk, &opts) < 0) { close(nsk); goto error; } - optlen = sizeof(priority); - if (getsockopt(nsk, SOL_SOCKET, SO_PRIORITY, &opt, &optlen) < 0) { - syslog(LOG_ERR, "Can't get socket priority: %s (%d)", - strerror(errno), errno); - goto error; - } - - ba2str(&addr.l2_bdaddr, ba); - syslog(LOG_INFO, "Connect from %s (%s, psm %d, dcid %d)", ba, - get_lookup_str(bdaddr_types, addr.l2_bdaddr_type), - addr.l2_psm, addr.l2_cid); - - /* Check for socket address */ - memset(&addr, 0, sizeof(addr)); - optlen = sizeof(addr); - - if (getsockname(nsk, (struct sockaddr *) &addr, &optlen) < 0) { - syslog(LOG_ERR, "Can't get socket name: %s (%d)", - strerror(errno), errno); - goto error; - } - - ba2str(&addr.l2_bdaddr, ba); - syslog(LOG_INFO, "Local device %s (%s, psm %d, scid %d)", ba, - get_lookup_str(bdaddr_types, addr.l2_bdaddr_type), - addr.l2_psm, addr.l2_cid); - - syslog(LOG_INFO, "Options [imtu %d, omtu %d, " - "flush_to %d, mode %d, handle %d, " - "class 0x%02x%02x%02x, priority %d, rcvbuf %d]", - opts.imtu, opts.omtu, opts.flush_to, - opts.mode, conn.hci_handle, conn.dev_class[2], - conn.dev_class[1], conn.dev_class[0], opt, - rcvbuf); - omtu = (opts.omtu > buffer_size) ? buffer_size : opts.omtu; imtu = (opts.imtu > buffer_size) ? buffer_size : opts.imtu; From patchwork Wed Feb 19 00:36:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11390143 X-Patchwork-Delegate: luiz.dentz@gmail.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 206AC139A for ; Wed, 19 Feb 2020 00:36:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 00A7C208E4 for ; Wed, 19 Feb 2020 00:36:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dpqfeI8s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726641AbgBSAgW (ORCPT ); Tue, 18 Feb 2020 19:36:22 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:33439 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbgBSAgW (ORCPT ); Tue, 18 Feb 2020 19:36:22 -0500 Received: by mail-pf1-f193.google.com with SMTP id n7so11565974pfn.0 for ; Tue, 18 Feb 2020 16:36:21 -0800 (PST) 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=KfHgx4KA2lQ2RntLtxbWBLc3vqu7hBUeejmhR/t+iIA=; b=dpqfeI8sLIn7iMd6t0Co9NopSBbBfao7NNJjgi9DWyYDxxf9ihRdQtIfjA+beKc+FD zn5BPqaAdRMllOKXpv+ToKvlFzifzbxHd/HdyOKspLx1lFb07Glva2rtERNXLwgxBg8J 4Xj9TMsrtGVXTeFempitpgJOqIIdt5CBi577IA6p+NpIBMy5UemOmt6ATqTHjEIEi9yf 9vvK4vizaNIX3xhwxWuRYXCQ2X0bHhPgfsG8nGC7txgZoyNQ9ra4obB/p08DI7GiOetR Kn6jpqLTx4CGe2yjVQ028TzbOFIMVPXea/Mj+hPtpkyI0Ji5CS8N2fSMoBE1cMnRtlpA F15w== 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=KfHgx4KA2lQ2RntLtxbWBLc3vqu7hBUeejmhR/t+iIA=; b=Qxkor7EzB6oFz/xcxxLMa0+b6UJ7Qo4XCcjGesJ0ExA9DqMuKlsQYsEePVQ8fo1W7J dUSC5D+SYNyaeUG6S8vRf6aUgsXZ/Eg/CzAfkS922AOLj+iYNcMDImIykZtXs4nQvA5D Q0DlXJfuYlbbyHJvTskNOAeJsFqME/cjlnBSwiDH2iZ1tRKsO8jiSBSE9V+rWXJUcRno wvIK3z9GvTPnwajofUAHz+sP2VOGfE37QDrf81MSwCnIEMFjE1rmJKpnzrxJy9+QWiPW j92svjPj/ZkoG+cFkS+bAUbXkO1PQiMjnYd3gH8VvAKpbxeoAgHfyQLt/LAVKNQwSctS u76Q== X-Gm-Message-State: APjAAAVWyf8CWTXD2BC6R+bn3IrTxxmwJp+3DYczL3MBwl9KUFt7Xr6O XQnmYxMboGf6XBAuW65tPemD6I3+LjI= X-Google-Smtp-Source: APXvYqz4tAUyKqIwN2P9p3ls+ecQLfNvXyfzTbfTQbpkOS/PNIgR/4k5AK+tymvtUBaFRgmUxyRTMA== X-Received: by 2002:a05:6a00:5b:: with SMTP id i27mr24511910pfk.112.1582072580936; Tue, 18 Feb 2020 16:36:20 -0800 (PST) Received: from localhost.localdomain ([192.102.209.42]) by smtp.gmail.com with ESMTPSA id v184sm180569pfc.67.2020.02.18.16.36.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 16:36:20 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 4/4] avdtp: Enable MTU auto tunning Date: Tue, 18 Feb 2020 16:36:12 -0800 Message-Id: <20200219003612.14599-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200219003612.14599-1-luiz.dentz@gmail.com> References: <20200219003612.14599-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This uses BT_PHY to check if kernel is able to do MTU auto tunning which is enabled by forcing the input MTU to 0. --- profiles/audio/avdtp.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c index f42f21bbb..0e075f9ff 100644 --- a/profiles/audio/avdtp.c +++ b/profiles/audio/avdtp.c @@ -401,6 +401,7 @@ struct avdtp { struct avdtp_stream *pending_open; + uint32_t phy; uint16_t imtu; uint16_t omtu; @@ -2291,6 +2292,9 @@ static void avdtp_connect_cb(GIOChannel *chan, GError *err, gpointer user_data) if (!session->io) session->io = g_io_channel_ref(chan); + /* Check if kernel supports reading packet types */ + bt_io_get(chan, NULL, BT_IO_OPT_PHY, &session->phy, BT_IO_OPT_INVALID); + bt_io_get(chan, &err, BT_IO_OPT_OMTU, &session->omtu, BT_IO_OPT_IMTU, &session->imtu, @@ -2399,14 +2403,26 @@ static GIOChannel *l2cap_connect(struct avdtp *session) src = btd_adapter_get_address(device_get_adapter(session->device)); - io = bt_io_connect(avdtp_connect_cb, session, - NULL, &err, - BT_IO_OPT_SOURCE_BDADDR, src, - BT_IO_OPT_DEST_BDADDR, - device_get_address(session->device), - BT_IO_OPT_PSM, AVDTP_PSM, - BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM, - BT_IO_OPT_INVALID); + if (session->phy) + io = bt_io_connect(avdtp_connect_cb, session, + NULL, &err, + BT_IO_OPT_SOURCE_BDADDR, src, + BT_IO_OPT_DEST_BDADDR, + device_get_address(session->device), + BT_IO_OPT_PSM, AVDTP_PSM, + BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM, + /* Set Input MTU to 0 to auto-tune */ + BT_IO_OPT_IMTU, 0, + BT_IO_OPT_INVALID); + else + io = bt_io_connect(avdtp_connect_cb, session, + NULL, &err, + BT_IO_OPT_SOURCE_BDADDR, src, + BT_IO_OPT_DEST_BDADDR, + device_get_address(session->device), + BT_IO_OPT_PSM, AVDTP_PSM, + BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM, + BT_IO_OPT_INVALID); if (!io) { error("%s", err->message); g_error_free(err);