3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2004-2011 Marcel Holtmann <marcel@holtmann.org>
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.
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.
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
36 static char *opcode2str(uint8_t opcode)
38 switch (opcode & 0x7f) {
66 return "Non-authoritative information";
70 return "Reset content";
72 return "Partial content";
74 return "Multiple choices";
76 return "Moved permanently";
78 return "Moved temporarily";
82 return "Not modified";
88 return "Unauthorized";
90 return "Payment required";
96 return "Method not allowed";
98 return "Not acceptable";
100 return "Proxy authentication required";
102 return "Request timeout";
108 return "Length required";
110 return "Precondition failed";
112 return "Requested entity too large";
114 return "Requested URL too large";
116 return "Unsupported media type";
118 return "Internal server error";
120 return "Not implemented";
122 return "Bad gateway";
124 return "Service unavailable";
126 return "Gateway timeout";
128 return "HTTP version not supported";
130 return "Database full";
132 return "Database locked";
138 static char *hi2str(uint8_t hi)
152 return "Description";
160 return "End of Body";
164 return "Connection ID";
166 return "App. Parameters";
168 return "Auth. Challenge";
170 return "Auth. Response";
176 return "Object Class";
178 return "Session Parameters";
180 return "Session Sequence Number";
188 return "Single Response Mode";
190 return "Single Response Mode Parameters";
196 static void parse_headers(int level, struct frame *frm)
202 while (frm->len > 0) {
205 p_indent(level, frm);
207 printf("%s (0x%02x)", hi2str(hi), hi);
209 case 0x00: /* Unicode */
215 len = p_get_u16(frm) - 3;
216 printf(" = Unicode length %d\n", len);
221 raw_ndump(level, frm, len);
226 case 0x40: /* Byte sequence */
232 len = p_get_u16(frm) - 3;
233 printf(" = Sequence length %d\n", len);
238 raw_ndump(level, frm, len);
243 case 0x80: /* One byte */
250 printf(" = %d\n", hv8);
253 case 0xc0: /* Four bytes */
259 hv32 = p_get_u32(frm);
260 printf(" = %u\n", hv32);
266 void obex_dump(int level, struct frame *frm)
268 uint8_t last_opcode, opcode, status;
269 uint8_t version, flags, constants;
270 uint16_t length, pktlen;
272 frm = add_frame(frm);
274 while (frm->len > 2) {
275 opcode = p_get_u8(frm);
276 length = p_get_u16(frm);
277 status = opcode & 0x7f;
279 if ((int) frm->len < length - 3) {
285 p_indent(level, frm);
287 last_opcode = get_opcode(frm->handle, frm->dlci);
289 if (!(opcode & 0x70)) {
290 printf("OBEX: %s cmd(%c): len %d",
292 opcode & 0x80 ? 'f' : 'c', length);
293 set_opcode(frm->handle, frm->dlci, opcode);
295 printf("OBEX: %s rsp(%c): status %x%02d len %d",
296 opcode2str(last_opcode),
297 opcode & 0x80 ? 'f' : 'c',
298 status >> 4, status & 0xf, length);
299 opcode = last_opcode;
302 if (get_status(frm->handle, frm->dlci) == 0x10)
303 printf(" (continue)");
305 set_status(frm->handle, frm->dlci, status);
312 switch (opcode & 0x7f) {
313 case 0x00: /* Connect */
319 version = p_get_u8(frm);
320 flags = p_get_u8(frm);
321 pktlen = p_get_u16(frm);
322 printf(" version %d.%d flags %d mtu %d\n",
323 version >> 4, version & 0xf, flags, pktlen);
326 case 0x05: /* SetPath */
332 flags = p_get_u8(frm);
333 constants = p_get_u8(frm);
334 printf(" flags %d constants %d\n", flags, constants);
342 if ((status & 0x70) && (parser.flags & DUMP_VERBOSE)) {
343 p_indent(level, frm);
344 printf("Status %x%02d = %s\n",
345 status >> 4, status & 0xf,
349 parse_headers(level, frm);