From patchwork Thu May 5 00:06:27 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: 570006 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 33C92C433F5 for ; Thu, 5 May 2022 00:06:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229912AbiEEAKc (ORCPT ); Wed, 4 May 2022 20:10:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230357AbiEEAKV (ORCPT ); Wed, 4 May 2022 20:10:21 -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 1366ABE3A for ; Wed, 4 May 2022 17:06:32 -0700 (PDT) Received: by mail-io1-xd2f.google.com with SMTP id c125so3193535iof.9 for ; Wed, 04 May 2022 17:06:32 -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=nioaqjqLdY/wp4Axj57RP1u4no4YkH7ktCK5JxBPAOl4FLeNaXUk+TVbVj6y6N7qtP 3jfVco0a4P5gn73Bt/HM/BW0WrnH0ZNfAio2G0R/gB6zyPGpZsvWnv5G5Cb/dvjqynjY DuiN/86qZUxB2cqNsT+P9TxF5XKms9V25Ipv450YPEzYMLxRkNcZdXESzeWSciFcUzCs hXABrOLIhT9TKQXQ7mHB0WJ8uIdZSnTmAkpixuyPoGfeFb9xWNQXN+bvb/BwsLZv1WaW n6ZanavTHPfslDpsiODOP3jUfIuZtA4zbR8XEBaEnreXiChFXmzHvUcx2SDKhuvyCDQ+ 69lw== 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=ulH3AqiCWvHfIJ4r3Uq+5XzGSQLOlDbnMOy7idNCa3a4z3WL97McgsnY0MrUlOR4ip Ye/fneBC7Qa74DsRl8zC7LjxC+ITAVPEs++tulmDfKNEQRUo++Y2W8xKRG7cmgO2nQR+ xEtu/ePBVODfr5FzfuEWIM9NOmrYfMg1nvbw54G6xR/SVlh2Rs/NjbDgQ2YTh3Db8wzF whbjCwXnEXQqe123sEZSUfqugNZBLnbcnm6cgbNd9eJM0KCLojd/v7PWRrM+zLBhL0c9 mb60RsELVLcMAKPPsLLDGOw1L2v1qXEA94+tCBJXEklywfvotaxcPerAuD5XSbt4CpB8 UEqA== X-Gm-Message-State: AOAM531yatv+cJtujtM6DOX6ahPty2pC3N334aTENnOF4W/anVR1bWtY fX5/3alzWyYLYvwv4siyJw7/gJKId58= X-Google-Smtp-Source: ABdhPJw2iLavymU1fF8D4eUHIsuFqUS0x2//J8q4OM7f8aP+2WUw0GlxHkQDHUsDumWFtFWN8u2Ccw== X-Received: by 2002:a05:6638:5b3:b0:323:a07d:6747 with SMTP id b19-20020a05663805b300b00323a07d6747mr9721111jar.252.1651709191154; Wed, 04 May 2022 17:06:31 -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 f5-20020a056e020b4500b002cde6e352d2sm57926ilu.28.2022.05.04.17.06.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 17:06:30 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 1/2] Bluetooth: Add bt_status Date: Wed, 4 May 2022 17:06:27 -0700 Message-Id: <20220505000629.2903297-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 Thu May 5 00:06:29 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: 570005 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 93A24C433F5 for ; Thu, 5 May 2022 00:06:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbiEEAKe (ORCPT ); Wed, 4 May 2022 20:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230446AbiEEAKV (ORCPT ); Wed, 4 May 2022 20:10:21 -0400 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FDD74AE29 for ; Wed, 4 May 2022 17:06:34 -0700 (PDT) Received: by mail-io1-xd34.google.com with SMTP id h85so3179378iof.12 for ; Wed, 04 May 2022 17:06: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=HbiYWIdNVKwGTsgzPzqs9alYt87vKPF/fNKnqjlmsgTVrVKSY+BKH1moNiAadjnjCT uiDRW0O9WAAqxsblrrt/PcLBKUi1ujrk4w8FD2W2DUtx4pgXAGowXs2aacotN+tVhRkx q41q153OPp2qO+v9LxEEkxr62cDkf5PzcgvUadQrUJLz3/nlEBHWXGXlp6qMs+WZX4YZ HLAJLrDHwc6owOyil+7viEI4VAJS9yU60UCs1JqcZDxHIqS3LPHFi9EGI5D6hH04O5u1 IOavKSuxbiL2sh1Fft8TkHt+KECYeHgXGCbmFerDwesgZeHQCIWcAdEbJmWV4kOImmBT jHOA== 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=jm46pidryHrof6nDwis5HGupXZCxO5PEaE5/8RdtG9A6OY+CVVXRws1EA4iMAu/8VS ylwhG/6b9/VtP2EXZcOs+JtyA2bVL2O/uCKltKNnzIg11paCJzHTnC6bpahTb+2aMwAF caW4fdS+rDlfPpTly2kBvVfU7ArSuxuQlmvtC2qNoyn7rraCfRztteW/hlPkah5NbMn3 +pV6+GwqIYue6r1oaxfs3Y57F2QtCoEz1wrSzc9QxOsXI+4+nU5zuL55P6ikO3N4xUMj BSO6jGBrmvdudH0RsQ9dyMsTbUvFYx6CsG2i7M4tW+Amv9R67WQurIZQ+4SmzFbQzYYO ENIw== X-Gm-Message-State: AOAM532XXxv1Jk/wK/9/tR/LJZo9HTYor2TxMCKq6stjQQ0qBYDgMiRX +N0saTnMIqPG6CX+lFKFuFWvf4lPEHo= X-Google-Smtp-Source: ABdhPJzcfdtDfeHXLN3ohm27ZGuVplWF9dZcC34aYlZBqdxL98JgSqKKBVpdbM7gB/fAl/FhQsR8HA== X-Received: by 2002:a05:6638:2686:b0:323:bbe5:4f6c with SMTP id o6-20020a056638268600b00323bbe54f6cmr10718557jat.100.1651709193468; Wed, 04 May 2022 17:06:33 -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 f5-20020a056e020b4500b002cde6e352d2sm57926ilu.28.2022.05.04.17.06.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 17:06:32 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH 2/2] Bluetooth: Use bt_status to convert from errno Date: Wed, 4 May 2022 17:06:29 -0700 Message-Id: <20220505000629.2903297-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220505000629.2903297-1-luiz.dentz@gmail.com> References: <20220505000629.2903297-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);