mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-26 21:54:33 +08:00
hcidump: Add extended dump functionality
This commit is contained in:
parent
239941a891
commit
eae7ac2625
@ -335,8 +335,9 @@ static void usage(void)
|
||||
" -w, --save-dump=file Save dump to a file\n"
|
||||
" -r, --read-dump=file Read dump from a file\n"
|
||||
" -t, --ts Display time stamps\n"
|
||||
" -x, --hex Dump data in hex\n"
|
||||
" -a, --ascii Dump data in ascii\n"
|
||||
" -x, --hex Dump data in hex\n"
|
||||
" -X, --ext Dump data in hex and ascii\n"
|
||||
" -R, --raw Raw mode\n"
|
||||
" -C, --cmtp=psm PSM for CMTP\n"
|
||||
" -H, --hcrp=psm PSM for HCRP\n"
|
||||
@ -352,8 +353,9 @@ static struct option main_options[] = {
|
||||
{ "save-dump", 1, 0, 'w' },
|
||||
{ "read-dump", 1, 0, 'r' },
|
||||
{ "ts", 0, 0, 't' },
|
||||
{ "hex", 0, 0, 'x' },
|
||||
{ "ascii", 0, 0, 'a' },
|
||||
{ "hex", 0, 0, 'x' },
|
||||
{ "ext", 0, 0, 'X' },
|
||||
{ "raw", 0, 0, 'R' },
|
||||
{ "cmtp", 1, 0, 'C' },
|
||||
{ "hcrp", 1, 0, 'H' },
|
||||
@ -367,7 +369,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
printf("HCIDump - HCI packet analyzer ver %s\n", VERSION);
|
||||
|
||||
while ((opt=getopt_long(argc, argv, "i:s:p:w:r:txaRC:H:h", main_options, NULL)) != -1) {
|
||||
while ((opt=getopt_long(argc, argv, "i:s:p:w:r:taxXRC:H:h", main_options, NULL)) != -1) {
|
||||
switch(opt) {
|
||||
case 'i':
|
||||
device = atoi(optarg + 3);
|
||||
@ -395,12 +397,16 @@ int main(int argc, char *argv[])
|
||||
flags |= DUMP_TSTAMP;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
flags |= DUMP_ASCII;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
flags |= DUMP_HEX;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
flags |= DUMP_ASCII;
|
||||
case 'X':
|
||||
flags |= DUMP_EXT;
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
|
@ -97,31 +97,10 @@ uint32_t get_proto(uint16_t handle, uint16_t psm)
|
||||
return (pos < 0) ? 0 : proto_table[pos].proto;
|
||||
}
|
||||
|
||||
void hex_dump(int level, struct frame *frm, int num)
|
||||
{
|
||||
unsigned char *buf = frm->ptr;
|
||||
register int i,n;
|
||||
|
||||
if ((num < 0) || (num > frm->len))
|
||||
num = frm->len;
|
||||
|
||||
for (i = 0, n = 1; i < num; i++, n++) {
|
||||
if (n == 1)
|
||||
p_indent(level, frm);
|
||||
printf("%2.2X ", buf[i]);
|
||||
if (n == DUMP_WIDTH) {
|
||||
printf("\n");
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
if (i && n!=1)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void ascii_dump(int level, struct frame *frm, int num)
|
||||
{
|
||||
unsigned char *buf = frm->ptr;
|
||||
register int i,n;
|
||||
register int i, n;
|
||||
|
||||
if ((num < 0) || (num > frm->len))
|
||||
num = frm->len;
|
||||
@ -135,10 +114,61 @@ void ascii_dump(int level, struct frame *frm, int num)
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
if (i && n!=1)
|
||||
if (i && n != 1)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void hex_dump(int level, struct frame *frm, int num)
|
||||
{
|
||||
unsigned char *buf = frm->ptr;
|
||||
register int i, n;
|
||||
|
||||
if ((num < 0) || (num > frm->len))
|
||||
num = frm->len;
|
||||
|
||||
for (i = 0, n = 1; i < num; i++, n++) {
|
||||
if (n == 1)
|
||||
p_indent(level, frm);
|
||||
printf("%2.2X ", buf[i]);
|
||||
if (n == DUMP_WIDTH) {
|
||||
printf("\n");
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
if (i && n != 1)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void ext_dump(int level, struct frame *frm, int num)
|
||||
{
|
||||
unsigned char *buf = frm->ptr;
|
||||
register int i, n = 0, size;
|
||||
|
||||
if ((num < 0) || (num > frm->len))
|
||||
num = frm->len;
|
||||
|
||||
while (num > 0) {
|
||||
p_indent(level, frm);
|
||||
printf("%04x: ", n);
|
||||
|
||||
size = num > 16 ? 16 : num;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
printf("%02x ", buf[i]);
|
||||
for (i = 0; i < 16 - size; i++)
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
printf("%1c", isprint(buf[i]) ? buf[i] : '.');
|
||||
printf("\n");
|
||||
|
||||
buf += size;
|
||||
num -= size;
|
||||
n += size;
|
||||
}
|
||||
}
|
||||
|
||||
void raw_ndump(int level, struct frame *frm, int num)
|
||||
{
|
||||
if (!frm->len)
|
||||
@ -153,6 +183,9 @@ void raw_ndump(int level, struct frame *frm, int num)
|
||||
hex_dump(level, frm, num);
|
||||
break;
|
||||
|
||||
case DUMP_EXT:
|
||||
ext_dump(level, frm, num);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,11 +44,12 @@ struct frame {
|
||||
/* Parser flags */
|
||||
#define DUMP_WIDTH 20
|
||||
|
||||
#define DUMP_HEX 0x01
|
||||
#define DUMP_ASCII 0x02
|
||||
#define DUMP_TYPE_MASK (DUMP_HEX | DUMP_ASCII)
|
||||
#define DUMP_TSTAMP 0x04
|
||||
#define DUMP_ASCII 0x01
|
||||
#define DUMP_HEX 0x02
|
||||
#define DUMP_EXT 0x04
|
||||
#define DUMP_RAW 0x08
|
||||
#define DUMP_TSTAMP 0x10
|
||||
#define DUMP_TYPE_MASK (DUMP_ASCII | DUMP_HEX | DUMP_EXT)
|
||||
|
||||
/* Parser filter */
|
||||
#define FILT_HCI 0x0001
|
||||
@ -156,6 +157,7 @@ uint32_t get_proto(uint16_t handle, uint16_t psm);
|
||||
|
||||
void ascii_dump(int level, struct frame *frm, int num);
|
||||
void hex_dump(int level, struct frame *frm, int num);
|
||||
void ext_dump(int level, struct frame *frm, int num);
|
||||
void raw_dump(int level, struct frame *frm);
|
||||
void raw_ndump(int level, struct frame *frm, int num);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user