From: Johan Hedberg <johan.hedberg@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 07/15] Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found
Date: Wed, 18 Jan 2012 20:51:49 +0200 [thread overview]
Message-ID: <1326912717-6347-8-git-send-email-johan.hedberg@gmail.com> (raw)
In-Reply-To: <1326912717-6347-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
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>
---
include/net/bluetooth/hci_core.h | 11 +++++++++++
include/net/bluetooth/mgmt.h | 1 -
net/bluetooth/mgmt.c | 20 +++++++++++++-------
3 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 393bb73..02aa0f9 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)
return false;
}
+static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
+ u16 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);
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 4f166c8..bdace52 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -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;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index b7e7fdf..bec64c9 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,
{
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);
}
--
1.7.8.3
next prev parent reply other threads:[~2012-01-18 18:51 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-18 18:51 [PATCH 0/15] Bluetooth: Update to latest mgmt API Johan Hedberg
2012-01-18 18:51 ` [PATCH 01/15] Bluetooth: Fix clearing persistent flags Johan Hedberg
2012-01-18 19:02 ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 02/15] Bluetooth: Rename mgmt connected events to match user space Johan Hedberg
2012-01-18 19:03 ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 03/15] Bluetooth: Add eir_len parameter to mgmt_ev_device_found Johan Hedberg
2012-01-18 19:04 ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 04/15] Bluetooth: Rename eir_has_complete_name to eir_has_data_type Johan Hedberg
2012-01-18 19:05 ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 05/15] Bluetooth: Add missing EIR defines to hci.h Johan Hedberg
2012-01-18 19:05 ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 06/15] Bluetooth: Move eir_has_data_field to hci_core.h Johan Hedberg
2012-01-18 19:06 ` Marcel Holtmann
2012-01-18 18:51 ` Johan Hedberg [this message]
2012-01-18 19:08 ` [PATCH 07/15] Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found Marcel Holtmann
2012-01-18 19:18 ` Anderson Lizardo
2012-01-18 20:29 ` Johan Hedberg
2012-01-18 20:40 ` Anderson Lizardo
2012-01-18 20:58 ` Johan Hedberg
2012-01-19 9:26 ` Andrei Emeltchenko
2012-01-18 18:51 ` [PATCH 08/15] Bluetooth: Rename conn->pend to conn->flags Johan Hedberg
2012-01-18 19:12 ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 09/15] Bluetooth: Merge boolean members of struct hci_conn into flags Johan Hedberg
2012-01-18 19:12 ` Marcel Holtmann
2012-01-18 19:25 ` Johan Hedberg
2012-01-18 19:31 ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 10/15] Bluetooth: Add a convenience function to check for SSP enabled Johan Hedberg
2012-01-18 19:14 ` Marcel Holtmann
2012-01-19 9:30 ` Andrei Emeltchenko
2012-01-19 9:39 ` Johan Hedberg
2012-01-18 18:51 ` [PATCH 11/15] Bluetooth: Convert hdev->ssp_mode to a flag Johan Hedberg
2012-01-18 19:14 ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 12/15] Bluetooth: Convert hdev->out to a bool type Johan Hedberg
2012-01-18 19:15 ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 13/15] Bluetooth: Update device_connected and device_found events to latest API Johan Hedberg
2012-01-18 19:17 ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 14/15] Bluetooth: Rename hdev->flags to hdev->compat_flags Johan Hedberg
2012-01-18 19:18 ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 15/15] Bluetooth: Rename hdev->dev_flags to hdev-flags Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1326912717-6347-8-git-send-email-johan.hedberg@gmail.com \
--to=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).