Re: [PATCH BlueZ v4 7/8] device: Better error when the link key is missing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Bastien,

On Tue, Jul 1, 2025 at 6:20 AM Bastien Nocera <hadess@xxxxxxxxxx> wrote:
>
> Add a more precise error when the link key is missing for a
> profile or device we're trying to connect to.
> ---
>  doc/org.bluez.Device.rst |  2 ++
>  src/device.c             | 12 ++++++------
>  src/error.c              | 27 ++++++++++++++++++++++-----
>  src/error.h              |  3 +--
>  4 files changed, 31 insertions(+), 13 deletions(-)
>
> diff --git a/doc/org.bluez.Device.rst b/doc/org.bluez.Device.rst
> index b36a49eabdd5..d4de78a47239 100644
> --- a/doc/org.bluez.Device.rst
> +++ b/doc/org.bluez.Device.rst
> @@ -50,6 +50,8 @@ Possible errors:
>  :org.bluez.Error.InProgress:
>  :org.bluez.Error.AlreadyConnected:
>  :org.bluez.Error.ProfileUnavailable:
> +:org.bluez.Error.BrConnectionKeyMissing:
> +:org.bluez.Error.LeConnectionKeyMissing:

Id go with org.bluez.Error.BREDR.KeyMissing and org.bluez.Error.LE.KeyMissing

>
>  void Disconnect()
>  `````````````````
> diff --git a/src/device.c b/src/device.c
> index d7a859f9df3f..3bad7fb2c77c 100644
> --- a/src/device.c
> +++ b/src/device.c
> @@ -1982,14 +1982,14 @@ void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
>         }
>
>         if (device->connect) {
> -               const char *err_str;
>                 DBusMessage *reply;
>
> -               if (device->bonding_status == MGMT_STATUS_AUTH_FAILED)
> -                       err_str = ERR_BREDR_CONN_KEY_MISSING;
> -               else
> -                       err_str = ERR_BREDR_CONN_CANCELED;
> -               reply = btd_error_failed(device->connect, err_str);
> +               if (device->bonding_status == MGMT_STATUS_AUTH_FAILED) {
> +                       reply = btd_error_br_connection_key_missing(device->connect);
> +               } else {
> +                       reply = btd_error_failed(device->connect,
> +                                               ERR_BREDR_CONN_CANCELED);
> +               }
>                 g_dbus_send_message(dbus_conn, reply);
>                 dbus_message_unref(device->connect);
>                 device->bonding_status = 0;
> diff --git a/src/error.c b/src/error.c
> index 8070bc6107ae..596ea4280991 100644
> --- a/src/error.c
> +++ b/src/error.c
> @@ -136,6 +136,20 @@ DBusMessage *btd_error_profile_unavailable(DBusMessage *msg)
>                                         "profiles to connect to");
>  }
>
> +DBusMessage *btd_error_br_connection_key_missing(DBusMessage *msg)
> +{
> +       return g_dbus_create_error(msg, ERROR_INTERFACE
> +                                       ".BrConnectionKeyMissing",
> +                                       "BR/EDR Link Key missing");
> +}
> +
> +static DBusMessage *btd_error_le_connection_key_missing(DBusMessage *msg)
> +{
> +       return g_dbus_create_error(msg, ERROR_INTERFACE
> +                                       ".LeConnectionKeyMissing",
> +                                       "LE Link Key missing");
> +}
> +
>  DBusMessage *btd_error_failed(DBusMessage *msg, const char *str)
>  {
>         return g_dbus_create_error(msg, ERROR_INTERFACE
> @@ -177,8 +191,6 @@ static const char *btd_error_str_bredr_conn_from_errno(int errno_code)
>                 return ERR_BREDR_CONN_ABORT_BY_LOCAL;
>         case EPROTO:
>                 return ERR_BREDR_CONN_LMP_PROTO_ERROR;
> -       case EBADE:
> -               return ERR_BREDR_CONN_KEY_MISSING;
>         default:
>                 return ERR_BREDR_CONN_UNKNOWN;
>         }
> @@ -217,8 +229,6 @@ static const char *btd_error_str_le_conn_from_errno(int errno_code)
>                 return ERR_LE_CONN_ABORT_BY_LOCAL;
>         case EPROTO:
>                 return ERR_LE_CONN_LL_PROTO_ERROR;
> -       case EBADE:
> -               return ERR_LE_CONN_KEY_MISSING;
>         default:
>                 return ERR_LE_CONN_UNKNOWN;
>         }
> @@ -227,6 +237,8 @@ static const char *btd_error_str_le_conn_from_errno(int errno_code)
>  DBusMessage *btd_error_bredr_conn_from_errno(DBusMessage *msg, int errno_code)
>  {
>         switch (-errno_code) {
> +       case EBADE:
> +               return btd_error_br_connection_key_missing(msg);
>         case ENOPROTOOPT:
>                 return btd_error_profile_unavailable(msg);
>         default:
> @@ -237,6 +249,11 @@ DBusMessage *btd_error_bredr_conn_from_errno(DBusMessage *msg, int errno_code)
>
>  DBusMessage *btd_error_le_conn_from_errno(DBusMessage *msg, int errno_code)
>  {
> -       return btd_error_failed(msg,
> +       switch (-errno_code) {
> +       case EBADE:
> +               return btd_error_le_connection_key_missing(msg);
> +       default:
> +               return btd_error_failed(msg,
>                                 btd_error_str_le_conn_from_errno(errno_code));
> +       }
>  }
> diff --git a/src/error.h b/src/error.h
> index f4ad81e5daa5..96b7a7122457 100644
> --- a/src/error.h
> +++ b/src/error.h
> @@ -41,7 +41,6 @@
>  #define ERR_BREDR_CONN_LMP_PROTO_ERROR         "br-connection-lmp-protocol-"\
>                                                 "error"
>  #define ERR_BREDR_CONN_CANCELED                        "br-connection-canceled"
> -#define ERR_BREDR_CONN_KEY_MISSING             "br-connection-key-missing"
>  #define ERR_BREDR_CONN_UNKNOWN                 "br-connection-unknown"
>
>  /* LE connection failure reasons */
> @@ -62,7 +61,6 @@
>  #define ERR_LE_CONN_LL_PROTO_ERROR     "le-connection-link-layer-protocol-"\
>                                         "error"
>  #define ERR_LE_CONN_GATT_BROWSE                "le-connection-gatt-browsing"
> -#define ERR_LE_CONN_KEY_MISSING                "le-connection-key-missing"
>  #define ERR_LE_CONN_UNKNOWN            "le-connection-unknown"
>
>  DBusMessage *btd_error_invalid_args(DBusMessage *msg);
> @@ -84,6 +82,7 @@ DBusMessage *btd_error_agent_not_available(DBusMessage *msg);
>  DBusMessage *btd_error_not_ready(DBusMessage *msg);
>  DBusMessage *btd_error_not_ready_str(DBusMessage *msg, const char *str);
>  DBusMessage *btd_error_profile_unavailable(DBusMessage *msg);
> +DBusMessage *btd_error_br_connection_key_missing(DBusMessage *msg);
>  DBusMessage *btd_error_failed(DBusMessage *msg, const char *str);
>  DBusMessage *btd_error_bredr_conn_from_errno(DBusMessage *msg, int errno_code);
>  DBusMessage *btd_error_le_conn_from_errno(DBusMessage *msg, int errno_code);
> --
> 2.50.0
>
>


-- 
Luiz Augusto von Dentz





[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux