diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2016-01-05 06:19:31 -0500 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2016-01-05 11:02:49 -0500 |
commit | 0d3b7f64c84d53658daf28e2f9772e38acb9340d (patch) | |
tree | d6804e10698572dd927fbc11837bed1bf9f8c5c9 /include/net | |
parent | 29663b0cc1d5b9b6e2f6caf41e86c599a0310def (diff) |
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.h | 30 |
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, | |||
1283 | mutex_unlock(&hci_cb_list_lock); | 1283 | mutex_unlock(&hci_cb_list_lock); |
1284 | } | 1284 | } |
1285 | 1285 | ||
1286 | static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) | 1286 | static inline void *eir_get_data(u8 *eir, size_t eir_len, u8 type, |
1287 | size_t *data_len) | ||
1287 | { | 1288 | { |
1288 | size_t parsed = 0; | 1289 | size_t parsed = 0; |
1289 | 1290 | ||
1290 | if (data_len < 2) | 1291 | if (eir_len < 2) |
1291 | return false; | 1292 | return NULL; |
1292 | 1293 | ||
1293 | while (parsed < data_len - 1) { | 1294 | while (parsed < eir_len - 1) { |
1294 | u8 field_len = data[0]; | 1295 | u8 field_len = eir[0]; |
1295 | 1296 | ||
1296 | if (field_len == 0) | 1297 | if (field_len == 0) |
1297 | break; | 1298 | break; |
1298 | 1299 | ||
1299 | parsed += field_len + 1; | 1300 | parsed += field_len + 1; |
1300 | 1301 | ||
1301 | if (parsed > data_len) | 1302 | if (parsed > eir_len) |
1302 | break; | 1303 | break; |
1303 | 1304 | ||
1304 | if (data[1] == type) | 1305 | if (eir[1] != type) { |
1305 | return true; | 1306 | eir += field_len + 1; |
1307 | continue; | ||
1308 | } | ||
1309 | |||
1310 | /* Zero length data */ | ||
1311 | if (field_len == 1) | ||
1312 | return NULL; | ||
1306 | 1313 | ||
1307 | data += field_len + 1; | 1314 | if (data_len) |
1315 | *data_len = field_len - 1; | ||
1316 | |||
1317 | return &eir[2]; | ||
1308 | } | 1318 | } |
1309 | 1319 | ||
1310 | return false; | 1320 | return NULL; |
1311 | } | 1321 | } |
1312 | 1322 | ||
1313 | static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type) | 1323 | static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type) |