1 /*
2 *
3 * BlueZ - Bluetooth protocol stack for Linux
4 *
5 * Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org>
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <stdio.h>
29 #include <errno.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #include <sys/types.h>
35 #include <netinet/in.h>
36
37 #include "parser.h"
38
pid2str(uint16_t pid)39 static char *pid2str(uint16_t pid)
40 {
41 switch (pid) {
42 case 0x0001:
43 return "CreditGrant";
44 case 0x0002:
45 return "CreditRequest";
46 case 0x0003:
47 return "CreditReturn";
48 case 0x0004:
49 return "CreditQuery";
50 case 0x0005:
51 return "GetLPTStatus";
52 case 0x0006:
53 return "Get1284ID";
54 case 0x0007:
55 return "SoftReset";
56 case 0x0008:
57 return "HardRest";
58 case 0x0009:
59 return "RegisterNotification";
60 case 0x000A:
61 return "NotificationConnectionAlive";
62 default:
63 return "Reserved";
64 }
65 }
66
status2str(uint16_t status)67 static char *status2str(uint16_t status)
68 {
69 switch (status) {
70 case 0x0000:
71 return "Feature unsupported";
72 case 0x0001:
73 return "Success";
74 case 0x0002:
75 return "Credit synchronization error";
76 case 0xFFFF:
77 return "Generic error";
78 default:
79 return "Unknown";
80 }
81 }
82
hcrp_dump(int level,struct frame * frm)83 void hcrp_dump(int level, struct frame *frm)
84 {
85 uint16_t pid, tid, plen, status;
86 uint32_t credits;
87
88 pid = get_u16(frm);
89 tid = get_u16(frm);
90 plen = get_u16(frm);
91
92 p_indent(level, frm);
93
94 printf("HCRP %s %s: tid 0x%x plen %d",
95 pid2str(pid), frm->in ? "rsp" : "cmd", tid, plen);
96
97 if (frm->in) {
98 status = get_u16(frm);
99 printf(" status %d (%s)\n", status, status2str(status));
100 } else
101 printf("\n");
102
103 if (pid == 0x0001 && !frm->in) {
104 credits = get_u32(frm);
105 p_indent(level + 1, frm);
106 printf("credits %d\n", credits);
107 }
108
109 if (pid == 0x0002 && frm->in) {
110 credits = get_u32(frm);
111 p_indent(level + 1, frm);
112 printf("credits %d\n", credits);
113 }
114
115 raw_dump(level + 1, frm);
116 }
117