From patchwork Tue Jun 21 19:10:30 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: 584261 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 AA9D9C43334 for ; Tue, 21 Jun 2022 19:10:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237933AbiFUTKe (ORCPT ); Tue, 21 Jun 2022 15:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbiFUTKe (ORCPT ); Tue, 21 Jun 2022 15:10:34 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D6B620F43 for ; Tue, 21 Jun 2022 12:10:33 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id l6so5195037plg.11 for ; Tue, 21 Jun 2022 12:10:33 -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=Ai4G4UB57+HKsGwyeNmVm3s1TC46XAAomFY8+BT6rnU=; b=RhHTs/GE+6Ha97196UnE4XlXxQkQbAVw/i+zaLYG36xlxSYxIEwh9oPd4CU6CjmEMq zdlWCFxbtOl9DE3ir+gPOpFcbovltkDF/uXu/pkZGE9JNwstc0TqhF4Z6cGYMWxSbb4+ FxS54C17BL6CHUTF/bqMyh+VbsNNWCrNDBMQwSrQYnLyVbvoCv7OWSxm5uJISg7B9JMU akyECoWUJnZbvRB5lT/+ojpTDLMdpVLXUzZa+TQEp9PV+ebRnrcaVHSxZRWxvzCQNNx1 kajtYTjoTZU4LU3fopxsJAVwfrV2OPk4tbKcRKOgktAn/m/mvDzrnZPrmpevaw7hNnU3 QqAQ== 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=Ai4G4UB57+HKsGwyeNmVm3s1TC46XAAomFY8+BT6rnU=; b=2oc+StaiyoeIDFp5xPzVe9NkzUXFv3+BQcJL9fQB2PJvQVMJISxDfHv/9Lz0ivFqbR raLdvbxklJ7p0BdaEffHi/tGagkSMDs9PoFYF8fPt85rAAnRqgEAxm5aq77+pYPzsOH5 FwybqbZz8hQsmQYMLbZf+UYRJZhEEjQygoMF7mAaV1jgZxHtUAaUocpVfCeEhpNqrmYc HfHmSqbPXgp9h3e6gxmlrlJ/2LiJURw+a/X9fWJB181PtOwetWwxkOgH9a5dNPPdm0Yd 0qpP5MMC/q1SKD7EtHvziHjclyBbCtSJwvF1AzRE8Oigso9smUMKWI5et6Xj+z57jCwu dyow== X-Gm-Message-State: AJIora/ZMSDJWLo+4lzxaqHO2pEBugyjmh8jXE7OdqVxGJrsjLfdCFBF fxwPjWRV+YdceLgX88bLWVfP/Z5SKhLvAQ== X-Google-Smtp-Source: AGRyM1td+DUOk2qMz84lMsfMl1V5nbeoh/yzf3No/UQTl+4P2BGi3w+pmae/f7CW/qfw1TZ5KsVR8w== X-Received: by 2002:a17:903:230a:b0:16a:4372:359 with SMTP id d10-20020a170903230a00b0016a43720359mr1268630plh.46.1655838632519; Tue, 21 Jun 2022 12:10:32 -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 y188-20020a62cec5000000b00525286c7847sm4183546pfg.216.2022.06.21.12.10.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 12:10:32 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [RESEND 1/2] Bluetooth: Add bt_status Date: Tue, 21 Jun 2022 12:10:30 -0700 Message-Id: <20220621191031.2160381-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.3 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 Tue Jun 21 19:10:31 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: 583689 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 2F4F8C433EF for ; Tue, 21 Jun 2022 19:10:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352984AbiFUTKg (ORCPT ); Tue, 21 Jun 2022 15:10:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbiFUTKf (ORCPT ); Tue, 21 Jun 2022 15:10:35 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA0CD2A942 for ; Tue, 21 Jun 2022 12:10:34 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id p3-20020a17090a428300b001ec865eb4a2so9438427pjg.3 for ; Tue, 21 Jun 2022 12:10: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=M91d+Ao3w5IAZXIjlfYZP08YquFQRILfjWGYi4V/OIo=; b=p1y4hYOTAGzBGnwtq5LdnpeqToWsmktHHijFz7TR9A55r5arPI1vPi9q4goxnq76Fl Hg59NfTwn3cvMaX7VhRYtJfawodfEMpSO8S/ak3XUTjzCxkeAaMIt++sA4YJa2RMRAMA VVIhbsM3uAjj6oPP1XSpBlXSca5f0LRKG4QrYYp8PEGi2aERu4Pv7AMUQPSpw7S5j2/t +ao8bVRY1ngdyi7Aa8oMmqcNCcWrQ0w42YJ6cgHwqRbVXY1yxZcGkqD7Hp9zoh//XV99 dKumbBkcedNiyAHIV/zCkbHmBLGKRjfrkVFcOVv0T6ChClppl+owfZJp2INCGKDOYssK DgxQ== 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=M91d+Ao3w5IAZXIjlfYZP08YquFQRILfjWGYi4V/OIo=; b=ox/uifgQl/LDeYuURp4BQK714qCcOb8txxqq3yZZdCPQhM3gbX46eBIBv+GQv0pWDm liu09khXBIXN3RFDIJs5DjGwEjv9a7QQZpAWPr7OXlvdspOuzIkOQOxOwHwU0rEazqEs jFID7R+zfd1Lv32jQ1uIOFwNbefR8QQd80HthdVcWkfYP1BG1TL1PROWK2g7gIqiuk0S 8b53VMRRXeShehixd/I0JsepwPhvDTtq90tSJF99JOuByO2YxnOlavBdDa+a96YvAqlw SBXcu0HbMBeI8Sh9Moxh6rFyYUMQaZK4Zhv3GgwMUVZHs6nBK4eDgxsjH6D5j+WAZKp/ XIMg== X-Gm-Message-State: AJIora8RpSsVhbvglUXvhZt9UOuTpD4m5yP1AW+uVGwgXlDL63Our9dv wGPAQsBODrPvVaQ7feWyRaux/mPY/wD41w== X-Google-Smtp-Source: AGRyM1v9VcZCTq6xa3L9bvbbYrjhHGYg7to8eAsTa47nEa95U3NXkFVbwn6em9D6xWpkEjvPNYVLpA== X-Received: by 2002:a17:90a:778a:b0:1ea:264c:e9af with SMTP id v10-20020a17090a778a00b001ea264ce9afmr34216718pjk.246.1655838633750; Tue, 21 Jun 2022 12:10: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 y188-20020a62cec5000000b00525286c7847sm4183546pfg.216.2022.06.21.12.10.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 12:10:33 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [RESEND 2/2] Bluetooth: Use bt_status to convert from errno Date: Tue, 21 Jun 2022 12:10:31 -0700 Message-Id: <20220621191031.2160381-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220621191031.2160381-1-luiz.dentz@gmail.com> References: <20220621191031.2160381-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 7829433d54c1..1ce89c469293 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -950,7 +950,7 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) if (conn != hci_lookup_le_connect(hdev)) goto done; - hci_conn_failed(conn, err); + hci_conn_failed(conn, bt_status(err)); done: hci_dev_unlock(hdev);