linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/3] hciattach: add common debug print functions and toggle option
@ 2012-05-23  4:35 Tedd Ho-Jeong An
  2012-05-29 16:51 ` Tedd Ho-Jeong An
  0 siblings, 1 reply; 2+ messages in thread
From: Tedd Ho-Jeong An @ 2012-05-23  4:35 UTC (permalink / raw)
  To: linux-bluetooth, marcel; +Cc: tedd.an

From: Tedd Ho-Jeong An <tedd.an@intel.com>

This adds common debug print functions that print the debug messages
to stderr and it can be toggled with'-d' option in the parameter.

It provides two functions: one for message and the other for data contents.

---
 tools/hciattach.8 |    4 ++++
 tools/hciattach.c |   39 ++++++++++++++++++++++++++++++++++++---
 tools/hciattach.h |    5 ++++-
 3 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/tools/hciattach.8 b/tools/hciattach.8
index cc97cad..eccbc61 100644
--- a/tools/hciattach.8
+++ b/tools/hciattach.8
@@ -6,6 +6,7 @@ hciattach \- attach serial devices via UART HCI to BlueZ stack
 .RB [\| \-b \|]
 .RB [\| \-n \|]
 .RB [\| \-p \|]
+.RB [\| \-d \|]
 .RB [\| \-t
 .IR timeout \|]
 .RB [\| \-s
@@ -32,6 +33,9 @@ Don't detach from controlling terminal.
 .B \-p
 Print the PID when detaching.
 .TP
+.B \-d
+Print debug messages to stderr.
+.TP
 .BI \-t " timeout"
 Specify an initialization timeout.  (Default is 5 seconds.)
 .TP
diff --git a/tools/hciattach.c b/tools/hciattach.c
index 3e73956..e0a58de 100644
--- a/tools/hciattach.c
+++ b/tools/hciattach.c
@@ -42,6 +42,7 @@
 #include <sys/poll.h>
 #include <sys/param.h>
 #include <sys/ioctl.h>
+#include <stdarg.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
@@ -73,6 +74,8 @@ struct uart_t {
 
 static volatile sig_atomic_t __io_canceled = 0;
 
+static int debug;
+
 static void sig_hup(int sig)
 {
 }
@@ -144,6 +147,31 @@ static int uart_speed(int s)
 	}
 }
 
+void dbg_print(const char *fmt, ...)
+{
+	va_list args;
+
+	if (debug) {
+		fprintf(stderr, "dbg: ");
+		va_start(args, fmt);
+		vfprintf(stderr, fmt, args);
+		va_end(args);
+		fprintf(stderr, "\n");
+	}
+}
+
+void dbg_print_pkt(char *str, unsigned char *data, int len)
+{
+	int i;
+
+	if (debug) {
+		fprintf(stderr, "dbg: %s", str);
+		for (i = 0; i < len; i++)
+			fprintf(stderr, "%02x ", data[i]);
+		fprintf(stderr, "\n");
+	}
+}
+
 int set_speed(int fd, struct termios *ti, int speed)
 {
 	if (cfsetospeed(ti, uart_speed(speed)) < 0)
@@ -161,7 +189,7 @@ int set_speed(int fd, struct termios *ti, int speed)
 /*
  * Read an HCI event from the given file descriptor.
  */
-int read_hci_event(int fd, unsigned char* buf, int size)
+int read_hci_event(int fd, unsigned char *buf, int size)
 {
 	int remain, r;
 	int count = 0;
@@ -1260,7 +1288,7 @@ static void usage(void)
 {
 	printf("hciattach - HCI UART driver initialization utility\n");
 	printf("Usage:\n");
-	printf("\thciattach [-n] [-p] [-b] [-r] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
+	printf("\thciattach [-n] [-p] [-b] [-r] [-d] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
 	printf("\thciattach -l\n");
 }
 
@@ -1280,8 +1308,9 @@ int main(int argc, char *argv[])
 	detach = 1;
 	printpid = 0;
 	raw = 0;
+	debug = 0;
 
-	while ((opt=getopt(argc, argv, "bnpt:s:lr")) != EOF) {
+	while ((opt=getopt(argc, argv, "bnpdt:s:lr")) != EOF) {
 		switch(opt) {
 		case 'b':
 			send_break = 1;
@@ -1314,6 +1343,10 @@ int main(int argc, char *argv[])
 			raw = 1;
 			break;
 
+		case 'd':
+			debug = 1;
+			break;
+
 		default:
 			usage();
 			exit(1);
diff --git a/tools/hciattach.h b/tools/hciattach.h
index a24dbc4..a9a0d02 100644
--- a/tools/hciattach.h
+++ b/tools/hciattach.h
@@ -44,7 +44,10 @@
 #define HCI_UART_RESET_ON_INIT	1
 #define HCI_UART_CREATE_AMP	2
 
-int read_hci_event(int fd, unsigned char* buf, int size);
+void dbg_print(const char *fmt, ...);
+void dbg_print_pkt(char *str, unsigned char *data, int len);
+
+int read_hci_event(int fd, unsigned char *buf, int size);
 int set_speed(int fd, struct termios *ti, int speed);
 
 int texas_init(int fd, int *speed, struct termios *ti);
-- 
1.7.9.5

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

* Re: [PATCH v2 1/3] hciattach: add common debug print functions and toggle option
  2012-05-23  4:35 [PATCH v2 1/3] hciattach: add common debug print functions and toggle option Tedd Ho-Jeong An
@ 2012-05-29 16:51 ` Tedd Ho-Jeong An
  0 siblings, 0 replies; 2+ messages in thread
From: Tedd Ho-Jeong An @ 2012-05-29 16:51 UTC (permalink / raw)
  To: linux-bluetooth, marcel

Mracel.

I sent out the v2 of patches(total 3) after updating with your comment.

Let me know if you have any further comments.

Tedd

On Tuesday, May 22, 2012 09:35:35 PM you wrote:
> From: Tedd Ho-Jeong An <tedd.an@intel.com>
> 
> This adds common debug print functions that print the debug messages
> to stderr and it can be toggled with'-d' option in the parameter.
> 
> It provides two functions: one for message and the other for data contents.
> 
> ---
>  tools/hciattach.8 |    4 ++++
>  tools/hciattach.c |   39 ++++++++++++++++++++++++++++++++++++---
>  tools/hciattach.h |    5 ++++-
>  3 files changed, 44 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/hciattach.8 b/tools/hciattach.8
> index cc97cad..eccbc61 100644
> --- a/tools/hciattach.8
> +++ b/tools/hciattach.8
> @@ -6,6 +6,7 @@ hciattach \- attach serial devices via UART HCI to BlueZ stack
>  .RB [\| \-b \|]
>  .RB [\| \-n \|]
>  .RB [\| \-p \|]
> +.RB [\| \-d \|]
>  .RB [\| \-t
>  .IR timeout \|]
>  .RB [\| \-s
> @@ -32,6 +33,9 @@ Don't detach from controlling terminal.
>  .B \-p
>  Print the PID when detaching.
>  .TP
> +.B \-d
> +Print debug messages to stderr.
> +.TP
>  .BI \-t " timeout"
>  Specify an initialization timeout.  (Default is 5 seconds.)
>  .TP
> diff --git a/tools/hciattach.c b/tools/hciattach.c
> index 3e73956..e0a58de 100644
> --- a/tools/hciattach.c
> +++ b/tools/hciattach.c
> @@ -42,6 +42,7 @@
>  #include <sys/poll.h>
>  #include <sys/param.h>
>  #include <sys/ioctl.h>
> +#include <stdarg.h>
>  
>  #include <bluetooth/bluetooth.h>
>  #include <bluetooth/hci.h>
> @@ -73,6 +74,8 @@ struct uart_t {
>  
>  static volatile sig_atomic_t __io_canceled = 0;
>  
> +static int debug;
> +
>  static void sig_hup(int sig)
>  {
>  }
> @@ -144,6 +147,31 @@ static int uart_speed(int s)
>  	}
>  }
>  
> +void dbg_print(const char *fmt, ...)
> +{
> +	va_list args;
> +
> +	if (debug) {
> +		fprintf(stderr, "dbg: ");
> +		va_start(args, fmt);
> +		vfprintf(stderr, fmt, args);
> +		va_end(args);
> +		fprintf(stderr, "\n");
> +	}
> +}
> +
> +void dbg_print_pkt(char *str, unsigned char *data, int len)
> +{
> +	int i;
> +
> +	if (debug) {
> +		fprintf(stderr, "dbg: %s", str);
> +		for (i = 0; i < len; i++)
> +			fprintf(stderr, "%02x ", data[i]);
> +		fprintf(stderr, "\n");
> +	}
> +}
> +
>  int set_speed(int fd, struct termios *ti, int speed)
>  {
>  	if (cfsetospeed(ti, uart_speed(speed)) < 0)
> @@ -161,7 +189,7 @@ int set_speed(int fd, struct termios *ti, int speed)
>  /*
>   * Read an HCI event from the given file descriptor.
>   */
> -int read_hci_event(int fd, unsigned char* buf, int size)
> +int read_hci_event(int fd, unsigned char *buf, int size)
>  {
>  	int remain, r;
>  	int count = 0;
> @@ -1260,7 +1288,7 @@ static void usage(void)
>  {
>  	printf("hciattach - HCI UART driver initialization utility\n");
>  	printf("Usage:\n");
> -	printf("\thciattach [-n] [-p] [-b] [-r] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
> +	printf("\thciattach [-n] [-p] [-b] [-r] [-d] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]\n");
>  	printf("\thciattach -l\n");
>  }
>  
> @@ -1280,8 +1308,9 @@ int main(int argc, char *argv[])
>  	detach = 1;
>  	printpid = 0;
>  	raw = 0;
> +	debug = 0;
>  
> -	while ((opt=getopt(argc, argv, "bnpt:s:lr")) != EOF) {
> +	while ((opt=getopt(argc, argv, "bnpdt:s:lr")) != EOF) {
>  		switch(opt) {
>  		case 'b':
>  			send_break = 1;
> @@ -1314,6 +1343,10 @@ int main(int argc, char *argv[])
>  			raw = 1;
>  			break;
>  
> +		case 'd':
> +			debug = 1;
> +			break;
> +
>  		default:
>  			usage();
>  			exit(1);
> diff --git a/tools/hciattach.h b/tools/hciattach.h
> index a24dbc4..a9a0d02 100644
> --- a/tools/hciattach.h
> +++ b/tools/hciattach.h
> @@ -44,7 +44,10 @@
>  #define HCI_UART_RESET_ON_INIT	1
>  #define HCI_UART_CREATE_AMP	2
>  
> -int read_hci_event(int fd, unsigned char* buf, int size);
> +void dbg_print(const char *fmt, ...);
> +void dbg_print_pkt(char *str, unsigned char *data, int len);
> +
> +int read_hci_event(int fd, unsigned char *buf, int size);
>  int set_speed(int fd, struct termios *ti, int speed);
>  
>  int texas_init(int fd, int *speed, struct termios *ti);
> 

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

end of thread, other threads:[~2012-05-29 16:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-23  4:35 [PATCH v2 1/3] hciattach: add common debug print functions and toggle option Tedd Ho-Jeong An
2012-05-29 16:51 ` Tedd Ho-Jeong An

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).