Bluetooth: Fix EIR data generation for mgmt_device_found
authorVishal Agarwal <vishal.agarwal@stericsson.com>
Thu, 26 Apr 2012 13:49:56 +0000 (19:19 +0530)
committerGustavo Padovan <gustavo.padovan@collabora.co.uk>
Wed, 16 May 2012 19:13:19 +0000 (16:13 -0300)
The mgmt_device_found function expects to receive only the significant
part of the EIR data so it needs to be removed before calling the
function. This patch adds a new eir_get_length() helper function to
calculate the length of the significant part.

Signed-off-by: Vishal Agarwal <vishal.agarwal@stericsson.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
include/net/bluetooth/hci_core.h
net/bluetooth/hci_event.c

index b60d2c844ebad87c5e6180177375bbdcdfc56f64..9fc7728f94e4af3adaaed5944b5c665823363fc4 100644 (file)
@@ -926,6 +926,23 @@ static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
        return false;
 }
 
+static inline size_t eir_get_length(u8 *eir, size_t eir_len)
+{
+       size_t parsed = 0;
+
+       while (parsed < eir_len) {
+               u8 field_len = eir[0];
+
+               if (field_len == 0)
+                       return parsed;
+
+               parsed += field_len + 1;
+               eir += field_len + 1;
+       }
+
+       return eir_len;
+}
+
 static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
                                  u8 data_len)
 {
index fac840afd13152e35b1311fe3427567f9fa1f214..9c60e0d8db5f6b1e101b5f8a53a2ad6f7a91ace9 100644 (file)
@@ -3001,6 +3001,7 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct
        struct inquiry_data data;
        struct extended_inquiry_info *info = (void *) (skb->data + 1);
        int num_rsp = *((__u8 *) skb->data);
+       size_t eir_len;
 
        BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
 
@@ -3033,9 +3034,10 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct
 
                name_known = hci_inquiry_cache_update(hdev, &data, name_known,
                                                      &ssp);
+               eir_len = eir_get_length(info->data, sizeof(info->data));
                mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
                                  info->dev_class, info->rssi, !name_known,
-                                 ssp, info->data, sizeof(info->data));
+                                 ssp, info->data, eir_len);
        }
 
        hci_dev_unlock(hdev);