~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/bluetooth/eir.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*
  3  * BlueZ - Bluetooth protocol stack for Linux
  4  *
  5  * Copyright (C) 2021 Intel Corporation
  6  */
  7 
  8 #include <asm/unaligned.h>
  9 
 10 void eir_create(struct hci_dev *hdev, u8 *data);
 11 
 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);
 15 
 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,
 19                            u8 data_len);
 20 
 21 static inline u16 eir_precalc_len(u8 data_len)
 22 {
 23         return sizeof(u8) * 2 + data_len;
 24 }
 25 
 26 static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type,
 27                                   u8 *data, u8 data_len)
 28 {
 29         eir[eir_len++] = sizeof(type) + data_len;
 30         eir[eir_len++] = type;
 31         memcpy(&eir[eir_len], data, data_len);
 32         eir_len += data_len;
 33 
 34         return eir_len;
 35 }
 36 
 37 static inline u16 eir_append_le16(u8 *eir, u16 eir_len, u8 type, u16 data)
 38 {
 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);
 43 
 44         return eir_len;
 45 }
 46 
 47 static inline u16 eir_skb_put_data(struct sk_buff *skb, u8 type, u8 *data, u8 data_len)
 48 {
 49         u8 *eir;
 50         u16 eir_len;
 51 
 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;
 56         eir[1] = type;
 57         memcpy(&eir[2], data, data_len);
 58 
 59         return eir_len;
 60 }
 61 
 62 static inline void *eir_get_data(u8 *eir, size_t eir_len, u8 type,
 63                                  size_t *data_len)
 64 {
 65         size_t parsed = 0;
 66 
 67         if (eir_len < 2)
 68                 return NULL;
 69 
 70         while (parsed < eir_len - 1) {
 71                 u8 field_len = eir[0];
 72 
 73                 if (field_len == 0)
 74                         break;
 75 
 76                 parsed += field_len + 1;
 77 
 78                 if (parsed > eir_len)
 79                         break;
 80 
 81                 if (eir[1] != type) {
 82                         eir += field_len + 1;
 83                         continue;
 84                 }
 85 
 86                 /* Zero length data */
 87                 if (field_len == 1)
 88                         return NULL;
 89 
 90                 if (data_len)
 91                         *data_len = field_len - 1;
 92 
 93                 return &eir[2];
 94         }
 95 
 96         return NULL;
 97 }
 98 
 99 void *eir_get_service_data(u8 *eir, size_t eir_len, u16 uuid, size_t *len);
100 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php