linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH ] tools/gatt-client: print read/write error messages
@ 2015-02-12 14:44 Bharat Panda
  2015-02-12 14:57 ` Johan Hedberg
  0 siblings, 1 reply; 3+ messages in thread
From: Bharat Panda @ 2015-02-12 14:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: cpgs, Bharat Panda

Convert error codes to error messages for read/write value
error responses.
---
 tools/btgatt-client.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 68 insertions(+), 3 deletions(-)

diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index 8bda89b..0b937b0 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -74,6 +74,70 @@ static void print_prompt(void)
 	fflush(stdout);
 }
 
+static char *ecode_to_string(uint8_t ecode)
+{
+	char *err = NULL;
+
+	switch (ecode) {
+		case BT_ATT_ERROR_INVALID_HANDLE:
+			err = "ERROR: Invalid Handle";
+			break;
+		case BT_ATT_ERROR_READ_NOT_PERMITTED:
+			err = "Read Not Permitted";
+			break;
+		case BT_ATT_ERROR_WRITE_NOT_PERMITTED:
+			err = "Write Not Permitted";
+			break;
+		case BT_ATT_ERROR_INVALID_PDU:
+			err = "Invalid PDU";
+			break;
+		case BT_ATT_ERROR_AUTHENTICATION:
+			err = "Authentication Required";
+			break;
+		case BT_ATT_ERROR_REQUEST_NOT_SUPPORTED:
+			err = "Request Not Supported";
+			break;
+		case BT_ATT_ERROR_INVALID_OFFSET:
+			err = "Invalid Offset";
+			break;
+		case BT_ATT_ERROR_AUTHORIZATION:
+			err = "Authorization Required";
+			break;
+		case BT_ATT_ERROR_PREPARE_QUEUE_FULL:
+			err = "Prepare Write Queue Full";
+			break;
+		case BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND:
+			err = "Attribute Not Found";
+			break;
+		case BT_ATT_ERROR_ATTRIBUTE_NOT_LONG:
+			err = "Attribute Not Long";
+			break;
+		case BT_ATT_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE:
+			err = "Insuficient Encryption Key Size";
+			break;
+		case BT_ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LEN:
+			err = "Invalid Attribute value len";
+			break;
+		case BT_ATT_ERROR_UNLIKELY:
+			err = "Unlikely Error";
+			break;
+		case BT_ATT_ERROR_INSUFFICIENT_ENCRYPTION:
+			err = "Insufficient Encryption";
+			break;
+		case BT_ATT_ERROR_UNSUPPORTED_GROUP_TYPE:
+			err = "Group type Not Supported";
+			break;
+		case BT_ATT_ERROR_INSUFFICIENT_RESOURCES:
+			err = "Insufficient Resources";
+			break;
+		default:
+			err = "Unknown error type";
+			break;
+	}
+
+	return err;
+}
+
 static void att_disconnect_cb(int err, void *user_data)
 {
 	printf("Device disconnected: %s\n", strerror(err));
@@ -489,7 +553,8 @@ static void read_cb(bool success, uint8_t att_ecode, const uint8_t *value,
 	int i;
 
 	if (!success) {
-		PRLOG("\nRead request failed: 0x%02x\n", att_ecode);
+		PRLOG("\nRead request failed: %s\n",
+				ecode_to_string(att_ecode));
 		return;
 	}
 
@@ -596,7 +661,7 @@ static void write_cb(bool success, uint8_t att_ecode, void *user_data)
 	if (success) {
 		PRLOG("\nWrite successful\n");
 	} else {
-		PRLOG("\nWrite failed: 0x%02x\n", att_ecode);
+		PRLOG("\nWrite failed: %s\n", ecode_to_string(att_ecode));
 	}
 }
 
@@ -726,7 +791,7 @@ static void write_long_cb(bool success, bool reliable_error, uint8_t att_ecode,
 	} else if (reliable_error) {
 		PRLOG("Reliable write not verified\n");
 	} else {
-		PRLOG("Write failed: 0x%02x\n", att_ecode);
+		PRLOG("\nWrite failed: %s\n", ecode_to_string(att_ecode));
 	}
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH ] tools/gatt-client: print read/write error messages
  2015-02-12 14:44 [PATCH ] tools/gatt-client: print read/write error messages Bharat Panda
@ 2015-02-12 14:57 ` Johan Hedberg
  2015-02-12 15:17   ` Bharat Bhusan Panda
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hedberg @ 2015-02-12 14:57 UTC (permalink / raw)
  To: Bharat Panda; +Cc: linux-bluetooth, cpgs

Hi Bharat,

On Thu, Feb 12, 2015, Bharat Panda wrote:
> +static char *ecode_to_string(uint8_t ecode)

This should be static const char *

> +{
> +	char *err = NULL;
> +
> +	switch (ecode) {
> +		case BT_ATT_ERROR_INVALID_HANDLE:
> +			err = "ERROR: Invalid Handle";
> +			break;

First of all, please follow the coding style: the case statement should
start at the same indentation as the switch. Secondly, you can make this
all more compact by removing the err variable:

	case BT_ATT_ERROR_INVALID_HANDLE:
		return "Invalid Handle";
	case ...:
		return "...";

Johan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH ] tools/gatt-client: print read/write error messages
  2015-02-12 14:57 ` Johan Hedberg
@ 2015-02-12 15:17   ` Bharat Bhusan Panda
  0 siblings, 0 replies; 3+ messages in thread
From: Bharat Bhusan Panda @ 2015-02-12 15:17 UTC (permalink / raw)
  To: 'Johan Hedberg'; +Cc: linux-bluetooth, cpgs

Hi Johan,

> -----Original Message-----
> From: linux-bluetooth-owner@vger.kernel.org [mailto:linux-bluetooth-
> owner@vger.kernel.org] On Behalf Of Johan Hedberg
> Sent: Thursday, February 12, 2015 8:28 PM
> To: Bharat Panda
> Cc: linux-bluetooth@vger.kernel.org; cpgs@samsung.com
> Subject: Re: [PATCH ] tools/gatt-client: print read/write error messages
> 
> Hi Bharat,
> 
> On Thu, Feb 12, 2015, Bharat Panda wrote:
> > +static char *ecode_to_string(uint8_t ecode)
> 
> This should be static const char *
> 
> > +{
> > +	char *err = NULL;
> > +
> > +	switch (ecode) {
> > +		case BT_ATT_ERROR_INVALID_HANDLE:
> > +			err = "ERROR: Invalid Handle";
> > +			break;
> 
> First of all, please follow the coding style: the case statement should
start at
> the same indentation as the switch. Secondly, you can make this all more
> compact by removing the err variable:
> 
> 	case BT_ATT_ERROR_INVALID_HANDLE:
> 		return "Invalid Handle";
> 	case ...:
> 		return "...";
I have incorporated above review comments and submitted another version of
the patch.

Thanks.

Best Regards,
Bharat 



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-12 15:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-12 14:44 [PATCH ] tools/gatt-client: print read/write error messages Bharat Panda
2015-02-12 14:57 ` Johan Hedberg
2015-02-12 15:17   ` Bharat Bhusan Panda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).