From patchwork Wed Mar 18 21:51:19 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: 11446133 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 B71FC17E6 for ; Wed, 18 Mar 2020 21:51:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A96D20773 for ; Wed, 18 Mar 2020 21:51:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tKu6ResE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727070AbgCRVv2 (ORCPT ); Wed, 18 Mar 2020 17:51:28 -0400 Received: from mail-pf1-f182.google.com ([209.85.210.182]:42923 "EHLO mail-pf1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726776AbgCRVv2 (ORCPT ); Wed, 18 Mar 2020 17:51:28 -0400 Received: by mail-pf1-f182.google.com with SMTP id x2so194969pfn.9 for ; Wed, 18 Mar 2020 14:51:27 -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=MPfZ6Ur90/9wCSGmoi9z3v0hkVuFY/fVXq73vDSGlUE=; b=tKu6ResEkrxWegWROAp/ZLoohDnRUUNx3g2fdEXjRfwTlr9TTe9hQkYJKJW6F+Ygdh GVtZyIHHKgTHasL26gXlRmNeG/zadwwJPiuIuk5jjgYf6E0E2wSbfsImodxXwW/wXS7+ CtWhx27+oRTBGKLjJwCw2VNHI600NBJxeu7wlRsC/Avqi9fN15SlfQqrzl++PQJWxwkt ZO5/jqmX1/60FmU1W3aU9S8jO5PqT7shzzb2Dx61cpv0JWm4x3O9X2JnC5/Rpon3nP5E LSIA9S1yM8uAamexU9hAe+z0YEzSLJOYIjIMDxUA+Em3pFooEDEORDPxgrOUbxng+wfY qdvA== 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=MPfZ6Ur90/9wCSGmoi9z3v0hkVuFY/fVXq73vDSGlUE=; b=ZN388xwUP4/XmPyKKQqL15VhSfynq6Mp/jECK2xfoxvI7zQ0zKb6191Ee2yt5t85cl HM77XswRhRHPisFMOJAxRrqAEPxx/9cUxPfO+tR3/4aPYP4fCr7f++zPaUji6C74MtsR wkZAjtXmVdIg586ZJfZU+pFle0fQHi3f/2UdRk5CA3eT1LVIplnP0iT3jpMsGftPsJGA YrVQ8dFv/2RbF0RkfomHgFYgbrjGj3RozrKWp+0ylanrHXFYqNI91GsiK1JR6QPjDmmp moCxhH3gtos7+QuylZdht4Ycd53Dv0aZplhsaqP+nxjxZ2h+s/OV9Zok4Q6Sy0+Aqx6S yiSw== X-Gm-Message-State: ANhLgQ0XmHDvhfCbZojdudNRxPXPaRX01MdhhtUE5Rk0OzCX1KCIN6Do gzhFN85OJwg3D7loLm/LlTFPo1Gs X-Google-Smtp-Source: ADFU+vtkYY/DwSP3hwTZLiuzC5Nq8nHkBolU2YfyCdL63s5XKP0DEsGf4Ld0SMfx6ozuEVEv+wS6eg== X-Received: by 2002:a62:15d3:: with SMTP id 202mr386765pfv.231.1584568286123; Wed, 18 Mar 2020 14:51:26 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id r13sm83709pgf.1.2020.03.18.14.51.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 14:51:25 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v3 1/6] lib: Add definitions for Enhanced Credits Based Mode Date: Wed, 18 Mar 2020 14:51:19 -0700 Message-Id: <20200318215124.21880-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 --- lib/bluetooth.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/bluetooth.h b/lib/bluetooth.h index d14217eac..121010c63 100644 --- a/lib/bluetooth.h +++ b/lib/bluetooth.h @@ -141,6 +141,15 @@ struct bt_voice { #define BT_PHY_LE_CODED_TX 0x00002000 #define BT_PHY_LE_CODED_RX 0x00004000 +#define BT_MODE 15 + +#define BT_MODE_BASIC 0x00 +#define BT_MODE_RETRANS 0x01 +#define BT_MODE_FLOWCTL 0x02 +#define BT_MODE_ERTM 0x03 +#define BT_MODE_STREAMING 0x04 +#define BT_MODE_EXT_FLOWCTL 0x05 + /* Connection and socket states */ enum { BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */ From patchwork Wed Mar 18 21:51:20 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: 11446135 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 55D4D14B4 for ; Wed, 18 Mar 2020 21:51:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 35E1120773 for ; Wed, 18 Mar 2020 21:51:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eJ8drzsn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726934AbgCRVv2 (ORCPT ); Wed, 18 Mar 2020 17:51:28 -0400 Received: from mail-pj1-f49.google.com ([209.85.216.49]:37667 "EHLO mail-pj1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726776AbgCRVv2 (ORCPT ); Wed, 18 Mar 2020 17:51:28 -0400 Received: by mail-pj1-f49.google.com with SMTP id ca13so27044pjb.2 for ; Wed, 18 Mar 2020 14:51:28 -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=pXnDcxxE1zmo2t5aTdjtgw5YWupzZKBA0Z5OuAGW7ro=; b=eJ8drzsnPo1ZKqbUCon899SI1WnJuNbUPTs3TRuGlliuI12Y9rrmkJmHyrMdKXNUPr v/1/H48qFDrI1ekvPDQrLw+Q9Du7GSIwNNNIDw85v9tD9kU8/ESiFmzPYPzfVb1pfdG7 +pjDP9LJVQpr4Xe8TQUPxuoWj9pakS1rDloOyQcNJC7aeKis1kNYcSM7ZECsdnA6Zx1c nDAEGwYT4lHuzabo+bB69UZeJxFEBwRe3+RP6NdW2bXgoEF7L57ATarDc7Yzjin8rNuf xSS+OqBtkaYmS60+cSP+n87CiYPUcb+Tz1XKc2/oHGwL63k9bxr3JwCSUMc1B/Z/mC1C o0Fg== 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=pXnDcxxE1zmo2t5aTdjtgw5YWupzZKBA0Z5OuAGW7ro=; b=SJn01QS0DfLj9i227S7EMTSbduIJi+sc6CHhy2Q75hwgK3OgaeSotPQWwPzn2EEb7t HfXm1kzi46bj5n+v8lSk45NtP5n+P/dE9wNknH/o4B2d0GGHmSrqQ/2IsAvREfC05A4Q K585YUS52/A4LHlNOrCxyI+BOykJkVtlz+d/HtA7RNtu3nccBgWk0LlOTHHLA8BcWYRe m5ej9ntM7JTO0Xx4Gaw7egV5UE4H9MPIgqQiFVOE3mwRSKh7Wrru6J4Ybl0Spv+eKfix 2uKo/xhd9SsEzCf/jISBFriV5hh6WFSqqbzKQVBnb6A2IUzQ+/mCQBzDNO+F52HuKJg0 pJUw== X-Gm-Message-State: ANhLgQ1/ZxY5q/JquUAtBr7u4qy+fTJDxONcvTFZnqtlZvDsr0mPJXX5 2myrHANFgXC7dpdOKVvPwSNmURAw X-Google-Smtp-Source: ADFU+vs6u0DHsPNs1noXNqsUQu2KAGvIuKP+QgcQBvfZRqE+PQxgw/DIOvRX1l2lqHtfTbgXkF6G5Q== X-Received: by 2002:a17:90b:1997:: with SMTP id mv23mr299963pjb.84.1584568287101; Wed, 18 Mar 2020 14:51:27 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id r13sm83709pgf.1.2020.03.18.14.51.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 14:51:26 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v3 2/6] btio: Add mode to for Enhanced Credit Mode Date: Wed, 18 Mar 2020 14:51:20 -0700 Message-Id: <20200318215124.21880-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200318215124.21880-1-luiz.dentz@gmail.com> References: <20200318215124.21880-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_MODE_EXT_FLOWCTL which directly maps to BT_MODE_EXT_FLOWCTL. --- btio/btio.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++------ btio/btio.h | 3 ++- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/btio/btio.c b/btio/btio.c index db37b99da..e7b4db16b 100644 --- a/btio/btio.c +++ b/btio/btio.c @@ -630,18 +630,34 @@ static gboolean set_le_imtu(int sock, uint16_t imtu, GError **err) return TRUE; } +static gboolean set_le_mode(int sock, uint8_t mode, GError **err) +{ + if (setsockopt(sock, SOL_BLUETOOTH, BT_MODE, &mode, + sizeof(mode)) < 0) { + ERROR_FAILED(err, "setsockopt(BT_MODE)", errno); + return FALSE; + } + + return TRUE; +} + static gboolean l2cap_set(int sock, uint8_t src_type, int sec_level, uint16_t imtu, uint16_t omtu, uint8_t mode, int master, int flushable, uint32_t priority, GError **err) { if (imtu || omtu || mode) { - gboolean ret; + gboolean ret = FALSE; if (src_type == BDADDR_BREDR) ret = set_l2opts(sock, imtu, omtu, mode, err); - else - ret = set_le_imtu(sock, imtu, err); + else { + if (imtu) + ret = set_le_imtu(sock, imtu, err); + + if (ret && mode) + ret = set_le_mode(sock, mode, err); + } if (!ret) return ret; @@ -980,6 +996,30 @@ static int get_phy(int sock, uint32_t *phy) return 0; } +static int get_le_imtu(int sock, uint16_t *mtu) +{ + socklen_t len; + + len = sizeof(*mtu); + + if (getsockopt(sock, SOL_BLUETOOTH, BT_RCVMTU, mtu, &len) < 0) + return -errno; + + return 0; +} + +static int get_le_mode(int sock, uint8_t *mode) +{ + socklen_t len; + + len = sizeof(*mode); + + if (getsockopt(sock, SOL_BLUETOOTH, BT_MODE, mode, &len) < 0) + return -errno; + + return 0; +} + static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1, va_list args) { @@ -999,10 +1039,11 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1, memset(&l2o, 0, sizeof(l2o)); if (src.l2_bdaddr_type != BDADDR_BREDR) { - len = sizeof(l2o.imtu); - if (getsockopt(sock, SOL_BLUETOOTH, BT_RCVMTU, - &l2o.imtu, &len) == 0) + if (get_le_imtu(sock, &l2o.imtu) == 0) { + /* Older kernels may not support BT_MODE */ + get_le_mode(sock, &l2o.mode); goto parse_opts; + } /* Non-LE CoC enabled kernels will return one of these * in which case we need to fall back to L2CAP_OPTIONS. @@ -1644,6 +1685,12 @@ GIOChannel *bt_io_connect(BtIOConnect connect, gpointer user_data, sock = g_io_channel_unix_get_fd(io); + /* Use DEFER_SETUP when connecting using Ext-Flowctl */ + if (opts.mode == BT_IO_MODE_EXT_FLOWCTL && opts.defer) { + setsockopt(sock, SOL_BLUETOOTH, BT_DEFER_SETUP, &opts.defer, + sizeof(opts.defer)); + } + switch (opts.type) { case BT_IO_L2CAP: err = l2cap_connect(sock, &opts.dst, opts.dst_type, diff --git a/btio/btio.h b/btio/btio.h index 41a017acb..461c43eb0 100644 --- a/btio/btio.h +++ b/btio/btio.h @@ -71,7 +71,8 @@ typedef enum { BT_IO_MODE_RETRANS, BT_IO_MODE_FLOWCTL, BT_IO_MODE_ERTM, - BT_IO_MODE_STREAMING + BT_IO_MODE_STREAMING, + BT_IO_MODE_EXT_FLOWCTL } BtIOMode; typedef void (*BtIOConfirm)(GIOChannel *io, gpointer user_data); From patchwork Wed Mar 18 21:51:21 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: 11446137 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 743B717E6 for ; Wed, 18 Mar 2020 21:51:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 537A020772 for ; Wed, 18 Mar 2020 21:51:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zt8SA79V" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727113AbgCRVva (ORCPT ); Wed, 18 Mar 2020 17:51:30 -0400 Received: from mail-pj1-f65.google.com ([209.85.216.65]:50426 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726930AbgCRVv3 (ORCPT ); Wed, 18 Mar 2020 17:51:29 -0400 Received: by mail-pj1-f65.google.com with SMTP id v13so32083pjb.0 for ; Wed, 18 Mar 2020 14:51:28 -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=IBv8hQNbmpTa0AIoocboT1khiHc/5SGjGyL7viltjm4=; b=Zt8SA79VXMfVqmZWlveNoE4Of4buWhfNqcJKJREajFthUEnZlIWiOzPSNs3HnfCl5F jslFsIQAiF5T0fiRT6jxNWy3wNs9Q1GncYj4MWIBoZjA0K/+cnvUevj/8MSJggMvPXXV RrKU2sT0nWy4c/H3Cn3CItwG4EqbfgeGeIh8E5jmie1Giveo+PAxVSFefDtjNj098aZT d3v6TDezKVXkUxOSFc+hdWCY57MrGhKWO1gUnvqsCbaP7G/H92w7YUeWABzRjcjtsJYv hVQYili67Kc6+lM7y5D+6xfZCJLtl/RIX9w7B0J9GdtDvJJ480mLjfBuyvkMIvHJBPd+ J+Gw== 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=IBv8hQNbmpTa0AIoocboT1khiHc/5SGjGyL7viltjm4=; b=r/ymk1AyyIWem/Nj7eCEf8Knk0iC7+Rz1BWkyjSpqV+GciihhOg4zsOXrClzXBxnSD xz7El22mlMHt22ZZSas00VvJagi3GP8K3L7PFqTk/0eN8JwBzUGAp8/NrGnMNTKnu2lO gO/sohkPUmGvPD4LedhhuD/uRELsAs0VQzMLO9o1ztYIp/zBLcp2ENLBBrMZZMZUU2co zO2gDFK5r5aBh611gGGRUwG5kSCTjjz25daXpFzhvrNLQ2fl4XRM4RpesDCGr1h90y60 OUBnzYPSs2qGTTr0xcFlwPrTFRhVAmcGL5s22MNWnywRhceKmOq84Jl/eT0saazpSM9C j9LQ== X-Gm-Message-State: ANhLgQ02/QCypSa3pQngBk+gqrMXB4n2s6w4pRLcF/jP1OYjbc5eR+UR NtEDzSGo2N6K8yW/UQsp8pg4mSfd X-Google-Smtp-Source: ADFU+vsgMQ4/V8917NndWUnDqZeR9Ownb/Tn8+ng5m57YPJO9wZG5z2EzFQ7SA/5fJsOSOUwww/FOA== X-Received: by 2002:a17:90a:37c6:: with SMTP id v64mr313925pjb.20.1584568287933; Wed, 18 Mar 2020 14:51:27 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id r13sm83709pgf.1.2020.03.18.14.51.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 14:51:27 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v3 3/6] l2test: Add support for BT_MODE_EXT_FLOWCTL Date: Wed, 18 Mar 2020 14:51:21 -0700 Message-Id: <20200318215124.21880-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200318215124.21880-1-luiz.dentz@gmail.com> References: <20200318215124.21880-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 enables using l2test to connect or listen with BT_MODE_EXT_FLOWCTL. --- tools/l2test.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/l2test.c b/tools/l2test.c index 8c6e08646..0d846ed93 100644 --- a/tools/l2test.c +++ b/tools/l2test.c @@ -143,13 +143,14 @@ struct lookup_table { }; static struct lookup_table l2cap_modes[] = { - { "basic", L2CAP_MODE_BASIC }, + { "basic", BT_MODE_BASIC }, /* Not implemented - { "flowctl", L2CAP_MODE_FLOWCTL }, - { "retrans", L2CAP_MODE_RETRANS }, + { "flowctl", BT_MODE_FLOWCTL }, + { "retrans", BT_MODE_RETRANS }, */ - { "ertm", L2CAP_MODE_ERTM }, - { "streaming", L2CAP_MODE_STREAMING }, + { "ertm", BT_MODE_ERTM }, + { "streaming", BT_MODE_STREAMING }, + { "ext-flowctl",BT_MODE_EXT_FLOWCTL }, { 0 } }; @@ -283,7 +284,7 @@ static int getopts(int sk, struct l2cap_options *opts, bool connected) memset(opts, 0, sizeof(*opts)); - if (bdaddr_type == BDADDR_BREDR) { + if (bdaddr_type == BDADDR_BREDR || rfcmode) { optlen = sizeof(*opts); return getsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, opts, &optlen); } @@ -303,6 +304,13 @@ static int setopts(int sk, struct l2cap_options *opts) return setsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, opts, sizeof(*opts)); + if (opts->mode) { + if (setsockopt(sk, SOL_BLUETOOTH, BT_MODE, &opts->mode, + sizeof(opts->mode)) < 0) { + return -errno; + } + } + return setsockopt(sk, SOL_BLUETOOTH, BT_RCVMTU, &opts->imtu, sizeof(opts->imtu)); } From patchwork Wed Mar 18 21:51:22 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: 11446139 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 47BC717E6 for ; Wed, 18 Mar 2020 21:51:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2870120774 for ; Wed, 18 Mar 2020 21:51:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RKYwhlLz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727118AbgCRVva (ORCPT ); Wed, 18 Mar 2020 17:51:30 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:37958 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727116AbgCRVva (ORCPT ); Wed, 18 Mar 2020 17:51:30 -0400 Received: by mail-pj1-f68.google.com with SMTP id m15so25414pje.3 for ; Wed, 18 Mar 2020 14:51:30 -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=redNRYVw53Y2nCzF8YK8qJRWg+E/jmn8Yib4eOsg8Yw=; b=RKYwhlLzzuZtzK0RO3BuybZ1eloBsvTJSCicNijx1SEDkpSU7/2yxxbqfI6mWPquwJ D8aGPKLnlCkN39LqYIeneO/UmumqFhtNNBgAgOKyCcDwjTY13R0vJnu5iVT4p7rCX78Y Gp8Yd8hot2HnhtKDsTrFHNuGkbOcvl3sx8iSyJbfIqfmaQNuhI561OiNVHqihTJWNhRu zahWH/9S/s7bBVCbKBMi6hL+EbRm5yUSeV1kQ3fhTxuwzFuQy9RR9sQmoxo0A2lXKLHL d961VwLExn6TpkYaFNrRgiDeI30apIJn56+T8Mvxw8vHqLy/ipx3nrd/Q482PgW+hvuW OUtg== 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=redNRYVw53Y2nCzF8YK8qJRWg+E/jmn8Yib4eOsg8Yw=; b=c0owKnHe08MKqel/reVzqYJHy07K/c3EBpn0eL2gkT7Na2M5CuUnf++HAJlY1Pv6Uz NFpdzvEHZRf2Z/inj1Md+ERiVkdpqf/fAnu+iPhJ6BY4ZDA0RZv2aqgmo4w2a9g3RqLj /6q6q7TIsPDpeNt1EVIEQtjZm+jL1qK7bxpUutmRRAbWsoA9z4GxDcaS0GRAwZKJcCzx WpvBK59s8fX+UPFyXxCAg+8OIR7Hh7GoohliGlZVuxGwukEapisuiaKCM5pzCsj+oxRH hNuWSFquc7LmXCLBtya7XKZZPAMXMC+ovZP4cS6C2TdYuH44FkyoHhg5JX+CGUAybMjW aQXw== X-Gm-Message-State: ANhLgQ1ejfuFmHdHXC62wwPVaNeueNA/dkPY3pGuIDJfUr5A0Vi+WvxR KZF8inQ/KbIRpCh89mLvTCOrw/pZ X-Google-Smtp-Source: ADFU+vsFVBwjBlor2L5i3vDTWDXicXLkeC0NzXpTTfwEWVqvh0Vq3JG7zg6HWsqRRTplbLp6bTmEpA== X-Received: by 2002:a17:90a:2710:: with SMTP id o16mr303815pje.110.1584568289101; Wed, 18 Mar 2020 14:51:29 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id r13sm83709pgf.1.2020.03.18.14.51.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 14:51:28 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v3 4/6] emulator/bthost: Add support for ECRED Connection request/response Date: Wed, 18 Mar 2020 14:51:22 -0700 Message-Id: <20200318215124.21880-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200318215124.21880-1-luiz.dentz@gmail.com> References: <20200318215124.21880-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 support for ECRED Connection request/response which will be used by l2cap-runner to test L2CAP_MODE_EXT_FLOWCTL mode. --- emulator/bthost.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/emulator/bthost.c b/emulator/bthost.c index 6482bbecc..0fa283464 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -1773,6 +1773,69 @@ static bool l2cap_le_conn_rsp(struct bthost *bthost, struct btconn *conn, return true; } +static bool l2cap_ecred_conn_req(struct bthost *bthost, struct btconn *conn, + uint8_t ident, const void *data, uint16_t len) +{ + const struct bt_l2cap_pdu_ecred_conn_req *req = data; + struct { + struct bt_l2cap_pdu_ecred_conn_rsp pdu; + uint16_t dcid[5]; + } __attribute__ ((packed)) rsp; + uint16_t psm; + int num_scid, i = 0; + + if (len < sizeof(*req)) + return false; + + psm = le16_to_cpu(req->psm); + + memset(&rsp, 0, sizeof(rsp)); + + rsp.pdu.mtu = 64; + rsp.pdu.mps = 64; + rsp.pdu.credits = 1; + + if (!bthost_find_l2cap_cb_by_psm(bthost, psm)) { + rsp.pdu.result = cpu_to_le16(0x0002); /* PSM Not Supported */ + goto respond; + } + + len -= sizeof(rsp.pdu); + num_scid = len / sizeof(*req->scid); + + for (; i < num_scid; i++) + rsp.dcid[i] = cpu_to_le16(conn->next_cid++); + +respond: + l2cap_sig_send(bthost, conn, BT_L2CAP_PDU_ECRED_CONN_RSP, ident, &rsp, + sizeof(rsp.pdu) + i * sizeof(*rsp.dcid)); + + return true; +} + +static bool l2cap_ecred_conn_rsp(struct bthost *bthost, struct btconn *conn, + uint8_t ident, const void *data, uint16_t len) +{ + const struct { + const struct bt_l2cap_pdu_ecred_conn_rsp *pdu; + uint16_t scid[5]; + } __attribute__ ((packed)) *rsp = data; + int num_scid, i; + + if (len < sizeof(*rsp)) + return false; + + num_scid = len / sizeof(*rsp->scid); + + for (i = 0; i < num_scid; i++) + /* TODO add L2CAP connection before with proper PSM */ + bthost_add_l2cap_conn(bthost, conn, 0, + le16_to_cpu(rsp->scid[i]), 0); + + + return true; +} + static void l2cap_le_sig(struct bthost *bthost, struct btconn *conn, const void *data, uint16_t len) { @@ -1819,6 +1882,15 @@ static void l2cap_le_sig(struct bthost *bthost, struct btconn *conn, ret = l2cap_le_conn_rsp(bthost, conn, hdr->ident, data + sizeof(*hdr), hdr_len); break; + case BT_L2CAP_PDU_ECRED_CONN_REQ: + ret = l2cap_ecred_conn_req(bthost, conn, hdr->ident, + data + sizeof(*hdr), hdr_len); + break; + + case BT_L2CAP_PDU_ECRED_CONN_RSP: + ret = l2cap_ecred_conn_rsp(bthost, conn, hdr->ident, + data + sizeof(*hdr), hdr_len); + break; default: printf("Unknown L2CAP code 0x%02x\n", hdr->code); From patchwork Wed Mar 18 21:51:23 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: 11446143 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 0EBC117E6 for ; Wed, 18 Mar 2020 21:51:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C590A20772 for ; Wed, 18 Mar 2020 21:51:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZXb/+X+l" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727184AbgCRVvd (ORCPT ); Wed, 18 Mar 2020 17:51:33 -0400 Received: from mail-pl1-f174.google.com ([209.85.214.174]:43676 "EHLO mail-pl1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727116AbgCRVvd (ORCPT ); Wed, 18 Mar 2020 17:51:33 -0400 Received: by mail-pl1-f174.google.com with SMTP id f8so81435plt.10 for ; Wed, 18 Mar 2020 14:51:31 -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=y47JAL13kd9m3MR+MQoSfYse40ccLpnx6bG267K3WlY=; b=ZXb/+X+liM2sco8C1d/2QZ/c7VBuE8NfzGClghkiSlXGjkMdBuDVYpVOrSaVzYEAq4 N2KEOlAtNhK1oA7xCX30pwg2Yt9rCBMLSS8hcttJfwCwoe5pyQHPIJbhIMhUhpV8KH6z kBPFCAhaOkGkSjAe5zZ3epN+IDWVpuglKtIx2Z/QgdKPbdkKsz8+/1lYSaz8enQ7OxY6 odaH+1YB/02RJJmF7l2ochf29hz1rc3fFdBU80dkwKlc/LkoBtGKuh/jOx+qO6VxdFwd wJn5Bqa4I6J0524mrmPAcCUy/C+07Dn2VIxu7hSYhp5oyUgnKOBBkiFHW58Tj9Yg+NVB 06WQ== 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=y47JAL13kd9m3MR+MQoSfYse40ccLpnx6bG267K3WlY=; b=HI92uFL1M5Pd5rnmUDU31UCu8PdTmJ6Me3RQDIoQ9zwIRmueECdJ6JIT/L6pg1SGqD UukzIWl6350FaDPxi8WD3h1FBt/4xh0ciiWAGAd1CIxY71U7qiP82uTRdWdkmu9qSo+g ZHde5SGeE1LaAyithl+QZNh024yEfJa/n67RVomef9mUVl4iqHONBvrlIfO7TodViz6T QoaW/9ZSh2WavIpgLR/dNq2vuDZnRliVKrhCiZxEjvCTmPKP/H8FAaSOst2WyTznSddC 8hGebLN16v7zyksKRPE9nD2lebsTF2gfJm26PBrdvFHd/T7vI/z+b20zW5IdEa1mtZ2P XZbA== X-Gm-Message-State: ANhLgQ3+CV5yMJvMAodUvnn0lwocCVIPCLceOKI5yHyCR3K2/BowExoq eqG40dIGOFKRL5vLwxNnBq34u4CO X-Google-Smtp-Source: ADFU+vtbucaoyNWDFQhijjtaNJe2PeBJu0uwAm16PZxISxuXlscWpsp7VAnKagfqfP9K1x+Bl2Rxmw== X-Received: by 2002:a17:90b:d8d:: with SMTP id bg13mr271882pjb.29.1584568290213; Wed, 18 Mar 2020 14:51:30 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id r13sm83709pgf.1.2020.03.18.14.51.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 14:51:29 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v3 5/6] tools/l2cap-tester: Add test for Ext-Flowctl mode Date: Wed, 18 Mar 2020 14:51:23 -0700 Message-Id: <20200318215124.21880-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200318215124.21880-1-luiz.dentz@gmail.com> References: <20200318215124.21880-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 tests for Ext-Flowctl which uses ECRED PDUs. --- tools/l2cap-tester.c | 174 +++++++++++++++++++++++++++++++++---------- 1 file changed, 136 insertions(+), 38 deletions(-) diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c index 945f82caf..ebbd29f11 100644 --- a/tools/l2cap-tester.c +++ b/tools/l2cap-tester.c @@ -61,6 +61,7 @@ struct l2cap_data { uint16_t client_psm; uint16_t server_psm; uint16_t cid; + uint8_t mode; int expect_err; uint8_t send_cmd_code; @@ -91,7 +92,7 @@ struct l2cap_data { uint8_t *client_bdaddr; bool server_not_advertising; bool direct_advertising; - bool close_one_socket; + bool close_1; }; static void mgmt_debug(const char *str, void *user_data) @@ -474,17 +475,17 @@ static const struct l2cap_data le_client_close_socket_test_2 = { .server_not_advertising = true, }; -static const struct l2cap_data le_client_two_sockets_same_client = { +static const struct l2cap_data le_client_2_same_client = { .client_psm = 0x0080, .server_psm = 0x0080, .server_not_advertising = true, }; -static const struct l2cap_data le_client_two_sockets_close_one = { +static const struct l2cap_data le_client_2_close_1 = { .client_psm = 0x0080, .server_psm = 0x0080, .server_not_advertising = true, - .close_one_socket = true, + .close_1 = true, }; static const struct l2cap_data le_client_connect_nval_psm_test = { @@ -549,6 +550,49 @@ static const struct l2cap_data le_att_server_success_test_1 = { .cid = 0x0004, }; +static const struct l2cap_data ext_flowctl_client_connect_success_test_1 = { + .client_psm = 0x0080, + .server_psm = 0x0080, + .mode = BT_MODE_EXT_FLOWCTL, +}; + +static const struct l2cap_data ext_flowctl_client_connect_adv_success_test_1 = { + .client_psm = 0x0080, + .server_psm = 0x0080, + .mode = BT_MODE_EXT_FLOWCTL, + .direct_advertising = true, +}; + +static const struct l2cap_data ext_flowctl_client_connect_success_test_2 = { + .client_psm = 0x0080, + .server_psm = 0x0080, + .mode = BT_MODE_EXT_FLOWCTL, + .sec_level = BT_SECURITY_MEDIUM, +}; + +static const struct l2cap_data ext_flowctl_client_connect_reject_test_1 = { + .client_psm = 0x0080, + .mode = BT_MODE_EXT_FLOWCTL, + .send_cmd = cmd_reject_rsp, + .send_cmd_len = sizeof(cmd_reject_rsp), + .expect_err = ECONNREFUSED, +}; + +static const struct l2cap_data ext_flowctl_client_2 = { + .client_psm = 0x0080, + .server_psm = 0x0080, + .mode = BT_MODE_EXT_FLOWCTL, + .server_not_advertising = true, +}; + +static const struct l2cap_data ext_flowctl_client_2_close_1 = { + .client_psm = 0x0080, + .server_psm = 0x0080, + .mode = BT_MODE_EXT_FLOWCTL, + .server_not_advertising = true, + .close_1 = true, +}; + static void client_cmd_complete(uint16_t opcode, uint8_t status, const void *param, uint8_t len, void *user_data) @@ -1031,7 +1075,7 @@ failed: } static int create_l2cap_sock(struct test_data *data, uint16_t psm, - uint16_t cid, int sec_level) + uint16_t cid, int sec_level, uint8_t mode) { const struct l2cap_data *l2data = data->test_data; const uint8_t *master_bdaddr; @@ -1091,6 +1135,17 @@ static int create_l2cap_sock(struct test_data *data, uint16_t psm, } } + if (mode) { + if (setsockopt(sk, SOL_BLUETOOTH, BT_MODE, &mode, + sizeof(mode)) < 0) { + err = -errno; + tester_warn("Can't set mode: %s (%d)", strerror(errno), + errno); + close(sk); + return err; + } + } + return sk; } @@ -1212,7 +1267,8 @@ static void test_connect(const void *test_data) hciemu_add_master_post_command_hook(data->hciemu, direct_adv_cmd_complete, NULL); - sk = create_l2cap_sock(data, 0, l2data->cid, l2data->sec_level); + sk = create_l2cap_sock(data, 0, l2data->cid, l2data->sec_level, + l2data->mode); if (sk < 0) { tester_test_failed(); return; @@ -1241,7 +1297,8 @@ static void test_connect_reject(const void *test_data) const struct l2cap_data *l2data = data->test_data; int sk; - sk = create_l2cap_sock(data, 0, l2data->cid, l2data->sec_level); + sk = create_l2cap_sock(data, 0, l2data->cid, l2data->sec_level, + l2data->mode); if (sk < 0) { tester_test_failed(); return; @@ -1256,29 +1313,40 @@ static void test_connect_reject(const void *test_data) close(sk); } -static void connect_socket(const uint8_t *client_bdaddr, int *sk_holder, - GIOFunc connect_cb) +static int connect_socket(const uint8_t *client_bdaddr, GIOFunc connect_cb, + bool defer) { struct test_data *data = tester_get_data(); const struct l2cap_data *l2data = data->test_data; GIOChannel *io; int sk; - sk = create_l2cap_sock(data, 0, l2data->cid, l2data->sec_level); + sk = create_l2cap_sock(data, 0, l2data->cid, l2data->sec_level, + l2data->mode); if (sk < 0) { tester_print("Error in create_l2cap_sock"); tester_test_failed(); - return; + return -1; } - *sk_holder = sk; + if (defer) { + int opt = 1; + + if (setsockopt(sk, SOL_BLUETOOTH, BT_DEFER_SETUP, &opt, + sizeof(opt)) < 0) { + tester_print("Can't enable deferred setup: %s (%d)", + strerror(errno), errno); + tester_test_failed(); + return -1; + } + } if (connect_l2cap_impl(sk, client_bdaddr, BDADDR_LE_PUBLIC, l2data->client_psm, l2data->cid) < 0) { tester_print("Error in connect_l2cap_sock"); close(sk); tester_test_failed(); - return; + return -1; } if (connect_cb) { @@ -1290,7 +1358,10 @@ static void connect_socket(const uint8_t *client_bdaddr, int *sk_holder, g_io_channel_unref(io); } - tester_print("Connect in progress, sk = %d", sk); + tester_print("Connect in progress, sk = %d %s", sk, + defer ? "(deferred)" : ""); + + return -1; } static gboolean test_close_socket_1_part_3(gpointer arg) @@ -1457,11 +1528,11 @@ static void test_close_socket(const void *test_data) else client_bdaddr = hciemu_get_client_bdaddr(data->hciemu); - connect_socket(client_bdaddr, &data->sk, NULL); + data->sk = connect_socket(client_bdaddr, NULL, false); } -static uint8_t test_two_sockets_connect_cb_cnt; -static gboolean test_two_sockets_connect_cb(GIOChannel *io, GIOCondition cond, +static uint8_t test_2_connect_cb_cnt; +static gboolean test_2_connect_cb(GIOChannel *io, GIOCondition cond, gpointer user_data) { struct test_data *data = tester_get_data(); @@ -1485,15 +1556,15 @@ static gboolean test_two_sockets_connect_cb(GIOChannel *io, GIOCondition cond, } tester_print("Successfully connected"); - test_two_sockets_connect_cb_cnt++; + test_2_connect_cb_cnt++; - if (test_two_sockets_connect_cb_cnt == 2) { + if (test_2_connect_cb_cnt == 2) { close(data->sk); close(data->sk2); tester_test_passed(); } - if (l2data->close_one_socket && test_two_sockets_connect_cb_cnt == 1) { + if (l2data->close_1 && test_2_connect_cb_cnt == 1) { close(data->sk2); tester_test_passed(); } @@ -1510,16 +1581,16 @@ static gboolean enable_advertising(gpointer args) return FALSE; } -static void test_connect_two_sockets_part_2(void) +static void test_connect_2_part_2(void) { struct test_data *data = tester_get_data(); const struct l2cap_data *l2data = data->test_data; const uint8_t *client_bdaddr; client_bdaddr = hciemu_get_client_bdaddr(data->hciemu); - connect_socket(client_bdaddr, &data->sk2, test_two_sockets_connect_cb); + data->sk2 = connect_socket(client_bdaddr, test_2_connect_cb, false); - if (l2data->close_one_socket) { + if (l2data->close_1) { tester_print("Closing first socket! %d", data->sk); close(data->sk); } @@ -1528,7 +1599,7 @@ static void test_connect_two_sockets_part_2(void) } static uint8_t test_scan_enable_counter; -static void test_connect_two_sockets_router(uint16_t opcode, const void *param, +static void test_connect_2_router(uint16_t opcode, const void *param, uint8_t length, void *user_data) { const struct bt_hci_cmd_le_set_scan_enable *scan_params = param; @@ -1538,23 +1609,24 @@ static void test_connect_two_sockets_router(uint16_t opcode, const void *param, scan_params->enable == true) { test_scan_enable_counter++; if (test_scan_enable_counter == 1) - test_connect_two_sockets_part_2(); + test_connect_2_part_2(); else if (test_scan_enable_counter == 2) g_idle_add(enable_advertising, NULL); } } -static void test_connect_two_sockets(const void *test_data) +static void test_connect_2(const void *test_data) { struct test_data *data = tester_get_data(); const struct l2cap_data *l2data = data->test_data; const uint8_t *client_bdaddr; + bool defer; - test_two_sockets_connect_cb_cnt = 0; + test_2_connect_cb_cnt = 0; test_scan_enable_counter = 0; hciemu_add_master_post_command_hook(data->hciemu, - test_connect_two_sockets_router, data); + test_connect_2_router, data); if (l2data->server_psm) { struct bthost *bthost = hciemu_client_get_host(data->hciemu); @@ -1564,12 +1636,14 @@ static void test_connect_two_sockets(const void *test_data) NULL, NULL); } + defer = (l2data->mode == BT_MODE_EXT_FLOWCTL); + client_bdaddr = hciemu_get_client_bdaddr(data->hciemu); - if (l2data->close_one_socket) - connect_socket(client_bdaddr, &data->sk, NULL); + if (l2data->close_1) + data->sk = connect_socket(client_bdaddr, NULL, defer); else - connect_socket(client_bdaddr, &data->sk, - test_two_sockets_connect_cb); + data->sk = connect_socket(client_bdaddr, test_2_connect_cb, + defer); } static gboolean l2cap_listen_cb(GIOChannel *io, GIOCondition cond, @@ -1727,7 +1801,8 @@ static void test_server(const void *test_data) if (l2data->server_psm || l2data->cid) { sk = create_l2cap_sock(data, l2data->server_psm, - l2data->cid, l2data->sec_level); + l2data->cid, l2data->sec_level, + l2data->mode); if (sk < 0) { tester_test_failed(); return; @@ -1776,7 +1851,7 @@ static void test_getpeername_not_connected(const void *test_data) socklen_t len; int sk; - sk = create_l2cap_sock(data, 0, 0, 0); + sk = create_l2cap_sock(data, 0, 0, 0, 0); if (sk < 0) { tester_test_failed(); return; @@ -1902,14 +1977,14 @@ int main(int argc, char *argv[]) test_close_socket); test_l2cap_le("L2CAP LE Client - Open two sockets", - &le_client_two_sockets_same_client, + &le_client_2_same_client, setup_powered_client, - test_connect_two_sockets); + test_connect_2); test_l2cap_le("L2CAP LE Client - Open two sockets close one", - &le_client_two_sockets_close_one, + &le_client_2_close_1, setup_powered_client, - test_connect_two_sockets); + test_connect_2); test_l2cap_le("L2CAP LE Client - Invalid PSM", &le_client_connect_nval_psm_test, @@ -1920,6 +1995,29 @@ int main(int argc, char *argv[]) setup_powered_server, test_server); + test_l2cap_le("L2CAP Ext-Flowctl Client - Success", + &ext_flowctl_client_connect_success_test_1, + setup_powered_client, test_connect); + test_l2cap_le("L2CAP Ext-Flowctl Client, Direct Advertising - Success", + &ext_flowctl_client_connect_adv_success_test_1, + setup_powered_client, test_connect); + test_l2cap_le("L2CAP Ext-Flowctl Client SMP - Success", + &ext_flowctl_client_connect_success_test_2, + setup_powered_client, test_connect); + test_l2cap_le("L2CAP Ext-Flowctl Client - Command Reject", + &ext_flowctl_client_connect_reject_test_1, + setup_powered_client, test_connect); + + test_l2cap_le("L2CAP Ext-Flowctl Client - Open two sockets", + &ext_flowctl_client_2, + setup_powered_client, + test_connect_2); + + test_l2cap_le("L2CAP Ext-Flowctl Client - Open two sockets close one", + &ext_flowctl_client_2_close_1, + setup_powered_client, + test_connect_2); + test_l2cap_le("L2CAP LE ATT Client - Success", &le_att_client_connect_success_test_1, setup_powered_client, test_connect); From patchwork Wed Mar 18 21:51:24 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: 11446141 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 15DD514B4 for ; Wed, 18 Mar 2020 21:51:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EA3A220772 for ; Wed, 18 Mar 2020 21:51:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j2py525b" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727177AbgCRVvc (ORCPT ); Wed, 18 Mar 2020 17:51:32 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:37067 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727132AbgCRVvc (ORCPT ); Wed, 18 Mar 2020 17:51:32 -0400 Received: by mail-pl1-f193.google.com with SMTP id f16so94130plj.4 for ; Wed, 18 Mar 2020 14:51:32 -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=Lg7nkN4mkSlGzt343AERUU8DxSDQ1y02ISUsPdPcwHY=; b=j2py525b4u7qXtRQcjGH8PvWFOuhkN+Hl3qf1SXXsNkQUK4hbJ2R8ZvFb1Dv2wNElO qvTZsBnOKCoQaGhsP15ewYhn/2GUKOy2hjpouDXA66UcmlGX5w5Ue05CMB1lN3OWiahf oqy21uXtJ07sefy4vgVqdXwn5xdmfcWXW2uy30EkviEhT4BPqDQGkhoJ4lohNzOJn0OI oj/5v8fOSiP7zOW4+wDwJVwSzOhyBrrFiRGYjjvRKtZKaldQKlPyVKAtujblw3SLVgIo pbEBOIBuNP1eUS+kkHI+zCnA8yigJZtsp6QDlAPxnStbqLyskjISQPC8xVowohsqUleW l5CQ== 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=Lg7nkN4mkSlGzt343AERUU8DxSDQ1y02ISUsPdPcwHY=; b=iunVRrUiUxYslQaTEbEUggwDCLdAKVHIK8pXqnPEi22iuybDMwNKi7HKAosGTNUYiZ 5s4iPCtlY8JRkvzo+FBfO+NJqvjYCQ5mF0WE/4w+HafYDpgdDcif9YEOKUI70YF24Wjd Tj1gOo4Gn/ikmjfGgu8MTKhCJ+QNzeoQd3W5BhY8jInA58Psg6g0XwzxBmm7d65njNma g8qK499fWZvv3GIrP2sPpyaEANi2G19bTAKmXssHSflAhVEmuxbG0D9QNORcqbY9Q4lj Oa+MG6pT4saqsWuDFORU/ThwiPMVDehZi/1bU3847e2+H7YbEg6+LN22RqNi3a5U05Wg UUzg== X-Gm-Message-State: ANhLgQ1tycqW+aP95CerUrryim6nIOYWQmvxsXM5fGiHVBF0l+55gihL jwS25777baCHaJySMrPQqnOlcM4F X-Google-Smtp-Source: ADFU+vsKmUfJuGdbVN+B8ZoIfX0ODLQtOylzl6B4/rJiRIXJThJV26W3PUO5+2izMTOiX4aDc4dbdg== X-Received: by 2002:a17:90a:a891:: with SMTP id h17mr274498pjq.182.1584568291096; Wed, 18 Mar 2020 14:51:31 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id r13sm83709pgf.1.2020.03.18.14.51.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 14:51:30 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v3 6/6] gatt: Enable connecting to EATT channel using Ext-Flowctl mode Date: Wed, 18 Mar 2020 14:51:24 -0700 Message-Id: <20200318215124.21880-6-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200318215124.21880-1-luiz.dentz@gmail.com> References: <20200318215124.21880-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 use of BT_IO_MODE_EXT_FLOWCTL to connect to EATT channels. --- src/gatt-client.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/gatt-client.c b/src/gatt-client.c index 20efb7ae9..a9bfc2802 100644 --- a/src/gatt-client.c +++ b/src/gatt-client.c @@ -2182,9 +2182,13 @@ static void eatt_connect(struct btd_gatt_client *client) ba2str(device_get_address(dev), addr); - DBG("Connection attempt to: %s", addr); - for (i = bt_att_get_channels(att); i < main_opts.gatt_channels; i++) { + int defer_timeout = i + 1 < main_opts.gatt_channels ? 1 : 0; + + DBG("Connection attempt to: %s defer %s", addr, + defer_timeout ? "true" : "false"); + + /* Attempt to connect using the Ext-Flowctl */ io = bt_io_connect(eatt_connect_cb, client, NULL, &gerr, BT_IO_OPT_SOURCE_BDADDR, btd_adapter_get_address(adapter), @@ -2194,15 +2198,35 @@ static void eatt_connect(struct btd_gatt_client *client) device_get_address(dev), BT_IO_OPT_DEST_TYPE, device_get_le_address_type(dev), + BT_IO_OPT_MODE, BT_IO_MODE_EXT_FLOWCTL, BT_IO_OPT_PSM, BT_ATT_EATT_PSM, BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW, BT_IO_OPT_MTU, main_opts.gatt_mtu, + BT_IO_OPT_DEFER_TIMEOUT, defer_timeout, BT_IO_OPT_INVALID); if (!io) { - error("EATT bt_io_connect(%s): %s", addr, - gerr->message); g_error_free(gerr); - return; + gerr = NULL; + /* Fallback to legacy LE Mode */ + io = bt_io_connect(eatt_connect_cb, client, NULL, &gerr, + BT_IO_OPT_SOURCE_BDADDR, + btd_adapter_get_address(adapter), + BT_IO_OPT_SOURCE_TYPE, + btd_adapter_get_address_type(adapter), + BT_IO_OPT_DEST_BDADDR, + device_get_address(dev), + BT_IO_OPT_DEST_TYPE, + device_get_le_address_type(dev), + BT_IO_OPT_PSM, BT_ATT_EATT_PSM, + BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW, + BT_IO_OPT_MTU, main_opts.gatt_mtu, + BT_IO_OPT_INVALID); + if (!io) { + error("EATT bt_io_connect(%s): %s", addr, + gerr->message); + g_error_free(gerr); + return; + } } g_io_channel_unref(io);