From patchwork Wed Feb 9 23:55:50 2022 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: 541541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CBECC433F5 for ; Thu, 10 Feb 2022 01:32:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233026AbiBJBc2 (ORCPT ); Wed, 9 Feb 2022 20:32:28 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:40760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233073AbiBJBc1 (ORCPT ); Wed, 9 Feb 2022 20:32:27 -0500 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6190C205E8 for ; Wed, 9 Feb 2022 17:32:25 -0800 (PST) Received: by mail-io1-xd36.google.com with SMTP id i62so5569485ioa.1 for ; Wed, 09 Feb 2022 17:32:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=etxAVAB3cOkKl6MfaDuYIWwyszQbn7AfSsAsSXTiogk=; b=Wz0PgVwRdXbk1AqlmPPIhWiUT4xber1Y0ZUcafQ0fZTBGdif3HY/7bsqKdJGwdhFop QoKY2tinGYofQdP5wtQkrdmlAU6S9a0T5o5eGs1JDqE0oJdUuqKhmSUipTIh4tRV6Ok6 bk08Ep6SIJ5wmXZQoSr7yGBkY+8T5EQthhULPdiu0yoV6K98++oTmj+N0WoKyRxDe7Di m/XY2Z+OF5wsjOHeKZtVshiAP+p1ad8t9oUd1mWx5MUdM/LgRLqVT4v6tNbnSfko3vfS s9u59EfsWFiKxB50CLcTp+VTFQgDnIDqg6zLqH7dZsv2z2Zys+N1k5DSfwxFek0N37Qe MH3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=etxAVAB3cOkKl6MfaDuYIWwyszQbn7AfSsAsSXTiogk=; b=ufBrJ7CLi80odD6TdFLR83wQf2ljQnFJEI+KkcxVjpwHu1kh6ZuRQ4rLduz3efC3ND yn6pPVVRAn21fwPmqsYLnAIj9lzp6+0wbdmuUHR03NN9zN/ywu2wV1z9WOUO48zBOOlW FQv+dvGFjlpW8hGvCle2F4j19xlCwR570DaoIRM6TDumrg+T/Euh3QaBGeLzNm7Qj7qy 4rQoS0yFIFG7XNiGuorkymo7x87nGXS0qq7F3xbuRG4NikaDHFJk+5QdI6eEdFcR11kO 2qYaEWJ8oZknJd3Z3CSN13v+RcdXreybRys24fKhlrq+DUljWOTOZdx8e/gWLKiFbmd+ xIMw== X-Gm-Message-State: AOAM532CMZWkoW620BCVdX9cF5RR1TRK05jPmm1gWLKRCGchYptUServ q1TIfYke0jQIxE2SqYPzgt5dZJy3ENmjoA== X-Google-Smtp-Source: ABdhPJzdjAiNO7HzOf3WWPBNcfJCceTaijfFJsWmL0R7AHuYUmKkSG+P5OTRGNPjIkpiB4rrYuu+Xw== X-Received: by 2002:a63:6a06:: with SMTP id f6mr3886696pgc.576.1644450954702; Wed, 09 Feb 2022 15:55:54 -0800 (PST) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id g7sm3240799pfi.7.2022.02.09.15.55.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 15:55:54 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/4] bthost: Fix not handling ACL fragmentation Date: Wed, 9 Feb 2022 15:55:50 -0800 Message-Id: <20220209235553.150294-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz Large packets requires the support of ACL fragmentation in order to be properly processed. --- emulator/bthost.c | 121 ++++++++++++++++++++++++++++++++++++++-------- monitor/bt.h | 2 + 2 files changed, 102 insertions(+), 21 deletions(-) diff --git a/emulator/bthost.c b/emulator/bthost.c index 66e337f34..ec7a7eb0d 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -203,6 +203,9 @@ struct bthost { uint8_t bdaddr[6]; uint8_t features[8]; bthost_send_func send_handler; + uint16_t acl_len; + uint16_t l2_len; + void *acl_data; void *send_data; struct cmd_queue cmd_q; uint8_t ncmd; @@ -491,6 +494,7 @@ void bthost_destroy(struct bthost *bthost) queue_destroy(bthost->le_ext_adv, le_ext_adv_free); + free(bthost->acl_data); free(bthost); } @@ -2426,24 +2430,15 @@ static void process_rfcomm(struct bthost *bthost, struct btconn *conn, } } -static void process_acl(struct bthost *bthost, const void *data, uint16_t len) +static void process_l2cap(struct bthost *bthost, uint16_t handle, + const void *data, uint16_t len) { - const struct bt_hci_acl_hdr *acl_hdr = data; - const struct bt_l2cap_hdr *l2_hdr = data + sizeof(*acl_hdr); - uint16_t handle, cid, acl_len, l2_len; + const struct bt_l2cap_hdr *l2_hdr = data; struct cid_hook *hook; struct btconn *conn; struct l2conn *l2conn; - const void *l2_data; - - if (len < sizeof(*acl_hdr) + sizeof(*l2_hdr)) - return; - - acl_len = le16_to_cpu(acl_hdr->dlen); - if (len != sizeof(*acl_hdr) + acl_len) - return; + uint16_t cid, l2_len; - handle = acl_handle(acl_hdr->handle); conn = bthost_find_conn(bthost, handle); if (!conn) { bthost_debug(bthost, "ACL data for unknown handle 0x%04x", @@ -2452,36 +2447,40 @@ static void process_acl(struct bthost *bthost, const void *data, uint16_t len) } l2_len = le16_to_cpu(l2_hdr->len); - if (len - sizeof(*acl_hdr) != sizeof(*l2_hdr) + l2_len) + if (len != sizeof(*l2_hdr) + l2_len) { + bthost_debug(bthost, "L2CAP invalid length: %u != %zu", + len, sizeof(*l2_hdr) + l2_len); return; + } - l2_data = data + sizeof(*acl_hdr) + sizeof(*l2_hdr); + bthost_debug(bthost, "L2CAP data: %u bytes", l2_len); cid = le16_to_cpu(l2_hdr->cid); hook = find_cid_hook(conn, cid); if (hook) { - hook->func(l2_data, l2_len, hook->user_data); + hook->func(l2_hdr->data, l2_len, hook->user_data); return; } switch (cid) { case 0x0001: - l2cap_sig(bthost, conn, l2_data, l2_len); + l2cap_sig(bthost, conn, l2_hdr->data, l2_len); break; case 0x0005: - l2cap_le_sig(bthost, conn, l2_data, l2_len); + l2cap_le_sig(bthost, conn, l2_hdr->data, l2_len); break; case 0x0006: - smp_data(conn->smp_data, l2_data, l2_len); + smp_data(conn->smp_data, l2_hdr->data, l2_len); break; case 0x0007: - smp_bredr_data(conn->smp_data, l2_data, l2_len); + smp_bredr_data(conn->smp_data, l2_hdr->data, l2_len); break; default: l2conn = btconn_find_l2cap_conn_by_scid(conn, cid); if (l2conn && l2conn->psm == 0x0003) - process_rfcomm(bthost, conn, l2conn, l2_data, l2_len); + process_rfcomm(bthost, conn, l2conn, l2_hdr->data, + l2_len); else bthost_debug(bthost, "Packet for unknown CID 0x%04x (%u)", @@ -2490,6 +2489,86 @@ static void process_acl(struct bthost *bthost, const void *data, uint16_t len) } } +static void append_acl_data(struct bthost *bthost, uint16_t handle, + uint8_t flags, const void *data, uint16_t len) +{ + if (!bthost->acl_data) { + bthost_debug(bthost, "Unexpected ACL frame: handle 0x%4.4x " + "flags 0x%2.2x", handle, flags); + return; + } + + if (bthost->acl_len + len > bthost->l2_len) { + bthost_debug(bthost, "Unexpected ACL frame: handle 0x%4.4x " + "flags 0x%2.2x", handle, flags); + return; + } + + memcpy(bthost->acl_data + bthost->acl_len, data, len); + bthost->acl_len += len; + + bthost_debug(bthost, "ACL data: %u/%u bytes", bthost->acl_len, + bthost->l2_len); + + if (bthost->acl_len < bthost->l2_len) + return; + + process_l2cap(bthost, handle, bthost->acl_data, bthost->acl_len); + + free(bthost->acl_data); + bthost->acl_data = NULL; + bthost->acl_len = 0; + bthost->l2_len = 0; +} + +static void process_acl(struct bthost *bthost, const void *data, uint16_t len) +{ + const struct bt_hci_acl_hdr *acl_hdr = data; + const struct bt_l2cap_hdr *l2_hdr = (void *) acl_hdr->data; + uint16_t handle, acl_len, l2_len; + uint8_t flags; + + acl_len = le16_to_cpu(acl_hdr->dlen); + if (len != sizeof(*acl_hdr) + acl_len) + return; + + handle = acl_handle(acl_hdr->handle); + flags = acl_flags(acl_hdr->handle); + + switch (flags) { + case 0x00: /* start of a non-automatically-flushable PDU */ + case 0x02: /* start of an automatically-flushable PDU */ + if (bthost->acl_data) { + bthost_debug(bthost, "Unexpected ACL start frame"); + free(bthost->acl_data); + bthost->acl_data = NULL; + bthost->acl_len = 0; + } + + l2_len = le16_to_cpu(l2_hdr->len) + sizeof(*l2_hdr); + + bthost_debug(bthost, "acl_len %u l2_len %u", acl_len, l2_len); + + if (acl_len == l2_len) { + process_l2cap(bthost, handle, acl_hdr->data, acl_len); + break; + } + + bthost->acl_data = malloc(l2_len); + bthost->acl_len = 0; + bthost->l2_len = l2_len; + /* fall through */ + case 0x01: /* continuing fragment */ + append_acl_data(bthost, handle, flags, acl_hdr->data, acl_len); + break; + case 0x03: /* complete automatically-flushable PDU */ + process_l2cap(bthost, handle, acl_hdr->data, acl_len); + break; + default: + bthost_debug(bthost, "Invalid ACL frame flags 0x%2.2x", flags); + } +} + void bthost_receive_h4(struct bthost *bthost, const void *data, uint16_t len) { uint8_t pkt_type; diff --git a/monitor/bt.h b/monitor/bt.h index dc4e11c3c..66ed3ef5a 100644 --- a/monitor/bt.h +++ b/monitor/bt.h @@ -488,6 +488,7 @@ struct bt_hci_cmd_hdr { struct bt_hci_acl_hdr { uint16_t handle; uint16_t dlen; + uint8_t data[]; } __attribute__ ((packed)); struct bt_hci_sco_hdr { @@ -3663,6 +3664,7 @@ struct bt_hci_evt_le_req_peer_sca_complete { struct bt_l2cap_hdr { uint16_t len; uint16_t cid; + uint8_t data[]; } __attribute__ ((packed)); struct bt_l2cap_hdr_sig { From patchwork Wed Feb 9 23:55:51 2022 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: 541893 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCB33C433EF for ; Thu, 10 Feb 2022 01:59:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233781AbiBJB72 (ORCPT ); Wed, 9 Feb 2022 20:59:28 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233589AbiBJB7Q (ORCPT ); Wed, 9 Feb 2022 20:59:16 -0500 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9385C11 for ; Wed, 9 Feb 2022 17:39:41 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id u16so1836158pfg.3 for ; Wed, 09 Feb 2022 17:39:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=EKXgK4hvTTvI6KIca/M1Yl6LgjBVeVLvORxpCeuBWYI=; b=MPnFr+iiV+bHIxw2dAsFblU8tI1rljyx8rcVSVbaXgt1bJs4Q00Lf58PmEHt6ZyQmV J8rGR+wFwvLe1mr361APTPNrGHaWXmqMJ1mWgV1cshb4HcTSRsSmWyu5hI80qhv2RByK D3ogjFmzR4RsVZdX2iUAZxV73wGUE8ev14Q4TGABCIl9x1y41VnURl/FMZ6Dp28glI0L ImiJHeOWX5o8GzK8kv19iRhcBJsovFGuUp0iXgzK1r0IX3/VzfeOR4WLrqe8waXI0+EO USpECu6aqQRtDzWFOTC1s9jOPtcaH3RnzndxhDOLV5TpQVF5u0kzm1ia7D4rTgDmEoW3 12uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EKXgK4hvTTvI6KIca/M1Yl6LgjBVeVLvORxpCeuBWYI=; b=pIYCWAhJLh9Gc067wVPLoE/437Mg5HrTJrSU6LisEKmFrDy5uhguKNABAQkXAqnSv2 DeVkFxZT932DG93SiIReWP0OvkZXYrnUCmm0w9iuNAKZ4qquKds9+qHO81AMvVIVQQSX CooZZlOAfglHEtxWCOXsE1x5uW+3zBwslNeE6rkOdG3GCbKaRhvpG96NA4elwoxIlW3d 5dCjUrl4OXhiNsyh8NlNK7EbcHH6HZ0ca7nLfHf66I8uahVKvZi1CU0+yq53z+uLuAmU GveHzBkhOUOM+H8j0H7pz+Wse0EW6ajygeI6IoAC6O88IQDMC0zwu61C38o2BkbdZv/q gKxA== X-Gm-Message-State: AOAM531pLeaAAOmrzCkTTgW8L1amL8aSCmDxnFYr5LJx/UnvF3UEizLz jqumiCF+OAaBktWvWBDQRMfS+o8T9kpRcw== X-Google-Smtp-Source: ABdhPJzuMgkl16dxow/XFCdDs7hP6ivVcDFQ+n2cLd1LRuz0LbZeWEO17z9fMKOpKkTUyM3UIkDh2A== X-Received: by 2002:a63:287:: with SMTP id 129mr3998698pgc.158.1644450955391; Wed, 09 Feb 2022 15:55:55 -0800 (PST) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id g7sm3240799pfi.7.2022.02.09.15.55.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 15:55:55 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/4] bthost: Fix length calculation for RFCOMM header Date: Wed, 9 Feb 2022 15:55:51 -0800 Message-Id: <20220209235553.150294-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220209235553.150294-1-luiz.dentz@gmail.com> References: <20220209235553.150294-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This fixes the length calculation for large packets that requires more than 1 byte. --- emulator/bthost.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/emulator/bthost.c b/emulator/bthost.c index ec7a7eb0d..bb1219d28 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -2373,20 +2373,25 @@ static void rfcomm_uih_recv(struct bthost *bthost, struct btconn *conn, uint16_t hdr_len, data_len; const void *p; - if (len < sizeof(*hdr)) + if (len < sizeof(*hdr)) { + bthost_debug(bthost, "RFCOMM UIH: too short"); return; + } if (RFCOMM_TEST_EA(hdr->length)) { data_len = (uint16_t) GET_LEN8(hdr->length); hdr_len = sizeof(*hdr); } else { uint8_t ex_len = *((uint8_t *)(data + sizeof(*hdr))); - data_len = ((uint16_t) hdr->length << 8) | ex_len; + data_len = GET_LEN16((((uint16_t) ex_len << 8) | hdr->length)); hdr_len = sizeof(*hdr) + sizeof(uint8_t); } - if (len < hdr_len + data_len) + if (len < hdr_len + data_len) { + bthost_debug(bthost, "RFCOMM UIH: %u != %u", len, + hdr_len + data_len); return; + } p = data + hdr_len; @@ -2408,6 +2413,8 @@ static void process_rfcomm(struct bthost *bthost, struct btconn *conn, { const struct rfcomm_hdr *hdr = data; + bthost_debug(bthost, "RFCOMM data: %u bytes", len); + switch (RFCOMM_GET_TYPE(hdr->control)) { case RFCOMM_SABM: rfcomm_sabm_recv(bthost, conn, l2conn, data, len); From patchwork Wed Feb 9 23:55:52 2022 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: 541540 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5194C43217 for ; Thu, 10 Feb 2022 01:59:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234323AbiBJB7H (ORCPT ); Wed, 9 Feb 2022 20:59:07 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:33834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234068AbiBJB6C (ORCPT ); Wed, 9 Feb 2022 20:58:02 -0500 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84E1A2B6A5 for ; Wed, 9 Feb 2022 17:44:03 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id x3so530797pll.3 for ; Wed, 09 Feb 2022 17:44:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=rV4Eu7WBcbdGqPKustrUZI4J/tnCnXCXuSWzYwJDk84=; b=bAK7uBL5uWhFyhVQLbCtGjRcAmCB/u/M9czo7hEt96y7XzxyDtv95xutzsYfCsMsNf QJisKGRh/AtAvkZ0ZjhERNS6AEZlhbx44Gz2nhl+4Xg/E6cdkXc8LYUfKMZRnPuMstf/ zTE34iicFXG45hMGAYRC3vqyAEqaW6aPfyv6YZ3aI0Rd0nSYvBclPGGeYasdkm2sNMdP fbsarqphtAmyV9oaiDslTGnCblpM/TOXy1XLrKw/uT47TkrcigDa0ZDCo4ZDIJjAAlKJ fNyDzJjXG3NTmtl1WPpTuBRKfLaEPAPS1U4RCTPCteM8BL3q4LELZ+UWw6jXnOCgZMi6 rk/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rV4Eu7WBcbdGqPKustrUZI4J/tnCnXCXuSWzYwJDk84=; b=r4Iy2AFLArsgH6vKktQakzmUgobHEsiHgqsG41H1uIQxP5OwVWijIuuXMVWsCiERr4 c1xucgWxBx1efR04+SSxlqLlS9gSkQFYObYtFhY5TKBugqesDCFG2EZ/VejKkwa29i5g wCRXvJwqkX5IDF6RzTWer6o7HRdJg7Ho2g1wcRoEdsHtAu+b6BJdnzhEmWAGAscdYK/m Q8tZITuCeIC58WVi7H9d1LgWhWR4KhDMNM5qrk3W5yqeDqe+NA+MH9TfKD1v3oTuIZ/E +KiYml7Cddzkw0VNRUb4epUDNHLftp1Qwi7VvqNEPvq7girSOaK7+r5cE7mJIdZkrHJ6 jEFA== X-Gm-Message-State: AOAM531h0SL09R/z37kiL2cNSdtHId7pu3oIe5Z6bPHW+XRuDHWiUlbo qrUKW9k8UNSLCIjTUTWxBqwu7f5dWTAqJw== X-Google-Smtp-Source: ABdhPJzfBhWXb8U3kPImfNGYNQrk+e22U3vPJsRm8zjHg1QRmOk9Sz37l4hX1qRSimgnOM1XNY94fA== X-Received: by 2002:a17:903:40c2:: with SMTP id t2mr4862998pld.143.1644450956044; Wed, 09 Feb 2022 15:55:56 -0800 (PST) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id g7sm3240799pfi.7.2022.02.09.15.55.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 15:55:55 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 3/4] bthost: Increase number of credits Date: Wed, 9 Feb 2022 15:55:52 -0800 Message-Id: <20220209235553.150294-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220209235553.150294-1-luiz.dentz@gmail.com> References: <20220209235553.150294-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This increase the number of credits so bigger packets can be sent by the likes of rfcomm-tester. --- emulator/bthost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emulator/bthost.c b/emulator/bthost.c index bb1219d28..d751e7dd4 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -2322,7 +2322,7 @@ static void rfcomm_pn_recv(struct bthost *bthost, struct btconn *conn, pn_cmd.ack_timer = pn->ack_timer; pn_cmd.max_retrans = pn->max_retrans; pn_cmd.mtu = pn->mtu; - pn_cmd.credits = pn->credits; + pn_cmd.credits = 255; rfcomm_uih_send(bthost, conn, l2conn, RFCOMM_ADDR(1, 0), RFCOMM_MCC_TYPE(0, RFCOMM_PN), &pn_cmd, sizeof(pn_cmd)); From patchwork Wed Feb 9 23:55:53 2022 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: 541895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2622CC433FE for ; Thu, 10 Feb 2022 01:28:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232439AbiBJB2r (ORCPT ); Wed, 9 Feb 2022 20:28:47 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:56782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232357AbiBJB2i (ORCPT ); Wed, 9 Feb 2022 20:28:38 -0500 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5119420F7C for ; Wed, 9 Feb 2022 17:28:40 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id y8so4756575pfa.11 for ; Wed, 09 Feb 2022 17:28:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=128JU9ZRRKnPuOh1w064by2lJFlQlZWtP6zeO7W2M20=; b=YxyHGW3cijYGiVelG0kk5Rirc+2Ql5aHyRwJTENB1M8ffWLL2124U9jfJMLdAUB1hL cbKymfFtvkHWr9Bq/Rw5elxUg3c7gPcR2X4FTlIuERWQW5Tx+MWQVJwSIOD1/+uAKcVp o47cf8bIUr+htME+yhxtKF5DGtRNJxE+z3d7I7K/4MkuQp75XyRMGJaOmLe6PNuheO10 AqNwrklTLuzUKVldlOQ8jNcb87Ge52A3vsKQ6ZzEqkunNTJkAFcamFcWMc6gYLCTli2J H91snKOrpDBIKb4t2BFRTqiQzFHcKfwoh1vzd+BqzX7ocOq853CiHcmAvrQvT/LOTeXK cnTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=128JU9ZRRKnPuOh1w064by2lJFlQlZWtP6zeO7W2M20=; b=xT20TN2S9pSm9z28pTyYhhIDjoUDLgRtUluuT9OigKHDs5nqh2vGxBiFNy7aakpEzk 7AcuoPi0YKO0hZ10fGlx0sZhgn2JoZOXft9F4J9EoHNFnmLSoAdey00na6UpwRsFWIDt rRSNwr3tstQ/Amcn6wN4hWVd1hBkUl4ZCzt/xabDrUC/pYNTeZfj8jBmbhk5mw9YlBK+ oASx4W38Fgn9L3Nm5522pi+pAm01wCZi81RHNmmOgiH2iForMcUhcR2+X6QgZRqhBuFH UX4jBrogjGbUPfOkXo0BUSL1X2KuuF0CIpCXJK/JY10JCgQwiPqCOOhsXx1pJ4tVyRY9 Uv3g== X-Gm-Message-State: AOAM533XUG/xRxUltS2SvALdCeQpu+VW2JNgnWB3fUVyNKQUMtlefZIg yCERAznoUCWvW0/3q6IBUL9/RKRA5RgklA== X-Google-Smtp-Source: ABdhPJybaFb4Eb8AzmsyZ1m5I6l9bqn/p3+yuKJ7d+vHnnwtnN/JADScnkI9eL/bT7S7VwD5HPaDGQ== X-Received: by 2002:a17:903:230c:: with SMTP id d12mr4685510plh.74.1644450956731; Wed, 09 Feb 2022 15:55:56 -0800 (PST) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id g7sm3240799pfi.7.2022.02.09.15.55.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 15:55:56 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 4/4] rfcomm-tester: Add test to write big chunks of data Date: Wed, 9 Feb 2022 15:55:53 -0800 Message-Id: <20220209235553.150294-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220209235553.150294-1-luiz.dentz@gmail.com> References: <20220209235553.150294-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This attempts to test traffic similar to OBEX using big chunk of data. --- tools/rfcomm-tester.c | 47 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/tools/rfcomm-tester.c b/tools/rfcomm-tester.c index ef47904de..650d33cb6 100644 --- a/tools/rfcomm-tester.c +++ b/tools/rfcomm-tester.c @@ -39,6 +39,7 @@ struct test_data { const void *test_data; unsigned int io_id; uint16_t conn_handle; + uint16_t recv_len; }; struct rfcomm_client_data { @@ -297,7 +298,24 @@ const struct rfcomm_client_data connect_send_success = { .server_channel = 0x0c, .client_channel = 0x0c, .data_len = sizeof(data), - .send_data = data + .send_data = data, +}; + +const uint8_t data_8k[8192] = { [0 ... 1023] = 0x00, + [1024 ... 2047] = 0x01, + [2048 ... 3071] = 0x02, + [3072 ... 4095] = 0x03, + [4096 ... 5119] = 0x04, + [5120 ... 6143] = 0x05, + [6144 ... 7167] = 0x06, + [7168 ... 8191] = 0x07, +}; + +const struct rfcomm_client_data connect_send_8k_success = { + .server_channel = 0x0c, + .client_channel = 0x0c, + .data_len = sizeof(data_8k), + .send_data = data_8k, }; const struct rfcomm_client_data connect_read_success = { @@ -448,7 +466,6 @@ static gboolean rc_connect_cb(GIOChannel *io, GIOCondition cond, ssize_t ret; tester_print("Writing %u bytes of data", cli->data_len); - ret = write(sk, cli->send_data, cli->data_len); if (cli->data_len != ret) { tester_warn("Failed to write %u bytes: %s (%d)", @@ -483,16 +500,29 @@ static void client_hook_func(const void *data, uint16_t len, tester_print("bthost received %u bytes of data", len); - if (cli->data_len != len) { + if (test_data->recv_len + len > cli->data_len) { + tester_print("received more data than expected"); tester_test_failed(); return; } - ret = memcmp(cli->send_data, data, len); - if (ret) + ret = memcmp(cli->send_data + test_data->recv_len, data, len); + if (ret) { tester_test_failed(); - else - tester_test_passed(); + return; + } + + test_data->recv_len += len; + + tester_print("bthost received progress %u/%u", test_data->recv_len, + cli->data_len); + + if (cli->data_len != test_data->recv_len) + return; + + test_data->recv_len = 0; + + tester_test_passed(); } static void server_hook_func(const void *data, uint16_t len, @@ -735,6 +765,9 @@ int main(int argc, char *argv[]) test_rfcomm("Basic RFCOMM Socket Client - Write Success", &connect_send_success, setup_powered_client, test_connect); + test_rfcomm("Basic RFCOMM Socket Client - Write 8k Success", + &connect_send_8k_success, setup_powered_client, + test_connect); test_rfcomm("Basic RFCOMM Socket Client - Read Success", &connect_read_success, setup_powered_client, test_connect);