aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2012-01-15 14:01:23 -0500
committerJohan Hedberg <johan.hedberg@intel.com>2012-02-13 10:01:28 -0500
commit1dc06093a9f353ef19b7b5180602884d0ce065c5 (patch)
treeea919a19d06f60f0843ada9d198a4870e58037f1
parent6759a67579a927f2a92f398cf67555e6cc92d0ff (diff)
Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found
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>
-rw-r--r--include/net/bluetooth/hci_core.h11
-rw-r--r--include/net/bluetooth/mgmt.h1
-rw-r--r--net/bluetooth/mgmt.c20
3 files changed, 24 insertions, 8 deletions
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 393bb73fc999..a0311018a4d0 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -893,6 +893,17 @@ static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
893 return false; 893 return false;
894} 894}
895 895
896static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
897 u8 data_len)
898{
899 eir[eir_len++] = sizeof(type) + data_len;
900 eir[eir_len++] = type;
901 memcpy(&eir[eir_len], data, data_len);
902 eir_len += data_len;
903
904 return eir_len;
905}
906
896int hci_register_cb(struct hci_cb *hcb); 907int hci_register_cb(struct hci_cb *hcb);
897int hci_unregister_cb(struct hci_cb *hcb); 908int hci_unregister_cb(struct hci_cb *hcb);
898 909
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 4f166c834ddb..bdace523b910 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -365,7 +365,6 @@ struct mgmt_ev_auth_failed {
365#define MGMT_EV_DEVICE_FOUND 0x0011 365#define MGMT_EV_DEVICE_FOUND 0x0011
366struct mgmt_ev_device_found { 366struct mgmt_ev_device_found {
367 struct mgmt_addr_info addr; 367 struct mgmt_addr_info addr;
368 __u8 dev_class[3];
369 __s8 rssi; 368 __s8 rssi;
370 __u8 confirm_name; 369 __u8 confirm_name;
371 __le16 eir_len; 370 __le16 eir_len;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index b7e7fdfaee38..bec64c98b6a9 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2786,23 +2786,29 @@ int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2786{ 2786{
2787 char buf[512]; 2787 char buf[512];
2788 struct mgmt_ev_device_found *ev = (void *) buf; 2788 struct mgmt_ev_device_found *ev = (void *) buf;
2789 size_t ev_size = sizeof(*ev) + eir_len; 2789 size_t ev_size;
2790 2790
2791 if (ev_size > sizeof(buf)) 2791 /* Leave 5 bytes for a potential CoD field */
2792 if (sizeof(*ev) + eir_len + 5 > sizeof(buf))
2792 return -EINVAL; 2793 return -EINVAL;
2793 2794
2795 memset(buf, 0, sizeof(buf));
2796
2794 bacpy(&ev->addr.bdaddr, bdaddr); 2797 bacpy(&ev->addr.bdaddr, bdaddr);
2795 ev->addr.type = link_to_mgmt(link_type, addr_type); 2798 ev->addr.type = link_to_mgmt(link_type, addr_type);
2796 ev->rssi = rssi; 2799 ev->rssi = rssi;
2797 ev->confirm_name = cfm_name; 2800 ev->confirm_name = cfm_name;
2798 2801
2799 if (eir_len > 0) { 2802 if (eir_len > 0)
2800 put_unaligned_le16(eir_len, &ev->eir_len);
2801 memcpy(ev->eir, eir, eir_len); 2803 memcpy(ev->eir, eir, eir_len);
2802 }
2803 2804
2804 if (dev_class) 2805 if (dev_class && !eir_has_data_type(ev->eir, eir_len, EIR_CLASS_OF_DEV))
2805 memcpy(ev->dev_class, dev_class, sizeof(ev->dev_class)); 2806 eir_len = eir_append_data(ev->eir, eir_len, EIR_CLASS_OF_DEV,
2807 dev_class, 3);
2808
2809 put_unaligned_le16(eir_len, &ev->eir_len);
2810
2811 ev_size = sizeof(*ev) + eir_len;
2806 2812
2807 return mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, ev_size, NULL); 2813 return mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, ev_size, NULL);
2808} 2814}