monitor: Add frame number support
Luiz Augusto von Dentz
maintainerPATCH 1/3 monitor: Add frame number support
From: Luiz Augusto von Dentz <[email protected]>
This adds -f/--frames options which can be used to show the frame number:
Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4 #86 [hci1] 13:00:02.639412
LE Set Scan Parameters (0x08|0x000b) ncmd 1
Status: Success (0x00)
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2 #87 [hci1] 13:00:02.639663
Scanning: Enabled (0x01)
Filter duplicates: Enabled (0x01)Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4 #88 [hci1] 13:00:02.640420
LE Set Scan Enable (0x08|0x000c) ncmd 2
Status: Success (0x00)
---
monitor/main.c | 7 ++++++-
monitor/packet.c | 37 +++++++++++++++++++++++++++----------
monitor/packet.h | 1 +
3 files changed, 34 insertions(+), 11 deletions(-)monitor/main.c +6 -1
@@ -70,6 +70,7 @@ static void usage(void)"\t-T, --date Show time and date information\n" "\t-S, --sco Dump SCO traffic\n" "\t-E, --ellisys [ip] Send Ellisys HCI Injection\n" +"\t-f, --frames Show frame counter\n" "\t-h, --help Show help options\n"); }
@@ -86,6 +87,7 @@ static const struct option main_options[] = { { "date", no_argument, NULL, 'T' }, { "sco", no_argument, NULL, 'S' }, { "ellisys", required_argument, NULL, 'E' }, + { "frames", no_argument, NULL, 'f' }, { "todo", no_argument, NULL, '#' }, { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' },
@@ -113,7 +115,7 @@ int main(int argc, char *argv[])for (;;) {int opt; - opt =getopt_long (argc, argv,"d:r:w:a:s:p:i:tTSE:vh" , + opt =getopt_long (argc, argv,"d:r:w:a:s:p:i:tfTSE:vh" , main_options,NULL );if (opt <0 )break ;
@@ -171,6 +173,9 @@ int main(int argc, char *argv[]) ellisys_server = optarg; ellisys_port =24352 ;break ; +case 'f' : + filter_mask |=PACKET_FILTER_SHOW_FRAME ; +break ;case '#' :packet_todo ();lmp_todo ();
monitor/packet.c +27 -10
@@ -58,6 +58,7 @@#include "packet.h" #define COLOR_CHANNEL_LABEL COLOR_WHITE +#define COLOR_FRAME_LABEL COLOR_WHITE#define COLOR_INDEX_LABEL COLOR_WHITE#define COLOR_TIMESTAMP COLOR_YELLOW
@@ -259,6 +260,18 @@ void packet_select_index(uint16_t index)#define print_space (x) printf("%*c", (x), ' '); +#define MAX_INDEX 16 + +struct index_data { +uint8_t type; +uint8_t bdaddr[6 ]; +uint16_t manufacturer; +size_t frame; +}; + +static struct index_data index_list[MAX_INDEX ]; + + static void print_packet(struct timeval *tv, struct ucred *cred, char ident, uint16_t index, const char *channel, const char *color, const char *label,
@@ -280,6 +293,20 @@ static void print_packet(struct timeval *tv, struct ucred *cred, char ident, ts_pos += n; ts_len += n; } + }else if (filter_mask &PACKET_FILTER_SHOW_FRAME && + (ident =='<' || ident =='>' )) { +if (use_color ()) { + n =sprintf (ts_str + ts_pos,"%s" ,COLOR_FRAME_LABEL ); +if (n >0 ) + ts_pos += n; + } + + n =sprintf (ts_str + ts_pos," #%zu" , + ++index_list[index].frame); +if (n >0 ) { + ts_pos += n; + ts_len += n; + } } if ((filter_mask & PACKET_FILTER_SHOW_INDEX) &&
@@ -3828,16 +3855,6 @@ static int addr2str(const uint8_t *addr, char *str) addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]); } -#define MAX_INDEX 16 - -struct index_data { -uint8_t type; -uint8_t bdaddr[6 ]; -uint16_t manufacturer; -}; - -static struct index_data index_list[MAX_INDEX ]; -void packet_monitor (struct timeval *tv,struct ucred *cred,uint16_t index,uint16_t opcode,const void *data,uint16_t size)
monitor/packet.h +1 -0
@@ -33,6 +33,7 @@#define PACKET_FILTER_SHOW_TIME_OFFSET (1 << 3)#define PACKET_FILTER_SHOW_ACL_DATA (1 << 4)#define PACKET_FILTER_SHOW_SCO_DATA (1 << 5) +#define PACKET_FILTER_SHOW_FRAME (1 << 6)void packet_set_filter (unsigned long filter);void packet_add_filter (unsigned long filter);
Signature · 1 line
2.9.3
Luiz Augusto von Dentz
maintainerPATCH 2/3 monitor: Fix not decoding control frames
From: Luiz Augusto von Dentz <[email protected]>
In order to enable decoding control frames packet_monitor needs to check if the index is set to HCI_DEV_NONE since that will call packet_ctrl_open which setups the ctrl and assign it a cookie.
--- monitor/packet.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
monitor/packet.c +5 -4
@@ -3866,10 +3866,11 @@ void packet_monitor(struct timeval *tv, struct ucred *cred,uint16_t manufacturer;const char *ident; -if (index_filter && index_number != index) -return ; - - index_current = index; +if (index !=HCI_DEV_NONE ) { +if (index_filter && index_number != index) +return ; + index_current = index; + }if (tv && time_offset == ((time_t) -1 )) time_offset = tv->tv_sec;
Signature · 1 line
2.9.3
Luiz Augusto von Dentz
maintainerPATCH 3/3 client: Always start an agent
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Always register agent with 'KeyboardDisplay' capability.
--- client/main.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
client/main.c +4 -14
@@ -54,6 +54,8 @@#define PROMPT_ON COLOR_BLUE "[bluetooth]" COLOR_OFF "# "#define PROMPT_OFF "Waiting to connect to bluetoothd..." +#define AGENT_CAP "KeyboardDisplay" +static GMainLoop *main_loop;static DBusConnection *dbus_conn;
@@ -2352,23 +2354,9 @@ static guint setup_signalfd(void)static gboolean option_version = FALSE; -static gboolean parse_agent (const char *key,const char *value, -gpointer user_data,GError **error) -{ -if (value) - auto_register_agent =g_strdup (value); -else - auto_register_agent =g_strdup ("" ); - -return TRUE; -} -static GOptionEntry options[] = { {"version" ,'v' ,0 ,G_OPTION_ARG_NONE , &option_version,"Show version information and exit" }, - {"agent" ,'a' ,G_OPTION_FLAG_OPTIONAL_ARG , -G_OPTION_ARG_CALLBACK , parse_agent, -"Register agent handler" ,"CAPABILITY" }, {NULL }, };
@@ -2399,6 +2387,8 @@ int main(int argc, char *argv[])g_option_context_free (context); + auto_register_agent =g_strdup (AGENT_CAP ); +if (option_version == TRUE) {printf ("%s\n" ,VERSION );exit (0 );
Signature · 1 line
2.9.3
Marcel Holtmann
maintainerRe: [PATCH BlueZ 3/3] client: Always start an agent
Hi Luiz,
Quoted 31 lines
Always register agent with 'KeyboardDisplay' capability.
---client/main.c| 18 ++++--------------1 file changed, 4 insertions(+), 14 deletions(-)client/main.c +2
-9@@ -54,6 +54,8 @@#define PROMPT_ON COLOR_BLUE "[bluetooth]" COLOR_OFF "# "#define PROMPT_OFF "Waiting to connect to bluetoothd..." +#define AGENT_CAP "KeyboardDisplay" +static GMainLoop *main_loop;static DBusConnection *dbus_conn;@@ -2352,23 +2354,9 @@ static guint setup_signalfd(void)static gboolean option_version = FALSE; -static gboolean parse_agent (const char *key,const char *value, -gpointer user_data,GError **error) -{ -if (value) - auto_register_agent =g_strdup (value); -else - auto_register_agent =g_strdup ("" ); - -return TRUE;
client/main.c static guint setup_signalfd(void) · line 2361
Quoted 10 lines
client/main.c +0
-5-} -static GOptionEntry options[] = { {"version" ,'v' ,0 ,G_OPTION_ARG_NONE , &option_version,"Show version information and exit" }, - {"agent" ,'a' ,G_OPTION_FLAG_OPTIONAL_ARG , -G_OPTION_ARG_CALLBACK , parse_agent, -"Register agent handler" ,"CAPABILITY" }, {NULL }, };
actually leave the agent option and make the argument mandatory. We should be registering with “” as agent string by default. That ensures that we use the defaults from bluetoothd and mgmt. However the command line option can overwrite the IO capability.
Regards
Marcel
Marcel Holtmann
maintainerHi Luiz,
Quoted 23 lines
This adds -f/--frames options which can be used to show the frame number:
Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4 #86 [hci1] 13:00:02.639412LE Set Scan Parameters (0x08|0x000b) ncmd 1 Status: Success (0x00) < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2 #87 [hci1] 13:00:02.639663 Scanning: Enabled (0x01) Filter duplicates: Enabled (0x01)Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4 #88 [hci1] 13:00:02.640420LE Set Scan Enable (0x08|0x000c) ncmd 2 Status: Success (0x00) --- monitor/main.c | 7 ++++++- monitor/packet.c | 37 +++++++++++++++++++++++++++---------- monitor/packet.h | 1 + 3 files changed, 34 insertions(+), 11 deletions(-)monitor/main.c +0
-0
monitor/main.c static void usage(void) · line 75
Quoted 6 lines
monitor/main.c +1
-0@@ -70,6 +70,7 @@ static void usage(void)"\t-T, --date Show time and date information\n" "\t-S, --sco Dump SCO traffic\n" "\t-E, --ellisys [ip] Send Ellisys HCI Injection\n" +"\t-f, --frames Show frame counter\n" "\t-h, --help Show help options\n"); }
I would rather use -C / --counter as frame counter.
Quoted 45 lines
monitor/main.c +5
-1@@ -86,6 +87,7 @@ static const struct option main_options[] = { { "date", no_argument, NULL, 'T' }, { "sco", no_argument, NULL, 'S' }, { "ellisys", required_argument, NULL, 'E' }, + { "frames", no_argument, NULL, 'f' }, { "todo", no_argument, NULL, '#' }, { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' },@@ -113,7 +115,7 @@ int main(int argc, char *argv[])for (;;) {int opt; - opt =getopt_long (argc, argv,"d:r:w:a:s:p:i:tTSE:vh" , + opt =getopt_long (argc, argv,"d:r:w:a:s:p:i:tfTSE:vh" , main_options,NULL );if (opt <0 )break ;@@ -171,6 +173,9 @@ int main(int argc, char *argv[]) ellisys_server = optarg; ellisys_port =24352 ;break ; +case 'f' : + filter_mask |=PACKET_FILTER_SHOW_FRAME ; +break ;case '#' :packet_todo ();lmp_todo ();monitor/packet.c +3
-0@@ -58,6 +58,7 @@#include "packet.h" #define COLOR_CHANNEL_LABEL COLOR_WHITE +#define COLOR_FRAME_LABEL COLOR_WHITE#define COLOR_INDEX_LABEL COLOR_WHITE#define COLOR_TIMESTAMP COLOR_YELLOW@@ -259,6 +260,18 @@ void packet_select_index(uint16_t index)#define print_space (x) printf("%*c", (x), ' '); +#define MAX_INDEX 16 +
monitor/packet.c void packet_select_index(uint16_t index) · line 274
Quoted 10 lines
monitor/packet.c +10
-0+struct index_data { +uint8_t type; +uint8_t bdaddr[6 ]; +uint16_t manufacturer; +size_t frame; +}; + +static struct index_data index_list[MAX_INDEX ]; + +
Too many empty lines here.
monitor/packet.c static void print_packet(struct timeval *tv, struct ucred *cred, char ident, · line 297
Quoted 9 lines
monitor/packet.c +2
-0static void print_packet(struct timeval *tv, struct ucred *cred, char ident, uint16_t index, const char *channel, const char *color, const char *label,@@ -280,6 +293,20 @@ static void print_packet(struct timeval *tv, struct ucred *cred, char ident, ts_pos += n; ts_len += n; } + }else if (filter_mask &PACKET_FILTER_SHOW_FRAME && + (ident =='<' || ident =='>' )) {
Lets not use the ident to choose here.
monitor/packet.c static void print_packet(struct timeval *tv, struct ucred *cred, char ident, · line 305
Quoted 8 lines
monitor/packet.c +8
-0+if (use_color ()) { + n =sprintf (ts_str + ts_pos,"%s" ,COLOR_FRAME_LABEL ); +if (n >0 ) + ts_pos += n; + } + + n =sprintf (ts_str + ts_pos," #%zu" , + ++index_list[index].frame);
I would prefer if we add the frame number during input and not during display of the packet. That should be kept separate. Otherwise we create a mess like in hcidump.
Quoted 29 lines
monitor/packet.c +4
-10+if (n >0 ) { + ts_pos += n; + ts_len += n; + } } if ((filter_mask & PACKET_FILTER_SHOW_INDEX) &&@@ -3828,16 +3855,6 @@ static int addr2str(const uint8_t *addr, char *str) addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]); } -#define MAX_INDEX 16 - -struct index_data { -uint8_t type; -uint8_t bdaddr[6 ]; -uint16_t manufacturer; -}; - -static struct index_data index_list[MAX_INDEX ]; -void packet_monitor (struct timeval *tv,struct ucred *cred,uint16_t index,uint16_t opcode,const void *data,uint16_t size)monitor/packet.h +0
-0
monitor/packet.h line 36
Quoted 4 lines
monitor/packet.h +1
-0@@ -33,6 +33,7 @@#define PACKET_FILTER_SHOW_TIME_OFFSET (1 << 3)#define PACKET_FILTER_SHOW_ACL_DATA (1 << 4)#define PACKET_FILTER_SHOW_SCO_DATA (1 << 5) +#define PACKET_FILTER_SHOW_FRAME (1 << 6)
Call it FRAME_COUNTER or something similar. Just FRAME is misleading. Or we might just always show the frame counter anyway. It is not really in the way.
Regards
Marcel
Luiz Augusto von Dentz
maintainerRe: [PATCH BlueZ 3/3] client: Always start an agent
In reply to Marcel HoltmannHi Marcel,
On Thu, Apr 20, 2017 at 3:52 PM, Marcel Holtmann <[email protected]> wrot= e:
Quoted 20 lines
Hi Luiz,
Quoted 18 lines
Always register agent with 'KeyboardDisplay' capability.
---client/main.c| 18 ++++--------------1 file changed, 4 insertions(+), 14 deletions(-)client/main.c +2
-0@@ -54,6 +54,8 @@#define PROMPT_ON COLOR_BLUE "[bluetooth]" COLOR_OFF "# "#define PROMPT_OFF "Waiting to connect to bluetoothd..." +#define AGENT_CAP "KeyboardDisplay" +static GMainLoop *main_loop;static DBusConnection *dbus_conn;
Quoted 6 lines
client/main.c static guint setup_signalfd(void) · line 2356
Quoted 6 lines
client/main.c +0
-2@@ -2352,23 +2354,9 @@ static guint setup_signalfd(void) static gboolean option_version =3D FALSE; -static gboolean parse_agent(const char *key, const char *value, - gpointer user_data, GError **error=
)
Quoted 11 lines
Quoted 11 lines
client/main.c +0
-9-{ -if (value) - auto_register_agent =3D g_strdup(value); -else - auto_register_agent =3D g_strdup(""); - -return TRUE; -} - static GOptionEntry options[] =3D { {"version" ,'v' ,0 ,G_OPTION_ARG_NONE , &option_version,
Quoted 8 lines
client/main.c static guint setup_signalfd(void) · line 2361
Quoted 6 lines
client/main.c +0
-3"Show version information and exit" }, - {"agent" ,'a' ,G_OPTION_FLAG_OPTIONAL_ARG , -G_OPTION_ARG_CALLBACK , parse_agent, - "Register agent handler", "CAPABILITY" }, { NULL }, };actually leave the agent option and make the argument mandatory. We shoul=
d be registering with =E2=80=9C=E2=80=9D as agent string by default. That e= nsures that we use the defaults from bluetoothd and mgmt. However the comma= nd line option can overwrite the IO capability.
Alright, will send a v2 in a moment.
Quoted 4 lines
Regards
Marcel
--=20
Luiz Augusto von Dentz
Luiz Augusto von Dentz
maintainerHi Marcel,
Quoted 77 lines · Marcel Holtmann
Hi Luiz,
Quoted 23 lines
This adds -f/--frames options which can be used to show the frame number:
Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4 #86 [hci1] 13:00:02.639412LE Set Scan Parameters (0x08|0x000b) ncmd 1 Status: Success (0x00) < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2 #87 [hci1] 13:00:02.639663 Scanning: Enabled (0x01) Filter duplicates: Enabled (0x01)Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4 #88 [hci1] 13:00:02.640420LE Set Scan Enable (0x08|0x000c) ncmd 2 Status: Success (0x00) --- monitor/main.c | 7 ++++++- monitor/packet.c | 37 +++++++++++++++++++++++++++---------- monitor/packet.h | 1 + 3 files changed, 34 insertions(+), 11 deletions(-)monitor/main.c +0
-0monitor/main.c static void usage(void) · line 75
Quoted 6 lines
monitor/main.c +1
-0@@ -70,6 +70,7 @@ static void usage(void)"\t-T, --date Show time and date information\n" "\t-S, --sco Dump SCO traffic\n" "\t-E, --ellisys [ip] Send Ellisys HCI Injection\n" +"\t-f, --frames Show frame counter\n" "\t-h, --help Show help options\n"); }I would rather use -C / --counter as frame counter.
Quoted 43 lines
monitor/main.c +5
-1@@ -86,6 +87,7 @@ static const struct option main_options[] = { { "date", no_argument, NULL, 'T' }, { "sco", no_argument, NULL, 'S' }, { "ellisys", required_argument, NULL, 'E' }, + { "frames", no_argument, NULL, 'f' }, { "todo", no_argument, NULL, '#' }, { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' },@@ -113,7 +115,7 @@ int main(int argc, char *argv[])for (;;) {int opt; - opt =getopt_long (argc, argv,"d:r:w:a:s:p:i:tTSE:vh" , + opt =getopt_long (argc, argv,"d:r:w:a:s:p:i:tfTSE:vh" , main_options,NULL );if (opt <0 )break ;@@ -171,6 +173,9 @@ int main(int argc, char *argv[]) ellisys_server = optarg; ellisys_port =24352 ;break ; +case 'f' : + filter_mask |=PACKET_FILTER_SHOW_FRAME ; +break ;case '#' :packet_todo ();lmp_todo ();monitor/packet.c +1
-0@@ -58,6 +58,7 @@#include "packet.h" #define COLOR_CHANNEL_LABEL COLOR_WHITE +#define COLOR_FRAME_LABEL COLOR_WHITE#define COLOR_INDEX_LABEL COLOR_WHITE#define COLOR_TIMESTAMP COLOR_YELLOW@@ -259,6 +260,18 @@ void packet_select_index(uint16_t index)#define print_space (x) printf("%*c", (x), ' ');
Quoted 14 lines
monitor/packet.c void packet_select_index(uint16_t index) · line 274
Quoted 12 lines
monitor/packet.c +12
-0+#define MAX_INDEX 16 + +struct index_data { +uint8_t type; +uint8_t bdaddr[6 ]; +uint16_t manufacturer; +size_t frame; +}; + +static struct index_data index_list[MAX_INDEX ]; + +Too many empty lines here.
Will fix it.
Quoted 21 lines
monitor/packet.c static void print_packet(struct timeval *tv, struct ucred *cred, char ident, · line 297
Quoted 9 lines
monitor/packet.c +2
-0static void print_packet(struct timeval *tv, struct ucred *cred, char ident, uint16_t index, const char *channel, const char *color, const char *label,@@ -280,6 +293,20 @@ static void print_packet(struct timeval *tv, struct ucred *cred, char ident, ts_pos += n; ts_len += n; } + }else if (filter_mask &PACKET_FILTER_SHOW_FRAME && + (ident =='<' || ident =='>' )) {Lets not use the ident to choose here.
monitor/packet.c static void print_packet(struct timeval *tv, struct ucred *cred, char ident, · line 305
Quoted 8 lines
monitor/packet.c +8
-0+if (use_color ()) { + n =sprintf (ts_str + ts_pos,"%s" ,COLOR_FRAME_LABEL ); +if (n >0 ) + ts_pos += n; + } + + n =sprintf (ts_str + ts_pos," #%zu" , + ++index_list[index].frame);
Quoted 1 line
I would prefer if we add the frame number during input and not during display of the packet. That should be kept separate. Otherwise we create a mess like in hcidump.
I don't quite follow the during input vs display, or do you mean we should increment directly in the io callback?
Quoted 27 lines
Quoted 27 lines
monitor/packet.c +4
-10+if (n >0 ) { + ts_pos += n; + ts_len += n; + } } if ((filter_mask & PACKET_FILTER_SHOW_INDEX) &&@@ -3828,16 +3855,6 @@ static int addr2str(const uint8_t *addr, char *str) addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]); } -#define MAX_INDEX 16 - -struct index_data { -uint8_t type; -uint8_t bdaddr[6 ]; -uint16_t manufacturer; -}; - -static struct index_data index_list[MAX_INDEX ]; -void packet_monitor (struct timeval *tv,struct ucred *cred,uint16_t index,uint16_t opcode,const void *data,uint16_t size)monitor/packet.h +0
-1--- a/monitor/packet.h
Quoted 8 lines
monitor/packet.h line 36
Quoted 6 lines
+++
b/monitor/packet.hmonitor/packet.h +1
-0@@ -33,6 +33,7 @@#define PACKET_FILTER_SHOW_TIME_OFFSET (1 << 3)#define PACKET_FILTER_SHOW_ACL_DATA (1 << 4)#define PACKET_FILTER_SHOW_SCO_DATA (1 << 5) +#define PACKET_FILTER_SHOW_FRAME (1 << 6)Call it
FRAME_COUNTERor something similar. Just FRAME is misleading. Or we might just always show the frame counter anyway. It is not really in the way.
I wondering if we should enable it by default and don't bother with the option adding yet another option.
Quoted 4 lines
Regards
Marcel
Signature · 1 line
Luiz Augusto von Dentz