Re: [PATCH] Fix HCI LE advertising report dump

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Andre,

On Thu, Feb 24, 2011 at 5:17 PM, Andre Dieb Martins
<andre.dieb@xxxxxxxxxxx> wrote:
> LE advertising report event has only one data block for each report. Thus, we
> can't reuse ext_inquiry_response_dump(), which loops over successive data blocks
> until reaches a zero-length one.
>
> This commit introduces ext_inquiry_data_dump(), which dumps a frame containing
> data formatted according to [Vol 3] Part C, Section 8. This function is reused
> by ext_inquiry_response_dump().
>
> Also adds RSSI parsing to each advertising report.
> ---
> Âparser/hci.c | Â136 ++++++++++++++++++++++++++++++++-------------------------
> Â1 files changed, 76 insertions(+), 60 deletions(-)
>
> diff --git a/parser/hci.c b/parser/hci.c
> index 183fa66..dc27a27 100644
> --- a/parser/hci.c
> +++ b/parser/hci.c
> @@ -757,67 +757,83 @@ static char *filterpolicy2str(uint8_t policy)
> Â Â Â Â}
> Â}
>
> -static inline void ext_inquiry_response_dump(int level, struct frame *frm)
> +static inline void ext_inquiry_data_dump(int level, struct frame *frm,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â uint8_t *data)
> Â{
> - Â Â Â void *ptr = frm->ptr;
> - Â Â Â uint32_t len = frm->len;
> - Â Â Â uint8_t type, length;
> + Â Â Â uint8_t len = data[0];
> + Â Â Â uint8_t type;
> Â Â Â Âchar *str;
> Â Â Â Âint i;
>
> - Â Â Â length = get_u8(frm);
> + Â Â Â if (len == 0)
> + Â Â Â Â Â Â Â return;
>
> - Â Â Â while (length > 0) {
> - Â Â Â Â Â Â Â type = get_u8(frm);
> - Â Â Â Â Â Â Â length--;
> + Â Â Â type = data[1];
> + Â Â Â data += 2;
> + Â Â Â len -= 1;
>
> - Â Â Â Â Â Â Â switch (type) {
> - Â Â Â Â Â Â Â case 0x01:
> - Â Â Â Â Â Â Â Â Â Â Â p_indent(level, frm);
> - Â Â Â Â Â Â Â Â Â Â Â printf("Flags:");
> - Â Â Â Â Â Â Â Â Â Â Â for (i = 0; i < length; i++)
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â printf(" 0x%2.2x", *((uint8_t *) (frm->ptr + i)));
> - Â Â Â Â Â Â Â Â Â Â Â printf("\n");
> - Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â switch (type) {
> + Â Â Â case 0x01:
> + Â Â Â Â Â Â Â p_indent(level, frm);
> + Â Â Â Â Â Â Â printf("Flags:");
> + Â Â Â Â Â Â Â for (i = 0; i < len; i++)
> + Â Â Â Â Â Â Â Â Â Â Â printf(" 0x%2.2x", data[i]);
> + Â Â Â Â Â Â Â printf("\n");
> + Â Â Â Â Â Â Â break;
>
> - Â Â Â Â Â Â Â case 0x02:
> - Â Â Â Â Â Â Â case 0x03:
> - Â Â Â Â Â Â Â Â Â Â Â p_indent(level, frm);
> - Â Â Â Â Â Â Â Â Â Â Â printf("%s service classes:",
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â type == 0x02 ? "Shortened" : "Complete");
> - Â Â Â Â Â Â Â Â Â Â Â for (i = 0; i < length / 2; i++) {
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â uint16_t val = btohs(bt_get_unaligned((uint16_t *) (frm->ptr + (i * 2))));
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â printf(" 0x%4.4x", val);
> - Â Â Â Â Â Â Â Â Â Â Â }
> - Â Â Â Â Â Â Â Â Â Â Â printf("\n");
> - Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â case 0x02:
> + Â Â Â case 0x03:
> + Â Â Â Â Â Â Â p_indent(level, frm);
> + Â Â Â Â Â Â Â printf("%s service classes:",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â type == 0x02 ? "Shortened" : "Complete");
>
> - Â Â Â Â Â Â Â case 0x08:
> - Â Â Â Â Â Â Â case 0x09:
> - Â Â Â Â Â Â Â Â Â Â Â str = malloc(length + 1);
> - Â Â Â Â Â Â Â Â Â Â Â if (str) {
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â snprintf(str, length + 1, "%s", (char *) frm->ptr);
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â for (i = 0; i < length; i++)
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (!isprint(str[i]))
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â str[i] = '.';
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â p_indent(level, frm);
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â printf("%s local name: \'%s\'\n",
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â type == 0x08 ? "Shortened" : "Complete", str);
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â free(str);
> - Â Â Â Â Â Â Â Â Â Â Â }
> - Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â for (i = 0; i < len / 2; i++) {
> + Â Â Â Â Â Â Â Â Â Â Â uint16_t val;
>
> - Â Â Â Â Â Â Â case 0x0a:
> - Â Â Â Â Â Â Â Â Â Â Â p_indent(level, frm);
> - Â Â Â Â Â Â Â Â Â Â Â printf("TX power level: %d\n", *((uint8_t *) frm->ptr));
> - Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â Â Â Â Â val = btohs(bt_get_unaligned(((uint16_t *) (data + i * 2))));
> + Â Â Â Â Â Â Â Â Â Â Â printf(" 0x%4.4x", val);
> + Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â printf("\n");
> + Â Â Â Â Â Â Â break;
>
> - Â Â Â Â Â Â Â default:
> + Â Â Â case 0x08:
> + Â Â Â case 0x09:
> + Â Â Â Â Â Â Â str = malloc(len + 1);
> + Â Â Â Â Â Â Â if (str) {
> + Â Â Â Â Â Â Â Â Â Â Â snprintf(str, len + 1, "%s", (char *) data);
> + Â Â Â Â Â Â Â Â Â Â Â for (i = 0; i < len; i++)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (!isprint(str[i]))
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â str[i] = '.';
> Â Â Â Â Â Â Â Â Â Â Â Âp_indent(level, frm);
> - Â Â Â Â Â Â Â Â Â Â Â printf("Unknown type 0x%02x with %d bytes data\n",
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â type, length);
> - Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â Â Â Â Â printf("%s local name: \'%s\'\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â type == 0x08 ? "Shortened" : "Complete", str);
> + Â Â Â Â Â Â Â Â Â Â Â free(str);
> Â Â Â Â Â Â Â Â}
> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â case 0x0a:
> + Â Â Â Â Â Â Â p_indent(level, frm);
> + Â Â Â Â Â Â Â printf("TX power level: %d\n", *((uint8_t *) data));
> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â default:
> + Â Â Â Â Â Â Â p_indent(level, frm);
> + Â Â Â Â Â Â Â printf("Unknown type 0x%02x with %d bytes data\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â type, len);
> + Â Â Â Â Â Â Â break;
> + Â Â Â }
> +}
> +
> +static inline void ext_inquiry_response_dump(int level, struct frame *frm)
> +{
> + Â Â Â void *ptr = frm->ptr;
> + Â Â Â uint32_t len = frm->len;
> + Â Â Â uint8_t length;
> +
> + Â Â Â length = get_u8(frm);
> +
> + Â Â Â while (length > 0) {
> + Â Â Â Â Â Â Â ext_inquiry_data_dump(level, frm, frm->ptr);
>
> Â Â Â Â Â Â Â Âfrm->ptr += length;
> Â Â Â Â Â Â Â Âfrm->len -= length;
> @@ -3504,14 +3520,12 @@ static inline void evt_le_conn_complete_dump(int level, struct frame *frm)
>
> Âstatic inline void evt_le_advertising_report_dump(int level, struct frame *frm)
> Â{
> - Â Â Â uint8_t num = get_u8(frm);
> - Â Â Â char addr[18];
> - Â Â Â int i;
> + Â Â Â uint8_t num_reports = get_u8(frm);
> + Â Â Â const uint8_t RSSI_SIZE = 1;
>
> - Â Â Â for (i = 0; i < num; i++) {
> + Â Â Â while (num_reports--) {
> + Â Â Â Â Â Â Â char addr[18];
> Â Â Â Â Â Â Â Âle_advertising_info *info = frm->ptr;
> - Â Â Â Â Â Â Â void *ptr = frm->ptr;
> - Â Â Â Â Â Â Â uint32_t len = frm->len;
>
> Â Â Â Â Â Â Â Âp_ba2str(&info->bdaddr, addr);
>
> @@ -3522,13 +3536,15 @@ static inline void evt_le_advertising_report_dump(int level, struct frame *frm)
> Â Â Â Â Â Â Â Âprintf("bdaddr %s (%s)\n", addr,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âbdaddrtype2str(info->bdaddr_type));
>
> - Â Â Â Â Â Â Â frm->ptr += LE_ADVERTISING_INFO_SIZE;
> - Â Â Â Â Â Â Â frm->len -= LE_ADVERTISING_INFO_SIZE;
> + Â Â Â Â Â Â Â if (info->length > 0) {
> + Â Â Â Â Â Â Â Â Â Â Â ext_inquiry_data_dump(level, frm, &info->length + 1);
> + Â Â Â Â Â Â Â }
>
> - Â Â Â Â Â Â Â ext_inquiry_response_dump(level, frm);
> + Â Â Â Â Â Â Â frm->ptr += LE_ADVERTISING_INFO_SIZE + info->length + RSSI_SIZE;
> + Â Â Â Â Â Â Â frm->len -= LE_ADVERTISING_INFO_SIZE + info->length + RSSI_SIZE;
>
> - Â Â Â Â Â Â Â frm->ptr = ptr + 1;
> - Â Â Â Â Â Â Â frm->len = len - 1;
> + Â Â Â Â Â Â Â p_indent(level, frm);
> + Â Â Â Â Â Â Â printf("RSSI: %d\n", ((int8_t *) frm->ptr)[frm->len - 1]);
> Â Â Â Â}
> Â}
>
> --
> 1.7.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
>

hcidump is crashing. I gonna send a private e-mail with the hcidump
log to reproduce the problem.

Claudio.
ÿô.nlj·Ÿ®‰­†+%ŠË±é¥Šwÿº{.nlj·¥Š{±ý¶â^n‡r¡öë¨è&£ûz¹Þúzf£¢·hšˆ§~†­†Ûÿÿïÿ‘ê_èæ+v‰¨þ)ßø

[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux