OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
6.3 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../bluez-hcidump/0004-Fix-HCI-LE-advertising-report-dump.patch
  5. # Copyright (C) 2011 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. From 70fb86e548eef4d54bb659c76a47c0891ba5f99a Mon Sep 17 00:00:00 2001
  17. From: Andre Dieb Martins <andre.dieb@signove.com>
  18. Date: Mon, 28 Feb 2011 00:58:22 -0300
  19. Subject: [PATCH 4/6] Fix HCI LE advertising report dump
  20. LE advertising report event has only one data block for each report.
  21. Thus, we can't reuse ext_inquiry_response_dump(), which loops over
  22. successive data blocks until reaches a zero-length one.
  23. This commit introduces ext_inquiry_data_dump(), which dumps a frame
  24. containing data formatted according to [Vol 3] Part C, Section 8. This
  25. function is reused by ext_inquiry_response_dump().
  26. Also adds RSSI parsing to each advertising report.
  27. ---
  28. parser/hci.c | 146 +++++++++++++++++++++++++++++++++------------------------
  29. 1 files changed, 84 insertions(+), 62 deletions(-)
  30. diff --git a/parser/hci.c b/parser/hci.c
  31. index fbbebde..4d9a315 100644
  32. --- a/parser/hci.c
  33. +++ b/parser/hci.c
  34. @@ -757,67 +757,83 @@ static char *filterpolicy2str(uint8_t policy)
  35. }
  36. }
  37. -static inline void ext_inquiry_response_dump(int level, struct frame *frm)
  38. +static inline void ext_inquiry_data_dump(int level, struct frame *frm,
  39. + uint8_t *data)
  40. {
  41. - void *ptr = frm->ptr;
  42. - uint32_t len = frm->len;
  43. - uint8_t type, length;
  44. + uint8_t len = data[0];
  45. + uint8_t type;
  46. char *str;
  47. int i;
  48. - length = get_u8(frm);
  49. + if (len == 0)
  50. + return;
  51. - while (length > 0) {
  52. - type = get_u8(frm);
  53. - length--;
  54. + type = data[1];
  55. + data += 2;
  56. + len -= 1;
  57. - switch (type) {
  58. - case 0x01:
  59. - p_indent(level, frm);
  60. - printf("Flags:");
  61. - for (i = 0; i < length; i++)
  62. - printf(" 0x%2.2x", *((uint8_t *) (frm->ptr + i)));
  63. - printf("\n");
  64. - break;
  65. + switch (type) {
  66. + case 0x01:
  67. + p_indent(level, frm);
  68. + printf("Flags:");
  69. + for (i = 0; i < len; i++)
  70. + printf(" 0x%2.2x", data[i]);
  71. + printf("\n");
  72. + break;
  73. - case 0x02:
  74. - case 0x03:
  75. - p_indent(level, frm);
  76. - printf("%s service classes:",
  77. - type == 0x02 ? "Shortened" : "Complete");
  78. - for (i = 0; i < length / 2; i++) {
  79. - uint16_t val = btohs(bt_get_unaligned((uint16_t *) (frm->ptr + (i * 2))));
  80. - printf(" 0x%4.4x", val);
  81. - }
  82. - printf("\n");
  83. - break;
  84. + case 0x02:
  85. + case 0x03:
  86. + p_indent(level, frm);
  87. + printf("%s service classes:",
  88. + type == 0x02 ? "Shortened" : "Complete");
  89. - case 0x08:
  90. - case 0x09:
  91. - str = malloc(length + 1);
  92. - if (str) {
  93. - snprintf(str, length + 1, "%s", (char *) frm->ptr);
  94. - for (i = 0; i < length; i++)
  95. - if (!isprint(str[i]))
  96. - str[i] = '.';
  97. - p_indent(level, frm);
  98. - printf("%s local name: \'%s\'\n",
  99. - type == 0x08 ? "Shortened" : "Complete", str);
  100. - free(str);
  101. - }
  102. - break;
  103. + for (i = 0; i < len / 2; i++) {
  104. + uint16_t val;
  105. - case 0x0a:
  106. - p_indent(level, frm);
  107. - printf("TX power level: %d\n", *((uint8_t *) frm->ptr));
  108. - break;
  109. + val = btohs(bt_get_unaligned(((uint16_t *) (data + i * 2))));
  110. + printf(" 0x%4.4x", val);
  111. + }
  112. + printf("\n");
  113. + break;
  114. - default:
  115. + case 0x08:
  116. + case 0x09:
  117. + str = malloc(len + 1);
  118. + if (str) {
  119. + snprintf(str, len + 1, "%s", (char *) data);
  120. + for (i = 0; i < len; i++)
  121. + if (!isprint(str[i]))
  122. + str[i] = '.';
  123. p_indent(level, frm);
  124. - printf("Unknown type 0x%02x with %d bytes data\n",
  125. - type, length);
  126. - break;
  127. + printf("%s local name: \'%s\'\n",
  128. + type == 0x08 ? "Shortened" : "Complete", str);
  129. + free(str);
  130. }
  131. + break;
  132. +
  133. + case 0x0a:
  134. + p_indent(level, frm);
  135. + printf("TX power level: %d\n", *((uint8_t *) data));
  136. + break;
  137. +
  138. + default:
  139. + p_indent(level, frm);
  140. + printf("Unknown type 0x%02x with %d bytes data\n",
  141. + type, len);
  142. + break;
  143. + }
  144. +}
  145. +
  146. +static inline void ext_inquiry_response_dump(int level, struct frame *frm)
  147. +{
  148. + void *ptr = frm->ptr;
  149. + uint32_t len = frm->len;
  150. + uint8_t length;
  151. +
  152. + length = get_u8(frm);
  153. +
  154. + while (length > 0) {
  155. + ext_inquiry_data_dump(level, frm, frm->ptr);
  156. frm->ptr += length;
  157. frm->len -= length;
  158. @@ -825,8 +841,10 @@ static inline void ext_inquiry_response_dump(int level, struct frame *frm)
  159. length = get_u8(frm);
  160. }
  161. - frm->ptr = ptr + (EXTENDED_INQUIRY_INFO_SIZE - INQUIRY_INFO_WITH_RSSI_SIZE);
  162. - frm->len = len + (EXTENDED_INQUIRY_INFO_SIZE - INQUIRY_INFO_WITH_RSSI_SIZE);
  163. + frm->ptr = ptr +
  164. + (EXTENDED_INQUIRY_INFO_SIZE - INQUIRY_INFO_WITH_RSSI_SIZE);
  165. + frm->len = len +
  166. + (EXTENDED_INQUIRY_INFO_SIZE - INQUIRY_INFO_WITH_RSSI_SIZE);
  167. }
  168. static inline void bdaddr_command_dump(int level, struct frame *frm)
  169. @@ -3504,14 +3522,12 @@ static inline void evt_le_conn_complete_dump(int level, struct frame *frm)
  170. static inline void evt_le_advertising_report_dump(int level, struct frame *frm)
  171. {
  172. - uint8_t num = get_u8(frm);
  173. - char addr[18];
  174. - int i;
  175. + uint8_t num_reports = get_u8(frm);
  176. + const uint8_t RSSI_SIZE = 1;
  177. - for (i = 0; i < num; i++) {
  178. + while (num_reports--) {
  179. + char addr[18];
  180. le_advertising_info *info = frm->ptr;
  181. - void *ptr = frm->ptr;
  182. - uint32_t len = frm->len;
  183. p_ba2str(&info->bdaddr, addr);
  184. @@ -3522,13 +3538,19 @@ static inline void evt_le_advertising_report_dump(int level, struct frame *frm)
  185. printf("bdaddr %s (%s)\n", addr,
  186. bdaddrtype2str(info->bdaddr_type));
  187. - frm->ptr += LE_ADVERTISING_INFO_SIZE;
  188. - frm->len -= LE_ADVERTISING_INFO_SIZE;
  189. + if (info->length > 0) {
  190. + ext_inquiry_data_dump(level, frm,
  191. + ((uint8_t *) &info->length) + 1);
  192. + }
  193. - ext_inquiry_response_dump(level, frm);
  194. + frm->ptr += LE_ADVERTISING_INFO_SIZE + info->length;
  195. + frm->len -= LE_ADVERTISING_INFO_SIZE + info->length;
  196. +
  197. + p_indent(level, frm);
  198. + printf("RSSI: %d\n", ((int8_t *) frm->ptr)[frm->len - 1]);
  199. - frm->ptr = ptr + 1;
  200. - frm->len = len - 1;
  201. + frm->ptr += RSSI_SIZE;
  202. + frm->len -= RSSI_SIZE;
  203. }
  204. }
  205. --
  206. 1.7.2.3