hcrp.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2004-2011 Marcel Holtmann <marcel@holtmann.org>
  7. *
  8. *
  9. */
  10. #ifdef HAVE_CONFIG_H
  11. #include <config.h>
  12. #endif
  13. #define _GNU_SOURCE
  14. #include <stdio.h>
  15. #include <errno.h>
  16. #include <unistd.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include "parser.h"
  20. static char *pid2str(uint16_t pid)
  21. {
  22. switch (pid) {
  23. case 0x0001:
  24. return "CreditGrant";
  25. case 0x0002:
  26. return "CreditRequest";
  27. case 0x0003:
  28. return "CreditReturn";
  29. case 0x0004:
  30. return "CreditQuery";
  31. case 0x0005:
  32. return "GetLPTStatus";
  33. case 0x0006:
  34. return "Get1284ID";
  35. case 0x0007:
  36. return "SoftReset";
  37. case 0x0008:
  38. return "HardRest";
  39. case 0x0009:
  40. return "RegisterNotification";
  41. case 0x000A:
  42. return "NotificationConnectionAlive";
  43. default:
  44. return "Reserved";
  45. }
  46. }
  47. static char *status2str(uint16_t status)
  48. {
  49. switch (status) {
  50. case 0x0000:
  51. return "Feature unsupported";
  52. case 0x0001:
  53. return "Success";
  54. case 0x0002:
  55. return "Credit synchronization error";
  56. case 0xFFFF:
  57. return "Generic error";
  58. default:
  59. return "Unknown";
  60. }
  61. }
  62. void hcrp_dump(int level, struct frame *frm)
  63. {
  64. uint16_t pid, tid, plen, status;
  65. uint32_t credits;
  66. pid = p_get_u16(frm);
  67. tid = p_get_u16(frm);
  68. plen = p_get_u16(frm);
  69. p_indent(level, frm);
  70. printf("HCRP %s %s: tid 0x%x plen %d",
  71. pid2str(pid), frm->in ? "rsp" : "cmd", tid, plen);
  72. if (frm->in) {
  73. status = p_get_u16(frm);
  74. printf(" status %d (%s)\n", status, status2str(status));
  75. } else
  76. printf("\n");
  77. if (pid == 0x0001 && !frm->in) {
  78. credits = p_get_u32(frm);
  79. p_indent(level + 1, frm);
  80. printf("credits %d\n", credits);
  81. }
  82. if (pid == 0x0002 && frm->in) {
  83. credits = p_get_u32(frm);
  84. p_indent(level + 1, frm);
  85. printf("credits %d\n", credits);
  86. }
  87. raw_dump(level + 1, frm);
  88. }