From 8f5b98034330b1151113b6accb7f0c521aed361e Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 3 Mar 2004 02:59:16 +0000 Subject: [PATCH] hcidump: Add initial HCRP parser support --- tools/hcidump.1 | 6 ++- tools/hcidump.c | 7 +++ tools/parser/hcrp.c | 115 ++++++++++++++++++++++++++++++++++++++++++ tools/parser/l2cap.c | 7 +++ tools/parser/parser.h | 2 + tools/parser/sdp.h | 3 ++ 6 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 tools/parser/hcrp.c diff --git a/tools/hcidump.1 b/tools/hcidump.1 index 26bd92acd..181d311a5 100644 --- a/tools/hcidump.1 +++ b/tools/hcidump.1 @@ -66,6 +66,9 @@ Raw mode: do not display packet type, only data. .TP .BR -C ", " "\-\^\-cmtp" Sets the PSM value for the CAPI Message Transport Protocol +.TP +.BR -H ", " "\-\^\-hcrp" +Sets the PSM value for the Hardcopy Data Channel .SH FILTERS .B filter @@ -77,7 +80,8 @@ is a space-separated list of packet categories: available categories are .IR sdp , .IR bnep , .IR cmtp , -.IR hidp +.IR hidp , +.IR hcrp and .IR capi . If filters are used, only packets belonging to the specified categories are diff --git a/tools/hcidump.c b/tools/hcidump.c index fa2711e48..b8e351e68 100644 --- a/tools/hcidump.c +++ b/tools/hcidump.c @@ -301,6 +301,7 @@ static struct { { "bnep", FILT_BNEP }, { "cmtp", FILT_CMTP }, { "hidp", FILT_HIDP }, + { "hcrp", FILT_HCRP }, { "capi", FILT_CAPI }, { 0 } }; @@ -333,6 +334,7 @@ static void usage(void) " -a, --ascii Dump data in ascii\n" " -R, --raw Raw mode\n" " -C, --cmtp=psm PSM for CMTP\n" + " -H, --hcrp=psm PSM for HCRP\n" " -?, --help Give this help list\n" " --usage Give a short usage message\n" ); @@ -349,6 +351,7 @@ static struct option main_options[] = { { "ascii", 0, 0, 'a' }, { "raw", 0, 0, 'R' }, { "cmtp", 1, 0, 'C' }, + { "hcrp", 1, 0, 'H' }, { "help", 0, 0, 'h' }, { 0 } }; @@ -403,6 +406,10 @@ int main(int argc, char *argv[]) set_proto(0, atoi(optarg), SDP_UUID_CMTP); break; + case 'H': + set_proto(0, atoi(optarg), SDP_UUID_HARDCOPY_CONTROL_CHANNEL); + break; + case 'h': default: usage(); diff --git a/tools/parser/hcrp.c b/tools/parser/hcrp.c new file mode 100644 index 000000000..6fb17abdf --- /dev/null +++ b/tools/parser/hcrp.c @@ -0,0 +1,115 @@ +/* + * + * Bluetooth packet analyzer - HCRP parser + * + * Copyright (C) 2004 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * $Id$ + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "parser.h" + + +static char *pid2str(uint16_t pid) +{ + switch (pid) { + case 0x0001: + return "CreditGrant"; + case 0x0002: + return "CreditRequest"; + case 0x0003: + return "CreditReturn"; + case 0x0004: + return "CreditQuery"; + case 0x0005: + return "GetLPTStatus"; + case 0x0006: + return "Get1284ID"; + case 0x0007: + return "SoftReset"; + case 0x0008: + return "HardRest"; + case 0x0009: + return "RegisterNotification"; + case 0x000A: + return "NotificationConnectionAlive"; + default: + return "Reserved"; + } +} + +static char *status2str(uint16_t status) +{ + switch (status) { + case 0x0000: + return "Feature unsupported"; + case 0x0001: + return "Success"; + case 0x0002: + return "Credit synchronization error"; + case 0xFFFF: + return "Generic error"; + default: + return "Unknown"; + } +} + +void hcrp_dump(int level, struct frame *frm) +{ + uint16_t pid, tid, plen, status; + uint32_t credits; + + pid = get_u16(frm); + tid = get_u16(frm); + plen = get_u16(frm); + + p_indent(level, frm); + + printf("HCRP %s %s: tid 0x%x plen %d", + pid2str(pid), frm->in ? "rsp" : "cmd", tid, plen); + + if (frm->in) { + status = get_u16(frm); + printf(" status %d (%s)\n", status, status2str(status)); + } else + printf("\n"); + + if (pid == 0x0001 && !frm->in) { + credits = get_u32(frm); + p_indent(level + 1, frm); + printf("credits %d\n", credits); + } + + if (pid == 0x0002 && frm->in) { + credits = get_u32(frm); + p_indent(level + 1, frm); + printf("credits %d\n", credits); + } + + raw_dump(level + 1, frm); +} diff --git a/tools/parser/l2cap.c b/tools/parser/l2cap.c index 94a0d90a0..8b8e5fb11 100644 --- a/tools/parser/l2cap.c +++ b/tools/parser/l2cap.c @@ -438,6 +438,13 @@ static void l2cap_parse(int level, struct frame *frm) raw_dump(level + 1, frm); break; + case SDP_UUID_HARDCOPY_CONTROL_CHANNEL: + if (!p_filter(FILT_HCRP)) + hcrp_dump(level, frm); + else + raw_dump(level + 1, frm); + break; + default: if (p_filter(FILT_L2CAP)) break; diff --git a/tools/parser/parser.h b/tools/parser/parser.h index a5e9638bb..cfdf39f2e 100644 --- a/tools/parser/parser.h +++ b/tools/parser/parser.h @@ -57,6 +57,7 @@ struct frame { #define FILT_BNEP 0x0020 #define FILT_CMTP 0x0040 #define FILT_HIDP 0x0080 +#define FILT_HCRP 0x0100 #define FILT_CAPI 0x00010000 @@ -166,6 +167,7 @@ void sdp_dump(int level, struct frame *frm); void bnep_dump(int level, struct frame *frm); void cmtp_dump(int level, struct frame *frm); void hidp_dump(int level, struct frame *frm); +void hcrp_dump(int level, struct frame *frm); void capi_dump(int level, struct frame *frm); diff --git a/tools/parser/sdp.h b/tools/parser/sdp.h index d657a4f2a..90f5faf53 100644 --- a/tools/parser/sdp.h +++ b/tools/parser/sdp.h @@ -49,6 +49,9 @@ #define SDP_UUID_WSP 0x000E #define SDP_UUID_BNEP 0x000F /* PAN */ #define SDP_UUID_HIDP 0x0011 /* HID */ +#define SDP_UUID_HARDCOPY_CONTROL_CHANNEL 0x0012 /* HCRP */ +#define SDP_UUID_HARDCOPY_DATA_CHANNEL 0x0014 /* HCRP */ +#define SDP_UUID_HARDCOPY_NOTIFICATION 0x0016 /* HCRP */ #define SDP_UUID_CMTP 0x001B /* CIP */ #define SDP_UUID_L2CAP 0x0100 -- 2.47.3