amp.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2012 Intel Corporation.
  7. *
  8. */
  9. #ifdef HAVE_CONFIG_H
  10. #include <config.h>
  11. #endif
  12. #define _GNU_SOURCE
  13. #include "parser.h"
  14. #include "lib/amp.h"
  15. static void amp_dump_chanlist(int level, struct amp_tlv *tlv, char *prefix)
  16. {
  17. struct amp_chan_list *chan_list = (void *) tlv->val;
  18. struct amp_country_triplet *triplet;
  19. int i, num;
  20. num = (tlv->len - sizeof(*chan_list)) / sizeof(*triplet);
  21. printf("%s (number of triplets %d)\n", prefix, num);
  22. p_indent(level+2, 0);
  23. printf("Country code: %c%c%c\n", chan_list->country_code[0],
  24. chan_list->country_code[1], chan_list->country_code[2]);
  25. for (i = 0; i < num; i++) {
  26. triplet = &chan_list->triplets[i];
  27. p_indent(level+2, 0);
  28. if (triplet->chans.first_channel >= 201) {
  29. printf("Reg ext id %d reg class %d coverage class %d\n",
  30. triplet->ext.reg_extension_id,
  31. triplet->ext.reg_class,
  32. triplet->ext.coverage_class);
  33. } else {
  34. if (triplet->chans.num_channels == 1)
  35. printf("Channel %d max power %d\n",
  36. triplet->chans.first_channel,
  37. triplet->chans.max_power);
  38. else
  39. printf("Channels %d - %d max power %d\n",
  40. triplet->chans.first_channel,
  41. triplet->chans.first_channel +
  42. triplet->chans.num_channels,
  43. triplet->chans.max_power);
  44. }
  45. }
  46. }
  47. void amp_assoc_dump(int level, uint8_t *assoc, uint16_t len)
  48. {
  49. struct amp_tlv *tlv = (void *) assoc;
  50. p_indent(level, 0);
  51. printf("Assoc data [len %d]:\n", len);
  52. while (len > sizeof(*tlv)) {
  53. uint16_t tlvlen = btohs(tlv->len);
  54. struct amp_pal_ver *ver;
  55. p_indent(level+1, 0);
  56. switch (tlv->type) {
  57. case A2MP_MAC_ADDR_TYPE:
  58. if (tlvlen != 6)
  59. break;
  60. printf("MAC: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
  61. tlv->val[0], tlv->val[1], tlv->val[2],
  62. tlv->val[3], tlv->val[4], tlv->val[5]);
  63. break;
  64. case A2MP_PREF_CHANLIST_TYPE:
  65. amp_dump_chanlist(level, tlv, "Preferred Chan List");
  66. break;
  67. case A2MP_CONNECTED_CHAN:
  68. amp_dump_chanlist(level, tlv, "Connected Chan List");
  69. break;
  70. case A2MP_PAL_CAP_TYPE:
  71. if (tlvlen != 4)
  72. break;
  73. printf("PAL CAP: %2.2x %2.2x %2.2x %2.2x\n",
  74. tlv->val[0], tlv->val[1], tlv->val[2],
  75. tlv->val[3]);
  76. break;
  77. case A2MP_PAL_VER_INFO:
  78. if (tlvlen != 5)
  79. break;
  80. ver = (struct amp_pal_ver *) tlv->val;
  81. printf("PAL VER: %2.2x Comp ID: %4.4x SubVer: %4.4x\n",
  82. ver->ver, btohs(ver->company_id),
  83. btohs(ver->sub_ver));
  84. break;
  85. default:
  86. printf("Unrecognized type %d\n", tlv->type);
  87. break;
  88. }
  89. len -= tlvlen + sizeof(*tlv);
  90. assoc += tlvlen + sizeof(*tlv);
  91. tlv = (struct amp_tlv *) assoc;
  92. }
  93. }