From patchwork Fri May 13 23:46:09 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: 572608 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 6559BC433EF for ; Sat, 14 May 2022 01:42:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229640AbiENBmM (ORCPT ); Fri, 13 May 2022 21:42:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiENBmJ (ORCPT ); Fri, 13 May 2022 21:42:09 -0400 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91D5B36C353 for ; Fri, 13 May 2022 16:46:23 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id z12so6778540ilp.8 for ; Fri, 13 May 2022 16:46:23 -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=I0E+CHutkT2xy0OW1OZQy1kisFckLG44HV1YR7Ktc2CbB4b7FtTjUa9orvaB7FmfUw Cz1ElnYE1hBTLYcOynUO+qzn7QNifxStDG/thfHr9PEb9h5RSQFzFaMLvrTdK7lPG+Nl V0w4qme4lxwjDQLfcyQglSxzgRzHmy2VssIs46l61+t0Zpc+R6HGJlIIvcHOCTmZbAUs 99ONHSD9LOLLw+MPUUJvs6QEwhGWbFaM840SwS5HMW6YDk22sq2DQ1orOBVJ443MgGtq 3f5DWel+j5X39Vf8iNn6GnpADiYRyLYNJr8i2AdYGI53rq5n8gToQF4aWzOE1G0pP4ad zJWg== 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=nHsWdvibkXjJMguH9rrKeAWVwMSMACQP5soHtZRwOe4jt6/e/LPgp2gYyfc5XtveJD kbtAhBqAhgpva9rYeed9VJI2c/s+PlWKMkaB62/ZbJMdtlbHYzEIZRoJBqodqfg4Uq3D n7DY0JaX6/uSiaCUMy/aJMkoACRGg4wxx/dhz94LDn6ODSx2/g9XQgda/ewpsGglmVGm +snd1L3J85aBc7Ila7nXV82XStPvvln0BF/PHaxdduG2mQwD/yjPT2zwtlDaBvD2NCAm BLJBtBA1X7oAYpQbLMfsVFLfd1okMK8WL/Lc9ORA/RAcEKLeIA7KPDscIVs52NSGW/m2 nQtw== X-Gm-Message-State: AOAM530Y+gCeoL6/RqsbqZ+64JeunR6GhGDplcIthMTBF+KNdQ73Qp2E 16vn98h1POptMsmSLEsIChhc3ogVL3I= X-Google-Smtp-Source: ABdhPJwWmkUu3vUzOijN+BL3MDikgOt0IsOFuU6nHzrMbSFAMXFMwrpHSLml0clWB91KW5piZoYUow== X-Received: by 2002:a92:7a03:0:b0:2d0:f018:ec30 with SMTP id v3-20020a927a03000000b002d0f018ec30mr3722760ilc.81.1652485574528; Fri, 13 May 2022 16:46:14 -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 k9-20020a02cb49000000b0032b3a78178fsm1045203jap.83.2022.05.13.16.46.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 16:46:14 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 1/3] Bluetooth: Add bt_status Date: Fri, 13 May 2022 16:46:09 -0700 Message-Id: <20220513234611.1360704-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:46:10 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: 573048 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 DC058C433FE for ; Sat, 14 May 2022 01:42:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbiENBmN (ORCPT ); Fri, 13 May 2022 21:42:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbiENBmL (ORCPT ); Fri, 13 May 2022 21:42:11 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2173C3ACA2F for ; Fri, 13 May 2022 16:46:25 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id n6so6773960ili.7 for ; Fri, 13 May 2022 16:46:25 -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=oXQhp9Vk6coiHKOaQbcWt0MLHOhvkkF5KVA3WGBeqWnjAsmUSmw2OShQueiyySUKyX UblFT99sQ835Fd5xV4ORGrJ7+BBtPjyoIuHKzNyZ0787nyHg6wIWac/oQ32w61Ea3xms pKkCT7RoUvXPo8LVSYsQ1jD3FxhPZbJIm74dUnKR3UJdmCbl9mDnr1rw8GFnxJRTWPkN Nj69Zsc6ysk+MY6TK2X7aEq1B0v0WRZOOsyt4wDqTT59Dtta1ahzvC2mJw/VlMXUO+25 t8aUAxf5ifE5YQvO7VLX2E8Az9bLBiucAq+CE0/qJQltm1LZspzHeI6OFbm9rXBR7SA7 JNEg== 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=h2pr8kQ/vMX7fdLA9wxhE4LsTruDPyBCVc/RNtP4ZRwJ4gHxFQwc99dGN8DzPvxmAn lG/qWD8Rbnfjw7d2ZJOnKsoJfmfm7XZKs7mCh6fco8ZKZVLwBrhdwdF6bTVP9gbHtAte ubuAkZpPWKXlILrU8rcYD+zF95eiXD8XX238qJgzddnWEKlf9apCKGS0He7cCqwyAmaL tBicN76CwtYbE4hIVw232Jl6hJunJ6kKuW/s5E+4tKqjHs6sv60NZT0/AGOAT3BzMPhc pV1WJBwi+RxRMgSW3tJDIEeEC3tIJfzeP8LKSbpt9FKXDnVQ9cNmq2RVgaFtXQfYEdpi Wk5A== X-Gm-Message-State: AOAM533rCG8IzpwAZv6MLsQHimeAcN5EWaWEMo5ozlRbXGs/RSghboWe Cb/yhBqbdnhjTLfnQ1yuiyDD5ggEeqM= X-Google-Smtp-Source: ABdhPJzA2Bi/hVOFBEA0UCyuNmamX3O//YmM9Cwiki3EAfaPVdH1SLpQoK4qh768stI8TSiOjQEgtw== X-Received: by 2002:a92:d708:0:b0:2d0:ecd5:894c with SMTP id m8-20020a92d708000000b002d0ecd5894cmr3552488iln.201.1652485575714; Fri, 13 May 2022 16:46:15 -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 k9-20020a02cb49000000b0032b3a78178fsm1045203jap.83.2022.05.13.16.46.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 16:46:15 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 2/3] Bluetooth: Use bt_status to convert from errno Date: Fri, 13 May 2022 16:46:10 -0700 Message-Id: <20220513234611.1360704-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220513234611.1360704-1-luiz.dentz@gmail.com> References: <20220513234611.1360704-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:46:11 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: 573049 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 C192EC433F5 for ; Sat, 14 May 2022 01:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229625AbiENBln (ORCPT ); Fri, 13 May 2022 21:41:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiENBlm (ORCPT ); Fri, 13 May 2022 21:41:42 -0400 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC5B936DCDD for ; Fri, 13 May 2022 16:46:27 -0700 (PDT) Received: by mail-io1-xd2f.google.com with SMTP id o190so10336879iof.10 for ; Fri, 13 May 2022 16:46:27 -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=VlFyv9ldND/lJmA77XlE+D6MAlUKWPX9DalQosILKag=; b=jvPJb5/FrbHeypd7sMc4l6Cli6Izcz+IphxhKGAkhetMXNO16wnUcANno3TIYVR62l xKu0MUwQCdbdFxyalxjNtUbdFShSAEhzDcluZTfWL659bGUkH7rBIJ7FaCRF7gXp9WtJ AnG0mNV0XgquAmjmCor5EBxKdeDLc1+A+P2OqDSkanyfPhsowbtw7o7xJcrKJWKTSd+d TP1gosSV32D8YhtSVVBQY0EHtdrHURsbfWahM3Z0HfqTMhpc1838Nkcrsc4CslUo136W QxK+pu10vZFr1ILY7zo5LG/GqIwUvv1ejBmjKfMrD8jkioSPW3vcUr7WqKNADw0Ox0be Lovw== 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=VlFyv9ldND/lJmA77XlE+D6MAlUKWPX9DalQosILKag=; b=cM+kWAjaHcdtEyGTRvMHlz0YjjfcNo6HausfSWRT+SeCZWDdJ0OTVct3mNYgf+eu0C sADuvTW5tv173aaAF1yi+3Owbucdch7mBUcLvctqv3WCpa6Cjbg89n7eAch9xgapZqJd 83Xr80i5bNxln7LPDQRxdXHEan5aIrDpo+BqGY7YWwyGcZUeztiDNeo0lCU32vfyh7eT Ga2CC7EdWPAkcmtIkQZx3jBPFYZStNSNSAPzKGFLyGcGaaZQ8YN4jlSWhsWO7oiT5FFK hzx2JKMkGlYHFP0rnA/tNT5/mqq/yQhppi6VeC+9G1xq7n+ojUZZ3lsFilem51T8IZ2G mJwA== X-Gm-Message-State: AOAM530x/0wwZ4DimwGzvX3T9jx8VoAiElVVUQ37OuV71Rj2H3ypbchu BpaVZ1/ciVD+HeLXJWbprWY+8sK/VVg= X-Google-Smtp-Source: ABdhPJxFfRQUOgcsn3QvrmF2E20B0h7Plg6quvaSDj24VT5uANVvdLWj0OatdQP5vYR6QMTH/7yvIg== X-Received: by 2002:a05:6602:15c6:b0:611:591d:1d9a with SMTP id f6-20020a05660215c600b00611591d1d9amr3258465iow.177.1652485577028; Fri, 13 May 2022 16:46:17 -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 k9-20020a02cb49000000b0032b3a78178fsm1045203jap.83.2022.05.13.16.46.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 16:46:16 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 3/3] Bluetooth: hci_conn: Fix hci_connect_le_sync Date: Fri, 13 May 2022 16:46:11 -0700 Message-Id: <20220513234611.1360704-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220513234611.1360704-1-luiz.dentz@gmail.com> References: <20220513234611.1360704-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 | 2 +- net/bluetooth/hci_event.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 4a5193499b77..c981f3616bb1 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, 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;