From patchwork Fri May 13 23:51:23 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: 572607 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 328DDC433EF for ; Sat, 14 May 2022 01:50:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229651AbiENBu2 (ORCPT ); Fri, 13 May 2022 21:50:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbiENBu1 (ORCPT ); Fri, 13 May 2022 21:50:27 -0400 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25EEB3D6280 for ; Fri, 13 May 2022 16:53:21 -0700 (PDT) Received: by mail-il1-x136.google.com with SMTP id i22so6806847ila.1 for ; Fri, 13 May 2022 16:53:21 -0700 (PDT) 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=5E9/QWTff8XTUl3YMv8DsMWpigkqx7PC7kzC5bE9vX8=; b=BMYBZERquXYiAkw6aMfA1dxT6mDjsRqF0rpmedTSOQeQkrIZlJREHvfwM8+b8Y9vfn 139k8G0iBlgAGYI3XgV2UpON6txUVMX/yOu2YEdkjLrDHRD/mYDkgGtcaHV2S1VhokY4 uRGIik7/3+PNOS1BCQCq93peQ0A3SubgL6YdYXeJK7QkNYCAIiy9AopwcaJCOCfAZx4S ADnIpaaDfK2svwBCEqwQAp5ejim30vAk6XDhnKRpGb6CgqI6XE+mAFuxm3zw3T5ojVBJ K4QQLIziRbe1FJUJOPoA/oXSX7Mp6EzTK5BAUMlYwYcsTUaowewzlAp8hPooz2sN/FTP g3QA== 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=5E9/QWTff8XTUl3YMv8DsMWpigkqx7PC7kzC5bE9vX8=; b=UCTH0EpX7cPSE/UjeiPkKfE25gS22smI2D4DMVq8+5CgxGjwGsOj3Kh5k9IwpjYFTM M1sX8fnxlE/lo/EQk2TdPQtY+UP8k64xctxc6kBPyh8WPKna76k5Q3CKlQ+oX8CzW/5E X4sKA3u1FhikuRPV9KlhMgO2Vh9NwKQANhPIi2f8A1lR9da5bD+P3UGUMf48tboiVBAE /eE8FfM6LpuUvzf2yQ8Vs3+l076hv4r2Wf0+Sdpgw0AlY4lkcSKSC/1PttK/gYN11SzP ViAuoEdLIqdy76u1mL1fV7f/8BkcyI3PM8fjSg2ZG8gIVqpBAbC/7ggEbY8Mtr4mGfpb gfAA== X-Gm-Message-State: AOAM532cD3biYpKQ1ge9wPEd0/RGmAPdwLUcLZrIU4sPkrMjL4WxKiGw v6lJ2DKvbWMVDTrUx3SDIP8PeqtavFo= X-Google-Smtp-Source: ABdhPJwhBSDuwpfnuOn0HrsrPDqsvctHqYvCas4grtUfyBgMpYiORqE5voo283s34E3S5yz720PUuw== X-Received: by 2002:a92:d708:0:b0:2d0:ecd5:894c with SMTP id m8-20020a92d708000000b002d0ecd5894cmr3559857iln.201.1652485886931; Fri, 13 May 2022 16:51:26 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id i16-20020a056e020d9000b002d0e8a52ab6sm937628ilj.27.2022.05.13.16.51.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 16:51:26 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 1/3] Bluetooth: Add bt_status Date: Fri, 13 May 2022 16:51:23 -0700 Message-Id: <20220513235125.1364692-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds bt_status which can be used to convert Unix errno to Bluetooth status. Signed-off-by: Luiz Augusto von Dentz --- include/net/bluetooth/bluetooth.h | 1 + net/bluetooth/lib.c | 71 +++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 6b48d9e2aab9..cfe6159f26bc 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -521,6 +521,7 @@ static inline struct sk_buff *bt_skb_sendmmsg(struct sock *sk, } int bt_to_errno(u16 code); +__u8 bt_status(int err); void hci_sock_set_flag(struct sock *sk, int nr); void hci_sock_clear_flag(struct sock *sk, int nr); diff --git a/net/bluetooth/lib.c b/net/bluetooth/lib.c index 5326f41a58b7..469a0c95b6e8 100644 --- a/net/bluetooth/lib.c +++ b/net/bluetooth/lib.c @@ -135,6 +135,77 @@ int bt_to_errno(__u16 code) } EXPORT_SYMBOL(bt_to_errno); +/* Unix errno to Bluetooth error codes mapping */ +__u8 bt_status(int err) +{ + /* Don't convert if already positive value */ + if (err >= 0) + return err; + + switch (err) { + case -EBADRQC: + return 0x01; + + case -ENOTCONN: + return 0x02; + + case -EIO: + return 0x03; + + case -EHOSTDOWN: + return 0x04; + + case -EACCES: + return 0x05; + + case -EBADE: + return 0x06; + + case -ENOMEM: + return 0x07; + + case -ETIMEDOUT: + return 0x08; + + case -EMLINK: + return 0x09; + + case EALREADY: + return 0x0b; + + case -EBUSY: + return 0x0c; + + case -ECONNREFUSED: + return 0x0d; + + case -EOPNOTSUPP: + return 0x11; + + case -EINVAL: + return 0x12; + + case -ECONNRESET: + return 0x13; + + case -ECONNABORTED: + return 0x16; + + case ELOOP: + return 0x17; + + case -EPROTONOSUPPORT: + return 0x1a; + + case -EPROTO: + return 0x19; + + default: + return 0x1f; + } +} +EXPORT_SYMBOL(bt_status); + void bt_info(const char *format, ...) { struct va_format vaf; From patchwork Fri May 13 23:51:24 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: 573050 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 89E2DC433F5 for ; Sat, 14 May 2022 00:03:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229569AbiENADk (ORCPT ); Fri, 13 May 2022 20:03:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbiENADj (ORCPT ); Fri, 13 May 2022 20:03:39 -0400 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4D643D733A for ; Fri, 13 May 2022 16:53:34 -0700 (PDT) Received: by mail-io1-xd30.google.com with SMTP id h85so10342322iof.12 for ; Fri, 13 May 2022 16:53:34 -0700 (PDT) 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=3DZNAkRxrKZ2IrtkklqnnZvSJg+0ZftVA00mm61Dk4k=; b=PzjHPNSPVIO8wkopCTLY7QP8PwH3l8Ki6I3UgxKyT1U3Uhl11OpOEzZTvXy2wX7zen yn5WQE2+rv7GgTSq7u3rBultfgRc9iotIw5kJF5/8UbyP/u0xhy7o/3CHEs4AJUbmpjm KJFpTKCViX5U6N3p9DysEPAaLOLWMFc/CQVMF1aPtNC1yGE7FtIDT1gcTkecawmqWSd5 wEqZaJmXsaHZjaY6MClSx3tAhK14fVQUXVHUgkoDbN6VR6LMXnpz9V98xuKdwuu1ZpTK 7BJisQtRZo6fSjhJxBxgE/m4lJq8ypWfqdji2uu/q3AZmf/7YYAVAq6DxaWNCiTbFDcL AT1g== 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=3DZNAkRxrKZ2IrtkklqnnZvSJg+0ZftVA00mm61Dk4k=; b=2+c09lm0jAMf5zSgU0pZWW4UtihcvaXM8M2oVsx7+x+fMUSaaneOYtbMTT4A7YCROT tPycA34Efu3Ja4nmIsKKfsZ6vlkyiQXy5Lx2xTbebpqmQ/U12V1rFF8VKipukw91mg0M wrwBBOIaTssh2vFORqBOoqZ/ddtDzoWbEetUpxbbEyCiKJPXvdxUjzjjqn1MznT5z76B YG+fN5whuuC9XY/FSPCcGTpQyuR1wU6g34SSk2QSwGoZWvFSqxX0vDv2Kx7WnQYd8nvq rKUqmLo+ce6Kb+Zov6IO8iZW+CmfSKgNpLyLbIY+c4rY8DGBZS9R/nib5lyOC4//Sffe 7czg== X-Gm-Message-State: AOAM5339VGw6DwPZsIViTm7pLM95xHOnEjnTlNidy0dH/DTVr3DufvB/ aiuWa08S7LMdbjatda1Ft4qRay9JnUw= X-Google-Smtp-Source: ABdhPJwZd25y1WfFCD5GtUQpypV2CI4Ms3UzCb6JwhrvRp1++HBNQlUb2fMWH2QOtMcNFUpLgR5cAg== X-Received: by 2002:a05:6602:1584:b0:65a:cf4f:c93a with SMTP id e4-20020a056602158400b0065acf4fc93amr3355101iow.52.1652485887853; Fri, 13 May 2022 16:51:27 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id i16-20020a056e020d9000b002d0e8a52ab6sm937628ilj.27.2022.05.13.16.51.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 16:51:27 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 2/3] Bluetooth: Use bt_status to convert from errno Date: Fri, 13 May 2022 16:51:24 -0700 Message-Id: <20220513235125.1364692-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220513235125.1364692-1-luiz.dentz@gmail.com> References: <20220513235125.1364692-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 If a command cannot be sent or there is a internal error an errno maybe set instead of a command status. Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_conn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 882a7df13005..4a5193499b77 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -946,7 +946,7 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) if (!conn) goto done; - hci_le_conn_failed(conn, err); + hci_le_conn_failed(conn, bt_status(err)); done: hci_dev_unlock(hdev); From patchwork Fri May 13 23:51:25 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: 573047 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 E0674C433EF for ; Sat, 14 May 2022 01:51:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229725AbiENBva (ORCPT ); Fri, 13 May 2022 21:51:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229713AbiENBv3 (ORCPT ); Fri, 13 May 2022 21:51:29 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 423593D9DC9 for ; Fri, 13 May 2022 16:54:00 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id z26so10354745iot.8 for ; Fri, 13 May 2022 16:53:59 -0700 (PDT) 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=LxtZQmDFCfzvq4Wq0MCLivGxZ+Q/kBABlT5s9jx1zMg=; b=B6KnFS/gDy35fPnMhh7LzU2WhAiLmuXQgqnPyamgmwwPlUXZ89cWvDdfr1AsSHXUSZ zWFh2kvxSY6wx9Qb2nn4T1E7jKQmRpzU6tkETFd1s5khc4ZX7lT/8hfSjKz4LxU/cz6K hpk5xERM0WI2YpUqixECEaIA0qH0BGdyR07NRzayTIM2lZAZewFMhwFfu3eRBQbjoki0 doJjhmnTG/TfIZN6kj2q1HUNmk79Q2oDbWowbPBZ99aixG4DgUyYD/dBtMFuiKIOazJ5 cRnRCzxC9Zo7TOY7684P9b2DGcNgWRBwZzrmZ3hF1mMlDd+wXgtsjrENEsvoUZddo+mF NMuw== 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=LxtZQmDFCfzvq4Wq0MCLivGxZ+Q/kBABlT5s9jx1zMg=; b=t6VZTCBbrbKYZkuYOM401OZV5tcO9IC9hnJgcMOjKuhmtZcCQshG0EqHcEUZiOT33R 1K3cgcl1CLYj8gQw0hYJK2S7CwGyGxehj1m0Qy78hlvEehJ4otR4YLUmnKzyN8HLYsgj lZMvfNrieD58FZYcSoihSOhhrSfZjNR7lntzHGN3vR6D+9es99OwcuJKQ9hj38caqk7C gkcTjc4nmxT0O77jhEPWCsbmZaqsGivNv5Pq4ySjdIV+6WyIoHB/yTc2CCZt8SZUfOt8 S2JIaTmoGZQ1vre3GDBE5OkrtinOJvGz+RjeGOCXzgQwYoYC71Iego8gh9E8Yapv1l6I rvSg== X-Gm-Message-State: AOAM533yLFhEruUzzGCqZ30Ewl7Tx3BlzJFW21UwNSyeiKE+g5C6vtpd txJQJtSSUr9DXMCiumvb72VhzulIguw= X-Google-Smtp-Source: ABdhPJzpurznFC+m7FMvgq6t48ylV/Y6TQ/nkx7SXU3FQzVo+ApTrZ6FK4XSfXJIz/dJdgC7GSP/Gw== X-Received: by 2002:a05:6638:160d:b0:32b:d9d2:f2f2 with SMTP id x13-20020a056638160d00b0032bd9d2f2f2mr3769190jas.68.1652485889038; Fri, 13 May 2022 16:51:29 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id i16-20020a056e020d9000b002d0e8a52ab6sm937628ilj.27.2022.05.13.16.51.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 16:51:28 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 3/3] Bluetooth: hci_conn: Fix hci_connect_le_sync Date: Fri, 13 May 2022 16:51:25 -0700 Message-Id: <20220513235125.1364692-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220513235125.1364692-1-luiz.dentz@gmail.com> References: <20220513235125.1364692-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 The handling of connection failures shall be handled by the request completion callback as already done by hci_cs_le_create_conn, also make sure to use hci_conn_failed instead of hci_le_conn_failed as the later don't actually call hci_conn_del to cleanup. Fixes: 8e8b92ee60de5 ("Bluetooth: hci_sync: Add hci_le_create_conn_sync") Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_conn.c | 5 +++-- net/bluetooth/hci_event.c | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 4a5193499b77..a36297368c58 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -943,10 +943,11 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) bt_dev_err(hdev, "request failed to create LE connection: err %d", err); - if (!conn) + /* Check if connection is still pending */ + if (conn != hci_lookup_le_connect(hdev)) goto done; - hci_le_conn_failed(conn, bt_status(err)); + hci_conn_failed(conn, bt_status(err)); done: hci_dev_unlock(hdev); diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 0270e597c285..af17dfb20e01 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -5632,10 +5632,12 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, status = HCI_ERROR_INVALID_PARAMETERS; } - if (status) { - hci_conn_failed(conn, status); + /* All connection failure handling is taken care of by the + * hci_conn_failed function which is triggered by the HCI + * request completion callbacks used for connecting. + */ + if (status) goto unlock; - } if (conn->dst_type == ADDR_LE_DEV_PUBLIC) addr_type = BDADDR_LE_PUBLIC;