13d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann/* 23d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * 3aace363653bba5b4b20648014a5b4103723d5991Marcel Holtmann * BlueZ - Bluetooth protocol stack for Linux 43d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * 5703086ed0bfa159fa2ba9e5fcfb6484865036cf2Marcel Holtmann * Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org> 63d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * 73d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * 83d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * This program is free software; you can redistribute it and/or modify 93d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * it under the terms of the GNU General Public License as published by 103d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * the Free Software Foundation; either version 2 of the License, or 113d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * (at your option) any later version. 123d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * 133d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * This program is distributed in the hope that it will be useful, 143d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * but WITHOUT ANY WARRANTY; without even the implied warranty of 153d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 163d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * GNU General Public License for more details. 173d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * 183d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * You should have received a copy of the GNU General Public License 193d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * along with this program; if not, write to the Free Software 20aace363653bba5b4b20648014a5b4103723d5991Marcel Holtmann * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 213d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann * 223d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann */ 233d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 24aace363653bba5b4b20648014a5b4103723d5991Marcel Holtmann#ifdef HAVE_CONFIG_H 25aace363653bba5b4b20648014a5b4103723d5991Marcel Holtmann#include <config.h> 26aace363653bba5b4b20648014a5b4103723d5991Marcel Holtmann#endif 27aace363653bba5b4b20648014a5b4103723d5991Marcel Holtmann 283d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann#include <stdio.h> 293d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann#include <errno.h> 30aace363653bba5b4b20648014a5b4103723d5991Marcel Holtmann#include <unistd.h> 31aace363653bba5b4b20648014a5b4103723d5991Marcel Holtmann#include <stdlib.h> 323d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann#include <string.h> 333d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 343d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann#include <sys/types.h> 353d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann#include <netinet/in.h> 363d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 373d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann#include "parser.h" 383d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 393d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmannstatic char *pid2str(uint16_t pid) 403d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann{ 413d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann switch (pid) { 423d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x0001: 433d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "CreditGrant"; 443d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x0002: 453d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "CreditRequest"; 463d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x0003: 473d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "CreditReturn"; 483d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x0004: 493d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "CreditQuery"; 503d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x0005: 513d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "GetLPTStatus"; 523d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x0006: 533d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "Get1284ID"; 543d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x0007: 553d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "SoftReset"; 563d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x0008: 573d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "HardRest"; 583d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x0009: 593d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "RegisterNotification"; 603d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x000A: 613d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "NotificationConnectionAlive"; 623d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann default: 633d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "Reserved"; 643d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann } 653d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann} 663d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 673d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmannstatic char *status2str(uint16_t status) 683d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann{ 693d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann switch (status) { 703d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x0000: 713d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "Feature unsupported"; 723d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x0001: 733d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "Success"; 743d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0x0002: 753d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "Credit synchronization error"; 763d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann case 0xFFFF: 773d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "Generic error"; 783d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann default: 793d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann return "Unknown"; 803d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann } 813d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann} 823d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 833d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmannvoid hcrp_dump(int level, struct frame *frm) 843d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann{ 853d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann uint16_t pid, tid, plen, status; 863d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann uint32_t credits; 873d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 883d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann pid = get_u16(frm); 893d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann tid = get_u16(frm); 903d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann plen = get_u16(frm); 913d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 923d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann p_indent(level, frm); 933d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 943d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann printf("HCRP %s %s: tid 0x%x plen %d", 953d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann pid2str(pid), frm->in ? "rsp" : "cmd", tid, plen); 963d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 973d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann if (frm->in) { 983d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann status = get_u16(frm); 993d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann printf(" status %d (%s)\n", status, status2str(status)); 1003d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann } else 1013d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann printf("\n"); 1023d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 1033d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann if (pid == 0x0001 && !frm->in) { 1043d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann credits = get_u32(frm); 1053d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann p_indent(level + 1, frm); 1063d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann printf("credits %d\n", credits); 1073d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann } 1083d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 1093d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann if (pid == 0x0002 && frm->in) { 1103d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann credits = get_u32(frm); 1113d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann p_indent(level + 1, frm); 1123d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann printf("credits %d\n", credits); 1133d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann } 1143d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann 1153d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann raw_dump(level + 1, frm); 1163d034662b5f703eeb81aee37fb464b6b17d31421Marcel Holtmann} 117