Bluetooth: Return success instead of EALREADY for mgmt commands
Subsystems (2)
PATCH 1/3 Bluetooth: Return success instead of EALREADY for mgmt commands
From: Johan Hedberg <[email protected]>
When the adapter state is already what is requested it's more friendly to user-space to simply report success than to send a EALREADY error message.
--- net/bluetooth/mgmt.c | 26 ++++++++++++++------------ 1 files changed, 14 insertions(+), 12 deletions(-)
net/bluetooth/mgmt.c +14 -12
@@ -290,6 +290,15 @@ static void mgmt_pending_remove(struct pending_cmd *cmd)mgmt_pending_free (cmd); } +static int send_mode_rsp (struct sock *sk,u16 opcode,u16 index,u8 val) +{ +struct mgmt_mode rp; + + rp.val = val; + +return cmd_complete (sk, index, opcode, &rp,sizeof (rp)); +} +static int set_powered (struct sock *sk,u16 index,unsigned char *data,u16 len) {struct mgmt_mode *cp;
@@ -312,7 +321,7 @@ static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len) up =test_bit (HCI_UP , &hdev->flags);if ((cp->val && up) || (!cp->val && !up)) { - err =cmd_status (sk, index,MGMT_OP_SET_POWERED ,EALREADY ); + err =send_mode_rsp (sk, index,MGMT_OP_SET_POWERED , cp->val); goto failed; }
@@ -375,7 +384,8 @@ static int set_discoverable(struct sock *sk, u16 index, unsigned char *data,if (cp->val ==test_bit (HCI_ISCAN , &hdev->flags) &&test_bit (HCI_PSCAN , &hdev->flags)) { - err =cmd_status (sk, index,MGMT_OP_SET_DISCOVERABLE ,EALREADY ); + err =send_mode_rsp (sk, index,MGMT_OP_SET_DISCOVERABLE , + cp->val); goto failed; }
@@ -440,7 +450,8 @@ static int set_connectable(struct sock *sk, u16 index, unsigned char *data, }if (cp->val ==test_bit (HCI_PSCAN , &hdev->flags)) { - err =cmd_status (sk, index,MGMT_OP_SET_CONNECTABLE ,EALREADY ); + err =send_mode_rsp (sk, index,MGMT_OP_SET_CONNECTABLE , + cp->val); goto failed; }
@@ -495,15 +506,6 @@ static int mgmt_event(u16 event, struct hci_dev *hdev, void *data,return 0 ; } -static int send_mode_rsp (struct sock *sk,u16 opcode,u16 index,u8 val) -{ -struct mgmt_mode rp; - - rp.val = val; - -return cmd_complete (sk, index, opcode, &rp,sizeof (rp)); -} -static int set_pairable (struct sock *sk,u16 index,unsigned char *data,u16 len) {
Signature · 1 line
1.7.7.2
PATCH 2/3 Bluetooth: Create a unique mgmt error code hierarchy
From: Johan Hedberg <[email protected]>
The management protocol uses a single byte for error codes (aka command status). In some places this value is directly copied from HCI and in other a POSIX error number is used. This makes it impossible for user-space to uniquily decipher the meaning of an error.
To solve this issue a new mgmt-specific set of error codes is added along with a conversion table for HCI status values.
--- include/net/bluetooth/mgmt.h | 17 +++ net/bluetooth/mgmt.c | 318 ++++++++++++++++++++++++++++++------------ 2 files changed, 244 insertions(+), 91 deletions(-)
include/net/bluetooth/mgmt.h +17 -0
@@ -23,6 +23,23 @@#define MGMT_INDEX_NONE 0xFFFF +#define MGMT_STATUS_SUCCESS 0x00 +#define MGMT_STATUS_UNKNOWN_COMMAND 0x01 +#define MGMT_STATUS_NOT_CONNECTED 0x02 +#define MGMT_STATUS_FAILED 0x03 +#define MGMT_STATUS_CONNECT_FAILED 0x04 +#define MGMT_STATUS_AUTH_FAILED 0x05 +#define MGMT_STATUS_NOT_PAIRED 0x06 +#define MGMT_STATUS_NO_RESOURCES 0x07 +#define MGMT_STATUS_TIMEOUT 0x08 +#define MGMT_STATUS_ALREADY_CONNECTED 0x09 +#define MGMT_STATUS_BUSY 0x0a +#define MGMT_STATUS_REJECTED 0x0b +#define MGMT_STATUS_NOT_SUPPORTED 0x0c +#define MGMT_STATUS_INVALID_PARAMS 0x0d +#define MGMT_STATUS_DISCONNECTED 0x0e +#define MGMT_STATUS_NOT_POWERED 0x0f +struct mgmt_hdr {__le16 opcode;__le16 index;
net/bluetooth/mgmt.c +227 -91
793 lines not on this page · raw message
Signature · 1 line
1.7.7.2
Re: [PATCH 2/3] Bluetooth: Create a unique mgmt error code hierarchy
Hi Johan,
net/bluetooth/mgmt.c line 40
Quoted 4 lines · On Fri, Nov 11, 2011 at 10:18 AM, <[email protected]> wrote:
net/bluetooth/mgmt.c +4
-0+#ifndef NELEM +#define NELEM (arr) (sizeof(arr) / sizeof((arr)[0])) +#endif +
What about using ARRAY_SIZE() from kernel.h ?
include/linux/kernel.h:#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
Regards,
Signature · 3 lines
Anderson Lizardo Instituto Nokia de Tecnologia - INdT Manaus - Brazil
Re: [PATCH 2/3] Bluetooth: Create a unique mgmt error code hierarchy
Hi Lizardo,
Quoted 10 lines · Anderson Lizardo
net/bluetooth/mgmt.c line 40
Quoted 4 lines · On Fri, Nov 11, 2011 at 10:18 AM, <[email protected]> wrote:
net/bluetooth/mgmt.c +4
-0+#ifndef NELEM +#define NELEM (arr) (sizeof(arr) / sizeof((arr)[0])) +#endif +What about using
ARRAY_SIZE()fromkernel.h?include/linux/kernel.h:#define
ARRAY_SIZE(arr)(sizeof(arr) / sizeof((arr)[0]) +__must_be_array(arr))
Yeah, I was looking for something like that but failed to find it. Thanks for the pointer! I'll send an updated patch soon.
Johan
PATCH v2 1/1 Bluetooth: Create a unique mgmt error code hierarchy
In reply to [email protected]From: Johan Hedberg <[email protected]>
The management protocol uses a single byte for error codes (aka command status). In some places this value is directly copied from HCI and in other a POSIX error number is used. This makes it impossible for user-space to uniquily decipher the meaning of an error.
To solve this issue a new mgmt-specific set of error codes is added along with a conversion table for HCI status values.
---
v2: Use ARRAY_SIZE() instead of a custom NELEM()
include/net/bluetooth/mgmt.h | 17 +++ net/bluetooth/mgmt.c | 315 ++++++++++++++++++++++++++++++------------ 2 files changed, 241 insertions(+), 91 deletions(-)
include/net/bluetooth/mgmt.h +17 -0
@@ -23,6 +23,23 @@#define MGMT_INDEX_NONE 0xFFFF +#define MGMT_STATUS_SUCCESS 0x00 +#define MGMT_STATUS_UNKNOWN_COMMAND 0x01 +#define MGMT_STATUS_NOT_CONNECTED 0x02 +#define MGMT_STATUS_FAILED 0x03 +#define MGMT_STATUS_CONNECT_FAILED 0x04 +#define MGMT_STATUS_AUTH_FAILED 0x05 +#define MGMT_STATUS_NOT_PAIRED 0x06 +#define MGMT_STATUS_NO_RESOURCES 0x07 +#define MGMT_STATUS_TIMEOUT 0x08 +#define MGMT_STATUS_ALREADY_CONNECTED 0x09 +#define MGMT_STATUS_BUSY 0x0a +#define MGMT_STATUS_REJECTED 0x0b +#define MGMT_STATUS_NOT_SUPPORTED 0x0c +#define MGMT_STATUS_INVALID_PARAMS 0x0d +#define MGMT_STATUS_DISCONNECTED 0x0e +#define MGMT_STATUS_NOT_POWERED 0x0f +struct mgmt_hdr {__le16 opcode;__le16 index;
net/bluetooth/mgmt.c +224 -91
790 lines not on this page · raw message
Signature · 1 line
1.7.7.2
Re: [PATCH v2] Bluetooth: Create a unique mgmt error code hierarchy
Hi Johan,
Quoted 9 lines · On Nov 11, 2011, at 1:10 PM, [email protected] wrote:
From: Johan Hedberg <[email protected]>
The management protocol uses a single byte for error codes (aka command status). In some places this value is directly copied from HCI and in other a POSIX error number is used. This makes it impossible for user-space to uniquily decipher the meaning of an error.
To solve this issue a new mgmt-specific set of error codes is added along with a conversion table for HCI status values.
Using _only_ POSIX error codes in management protocol doesn't solve this problems? We could use the bt_to_errno() function to translate HCI errors into POSIX errors.
BR,
Andre
Re: [PATCH v2] Bluetooth: Create a unique mgmt error code hierarchy
Hi Andre,
Quoted 11 lines · Andre Guedes
Quoted 7 lines
The management protocol uses a single byte for error codes (aka command status). In some places this value is directly copied from HCI and in other a POSIX error number is used. This makes it impossible for user-space to uniquily decipher the meaning of an error.
To solve this issue a new mgmt-specific set of error codes is added along with a conversion table for HCI status values.
Using _only_ POSIX error codes in management protocol doesn't solve this problems? We could use the
bt_to_errno()function to translate HCI errors into POSIX errors.
I think it's a bit too risky to restrict ourself to POSIX for all possible Bluetooth errors we may need to communicate to user-space. Considering that we still haven't added HS and LE based procedures to the protocol at least I'm not willing to bet that POSIX is enough, or at least that we'd get an intuitive mapping for it. Using our own codes gives us flexibility in the long run and it also allows for more clear and intuitive error names which you don't need to go digging in the kernel source to figure out exactly what HCI error they map to.
Johan
Re: [PATCH v2] Bluetooth: Create a unique mgmt error code hierarchy
In reply to [email protected]Hi Johan,
Quoted 10 lines · * [email protected] <[email protected]> [2011-11-11 18:10:00 +0200]:
From: Johan Hedberg <[email protected]>
The management protocol uses a single byte for error codes (aka command status). In some places this value is directly copied from HCI and in other a POSIX error number is used. This makes it impossible for user-space to uniquily decipher the meaning of an error.
To solve this issue a new mgmt-specific set of error codes is added along with a conversion table for HCI status values.
Quoted 7 lines
Signed-off-by Johan Hedberg <[email protected]>---
v2: UseARRAY_SIZE()instead of a customNELEM()include/net/bluetooth/mgmt.h | 17 +++ net/bluetooth/mgmt.c | 315 ++++++++++++++++++++++++++++++------------ 2 files changed, 241 insertions(+), 91 deletions(-)
It doesn't apply anymore, please rebase.
Gustavo
Re: [PATCH v2] Bluetooth: Create a unique mgmt error code hierarchy
Hi Gustavo,
Quoted 14 lines · Gustavo Padovan
Quoted 14 lines
From: Johan Hedberg <[email protected]>
The management protocol uses a single byte for error codes (aka command status). In some places this value is directly copied from HCI and in other a POSIX error number is used. This makes it impossible for user-space to uniquily decipher the meaning of an error.
To solve this issue a new mgmt-specific set of error codes is added along with a conversion table for HCI status values.
Signed-off-by Johan Hedberg <[email protected]>---
v2: UseARRAY_SIZE()instead of a customNELEM()
Quoted 5 lines
Quoted 3 lines
include/net/bluetooth/mgmt.h | 17 +++ net/bluetooth/mgmt.c | 315 ++++++++++++++++++++++++++++++------------ 2 files changed, 241 insertions(+), 91 deletions(-)It doesn't apply anymore, please rebase.
This one's also already in your tree.
commit ca69b7957bf2e3bc0acc882b837a42617498ece1
Johan
Re: [PATCH v2] Bluetooth: Create a unique mgmt error code hierarchy
Hi Johan,
Quoted 17 lines · Johan Hedberg
Hi Gustavo,
Quoted 14 lines · Gustavo Padovan
Quoted 14 lines
From: Johan Hedberg <[email protected]>
The management protocol uses a single byte for error codes (aka command status). In some places this value is directly copied from HCI and in other a POSIX error number is used. This makes it impossible for user-space to uniquily decipher the meaning of an error.
To solve this issue a new mgmt-specific set of error codes is added along with a conversion table for HCI status values.
Signed-off-by Johan Hedberg <[email protected]>---
v2: UseARRAY_SIZE()instead of a customNELEM()
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
include/net/bluetooth/mgmt.h | 17 +++ net/bluetooth/mgmt.c | 315 ++++++++++++++++++++++++++++++------------ 2 files changed, 241 insertions(+), 91 deletions(-)It doesn't apply anymore, please rebase.
This one's also already in your tree.
commitca69b7957bf2e3bc0acc882b837a42617498ece1
Oh, I get lost, people are sending so many patches and I forgot to reply here when I applied the patches.
Gustavo
PATCH 3/3 Bluetooth: Add missing cmd_complete for mgmt_load_link_keys
In reply to [email protected]From: Johan Hedberg <[email protected]>
The command complete event was completely missing for this command.
--- net/bluetooth/mgmt.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
net/bluetooth/mgmt.c +2 -0
@@ -1055,6 +1055,8 @@ static int load_link_keys(struct sock *sk, u16 index, unsigned char *data, key->pin_len); } +cmd_complete (sk, index,MGMT_OP_LOAD_LINK_KEYS ,NULL ,0 ); +hci_dev_unlock_bh (hdev);hci_dev_put (hdev);
Signature · 1 line
1.7.7.2
Re: [PATCH 3/3] Bluetooth: Add missing cmd_complete for mgmt_load_link_keys
Hi Johan,
Quoted 8 lines · * [email protected] <[email protected]> [2011-11-11 16:18:54 +0200]:
From: Johan Hedberg <[email protected]>
The command complete event was completely missing for this command.
Signed-off-by Johan Hedberg <[email protected]>--- net/bluetooth/mgmt.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
Patches 1 and 3 are applied. thanks.
Gustavo