summaryrefslogtreecommitdiffstats
path: root/include/net
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2016-01-05 13:19:31 +0200
committerMarcel Holtmann <marcel@holtmann.org>2016-01-05 17:02:49 +0100
commit0d3b7f64c84d53658daf28e2f9772e38acb9340d (patch)
treed6804e10698572dd927fbc11837bed1bf9f8c5c9 /include/net
parent29663b0cc1d5b9b6e2f6caf41e86c599a0310def (diff)
downloadlinux-0d3b7f64c84d53658daf28e2f9772e38acb9340d.tar.bz2
Bluetooth: Change eir_has_data_type() to more generic eir_get_data()
To make the EIR parsing helper more general purpose, make it return the found data and its length rather than just saying whether the data was present or not. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'include/net')
-rw-r--r--include/net/bluetooth/hci_core.h30
1 files changed, 20 insertions, 10 deletions
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index c95e0326c41a..372e2a7c4ada 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1283,31 +1283,41 @@ static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
mutex_unlock(&hci_cb_list_lock);
}
-static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
+static inline void *eir_get_data(u8 *eir, size_t eir_len, u8 type,
+ size_t *data_len)
{
size_t parsed = 0;
- if (data_len < 2)
- return false;
+ if (eir_len < 2)
+ return NULL;
- while (parsed < data_len - 1) {
- u8 field_len = data[0];
+ while (parsed < eir_len - 1) {
+ u8 field_len = eir[0];
if (field_len == 0)
break;
parsed += field_len + 1;
- if (parsed > data_len)
+ if (parsed > eir_len)
break;
- if (data[1] == type)
- return true;
+ if (eir[1] != type) {
+ eir += field_len + 1;
+ continue;
+ }
+
+ /* Zero length data */
+ if (field_len == 1)
+ return NULL;
- data += field_len + 1;
+ if (data_len)
+ *data_len = field_len - 1;
+
+ return &eir[2];
}
- return false;
+ return NULL;
}
static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type)