]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found
authorJohan Hedberg <johan.hedberg@intel.com>
Sun, 15 Jan 2012 19:01:23 +0000 (21:01 +0200)
committerJohan Hedberg <johan.hedberg@intel.com>
Mon, 13 Feb 2012 15:01:28 +0000 (17:01 +0200)
There's no need to have a separate device class field since the same
information can be encoded into the EIR data.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
include/net/bluetooth/hci_core.h
include/net/bluetooth/mgmt.h
net/bluetooth/mgmt.c

index 393bb73fc999a469ac992317765f78b6981788b6..a0311018a4d021a8af4ef4c94c51e0af3e30f75b 100644 (file)
@@ -893,6 +893,17 @@ static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
        return false;
 }
 
+static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
+                                                               u8 data_len)
+{
+       eir[eir_len++] = sizeof(type) + data_len;
+       eir[eir_len++] = type;
+       memcpy(&eir[eir_len], data, data_len);
+       eir_len += data_len;
+
+       return eir_len;
+}
+
 int hci_register_cb(struct hci_cb *hcb);
 int hci_unregister_cb(struct hci_cb *hcb);
 
index 4f166c834ddbb5bbcca91636b113600e22a06293..bdace523b91092f4a8f80d3458fb700ac9b75c39 100644 (file)
@@ -365,7 +365,6 @@ struct mgmt_ev_auth_failed {
 #define MGMT_EV_DEVICE_FOUND           0x0011
 struct mgmt_ev_device_found {
        struct mgmt_addr_info addr;
-       __u8 dev_class[3];
        __s8 rssi;
        __u8 confirm_name;
        __le16 eir_len;
index b7e7fdfaee380c31dc54b2e3a4965ed159d82bd8..bec64c98b6a9516f9352cecb21212fde93ce9ffb 100644 (file)
@@ -2786,23 +2786,29 @@ int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
 {
        char buf[512];
        struct mgmt_ev_device_found *ev = (void *) buf;
-       size_t ev_size = sizeof(*ev) + eir_len;
+       size_t ev_size;
 
-       if (ev_size > sizeof(buf))
+       /* Leave 5 bytes for a potential CoD field */
+       if (sizeof(*ev) + eir_len + 5 > sizeof(buf))
                return -EINVAL;
 
+       memset(buf, 0, sizeof(buf));
+
        bacpy(&ev->addr.bdaddr, bdaddr);
        ev->addr.type = link_to_mgmt(link_type, addr_type);
        ev->rssi = rssi;
        ev->confirm_name = cfm_name;
 
-       if (eir_len > 0) {
-               put_unaligned_le16(eir_len, &ev->eir_len);
+       if (eir_len > 0)
                memcpy(ev->eir, eir, eir_len);
-       }
 
-       if (dev_class)
-               memcpy(ev->dev_class, dev_class, sizeof(ev->dev_class));
+       if (dev_class && !eir_has_data_type(ev->eir, eir_len, EIR_CLASS_OF_DEV))
+               eir_len = eir_append_data(ev->eir, eir_len, EIR_CLASS_OF_DEV,
+                                                               dev_class, 3);
+
+       put_unaligned_le16(eir_len, &ev->eir_len);
+
+       ev_size = sizeof(*ev) + eir_len;
 
        return mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, ev_size, NULL);
 }