1 /* SPDX-License-Identifier: GPL-2.0 */
3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2021 Intel Corporation
8 #include <asm/unaligned.h>
10 void eir_create(struct hci_dev *hdev, u8 *data);
12 u8 eir_create_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr);
13 u8 eir_create_scan_rsp(struct hci_dev *hdev, u8 instance, u8 *ptr);
14 u8 eir_create_per_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr);
16 u8 eir_append_local_name(struct hci_dev *hdev, u8 *eir, u8 ad_len);
17 u8 eir_append_appearance(struct hci_dev *hdev, u8 *ptr, u8 ad_len);
18 u8 eir_append_service_data(u8 *eir, u16 eir_len, u16 uuid, u8 *data,
21 static inline u16 eir_precalc_len(u8 data_len)
23 return sizeof(u8) * 2 + data_len;
26 static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type,
27 u8 *data, u8 data_len)
29 eir[eir_len++] = sizeof(type) + data_len;
30 eir[eir_len++] = type;
31 memcpy(&eir[eir_len], data, data_len);
37 static inline u16 eir_append_le16(u8 *eir, u16 eir_len, u8 type, u16 data)
39 eir[eir_len++] = sizeof(type) + sizeof(data);
40 eir[eir_len++] = type;
41 put_unaligned_le16(data, &eir[eir_len]);
42 eir_len += sizeof(data);
47 static inline u16 eir_skb_put_data(struct sk_buff *skb, u8 type, u8 *data, u8 data_len)
52 eir_len = eir_precalc_len(data_len);
53 eir = skb_put(skb, eir_len);
54 WARN_ON(sizeof(type) + data_len > U8_MAX);
55 eir[0] = sizeof(type) + data_len;
57 memcpy(&eir[2], data, data_len);
62 static inline void *eir_get_data(u8 *eir, size_t eir_len, u8 type,
70 while (parsed < eir_len - 1) {
71 u8 field_len = eir[0];
76 parsed += field_len + 1;
86 /* Zero length data */
91 *data_len = field_len - 1;
99 void *eir_get_service_data(u8 *eir, size_t eir_len, u16 uuid, size_t *len);