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

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

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/bluetooth/eir.c (Version linux-6.12-rc7) and /net/bluetooth/eir.c (Version linux-6.6.60)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  * BlueZ - Bluetooth protocol stack for Linux       3  * BlueZ - Bluetooth protocol stack for Linux
  4  *                                                  4  *
  5  * Copyright (C) 2021 Intel Corporation             5  * Copyright (C) 2021 Intel Corporation
  6  */                                                 6  */
  7                                                     7 
  8 #include <net/bluetooth/bluetooth.h>                8 #include <net/bluetooth/bluetooth.h>
  9 #include <net/bluetooth/hci_core.h>                 9 #include <net/bluetooth/hci_core.h>
 10 #include <net/bluetooth/mgmt.h>                    10 #include <net/bluetooth/mgmt.h>
 11                                                    11 
 12 #include "eir.h"                                   12 #include "eir.h"
 13                                                    13 
 14 #define PNP_INFO_SVCLASS_ID             0x1200     14 #define PNP_INFO_SVCLASS_ID             0x1200
 15                                                    15 
 16 u8 eir_append_local_name(struct hci_dev *hdev,     16 u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
 17 {                                                  17 {
 18         size_t short_len;                          18         size_t short_len;
 19         size_t complete_len;                       19         size_t complete_len;
 20                                                    20 
 21         /* no space left for name (+ type + le     21         /* no space left for name (+ type + len) */
 22         if ((max_adv_len(hdev) - ad_len) < HCI     22         if ((max_adv_len(hdev) - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 2)
 23                 return ad_len;                     23                 return ad_len;
 24                                                    24 
 25         /* use complete name if present and fi     25         /* use complete name if present and fits */
 26         complete_len = strnlen(hdev->dev_name,     26         complete_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name));
 27         if (complete_len && complete_len <= HC     27         if (complete_len && complete_len <= HCI_MAX_SHORT_NAME_LENGTH)
 28                 return eir_append_data(ptr, ad     28                 return eir_append_data(ptr, ad_len, EIR_NAME_COMPLETE,
 29                                        hdev->d     29                                        hdev->dev_name, complete_len);
 30                                                    30 
 31         /* use short name if present */            31         /* use short name if present */
 32         short_len = strnlen(hdev->short_name,      32         short_len = strnlen(hdev->short_name, sizeof(hdev->short_name));
 33         if (short_len)                             33         if (short_len)
 34                 return eir_append_data(ptr, ad     34                 return eir_append_data(ptr, ad_len, EIR_NAME_SHORT,
 35                                        hdev->s     35                                        hdev->short_name,
 36                                        short_l     36                                        short_len);
 37                                                    37 
 38         /* use shortened full name if present,     38         /* use shortened full name if present, we already know that name
 39          * is longer then HCI_MAX_SHORT_NAME_L     39          * is longer then HCI_MAX_SHORT_NAME_LENGTH
 40          */                                        40          */
 41         if (complete_len)                          41         if (complete_len)
 42                 return eir_append_data(ptr, ad     42                 return eir_append_data(ptr, ad_len, EIR_NAME_SHORT,
 43                                        hdev->d     43                                        hdev->dev_name,
 44                                        HCI_MAX     44                                        HCI_MAX_SHORT_NAME_LENGTH);
 45                                                    45 
 46         return ad_len;                             46         return ad_len;
 47 }                                                  47 }
 48                                                    48 
 49 u8 eir_append_appearance(struct hci_dev *hdev,     49 u8 eir_append_appearance(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
 50 {                                                  50 {
 51         return eir_append_le16(ptr, ad_len, EI     51         return eir_append_le16(ptr, ad_len, EIR_APPEARANCE, hdev->appearance);
 52 }                                                  52 }
 53                                                    53 
 54 u8 eir_append_service_data(u8 *eir, u16 eir_le     54 u8 eir_append_service_data(u8 *eir, u16 eir_len, u16 uuid, u8 *data,
 55                            u8 data_len)            55                            u8 data_len)
 56 {                                                  56 {
 57         eir[eir_len++] = sizeof(u8) + sizeof(u     57         eir[eir_len++] = sizeof(u8) + sizeof(uuid) + data_len;
 58         eir[eir_len++] = EIR_SERVICE_DATA;         58         eir[eir_len++] = EIR_SERVICE_DATA;
 59         put_unaligned_le16(uuid, &eir[eir_len]     59         put_unaligned_le16(uuid, &eir[eir_len]);
 60         eir_len += sizeof(uuid);                   60         eir_len += sizeof(uuid);
 61         memcpy(&eir[eir_len], data, data_len);     61         memcpy(&eir[eir_len], data, data_len);
 62         eir_len += data_len;                       62         eir_len += data_len;
 63                                                    63 
 64         return eir_len;                            64         return eir_len;
 65 }                                                  65 }
 66                                                    66 
 67 static u8 *create_uuid16_list(struct hci_dev *     67 static u8 *create_uuid16_list(struct hci_dev *hdev, u8 *data, ptrdiff_t len)
 68 {                                                  68 {
 69         u8 *ptr = data, *uuids_start = NULL;       69         u8 *ptr = data, *uuids_start = NULL;
 70         struct bt_uuid *uuid;                      70         struct bt_uuid *uuid;
 71                                                    71 
 72         if (len < 4)                               72         if (len < 4)
 73                 return ptr;                        73                 return ptr;
 74                                                    74 
 75         list_for_each_entry(uuid, &hdev->uuids     75         list_for_each_entry(uuid, &hdev->uuids, list) {
 76                 u16 uuid16;                        76                 u16 uuid16;
 77                                                    77 
 78                 if (uuid->size != 16)              78                 if (uuid->size != 16)
 79                         continue;                  79                         continue;
 80                                                    80 
 81                 uuid16 = get_unaligned_le16(&u     81                 uuid16 = get_unaligned_le16(&uuid->uuid[12]);
 82                 if (uuid16 < 0x1100)               82                 if (uuid16 < 0x1100)
 83                         continue;                  83                         continue;
 84                                                    84 
 85                 if (uuid16 == PNP_INFO_SVCLASS     85                 if (uuid16 == PNP_INFO_SVCLASS_ID)
 86                         continue;                  86                         continue;
 87                                                    87 
 88                 if (!uuids_start) {                88                 if (!uuids_start) {
 89                         uuids_start = ptr;         89                         uuids_start = ptr;
 90                         uuids_start[0] = 1;        90                         uuids_start[0] = 1;
 91                         uuids_start[1] = EIR_U     91                         uuids_start[1] = EIR_UUID16_ALL;
 92                         ptr += 2;                  92                         ptr += 2;
 93                 }                                  93                 }
 94                                                    94 
 95                 /* Stop if not enough space to     95                 /* Stop if not enough space to put next UUID */
 96                 if ((ptr - data) + sizeof(u16)     96                 if ((ptr - data) + sizeof(u16) > len) {
 97                         uuids_start[1] = EIR_U     97                         uuids_start[1] = EIR_UUID16_SOME;
 98                         break;                     98                         break;
 99                 }                                  99                 }
100                                                   100 
101                 *ptr++ = (uuid16 & 0x00ff);       101                 *ptr++ = (uuid16 & 0x00ff);
102                 *ptr++ = (uuid16 & 0xff00) >>     102                 *ptr++ = (uuid16 & 0xff00) >> 8;
103                 uuids_start[0] += sizeof(uuid1    103                 uuids_start[0] += sizeof(uuid16);
104         }                                         104         }
105                                                   105 
106         return ptr;                               106         return ptr;
107 }                                                 107 }
108                                                   108 
109 static u8 *create_uuid32_list(struct hci_dev *    109 static u8 *create_uuid32_list(struct hci_dev *hdev, u8 *data, ptrdiff_t len)
110 {                                                 110 {
111         u8 *ptr = data, *uuids_start = NULL;      111         u8 *ptr = data, *uuids_start = NULL;
112         struct bt_uuid *uuid;                     112         struct bt_uuid *uuid;
113                                                   113 
114         if (len < 6)                              114         if (len < 6)
115                 return ptr;                       115                 return ptr;
116                                                   116 
117         list_for_each_entry(uuid, &hdev->uuids    117         list_for_each_entry(uuid, &hdev->uuids, list) {
118                 if (uuid->size != 32)             118                 if (uuid->size != 32)
119                         continue;                 119                         continue;
120                                                   120 
121                 if (!uuids_start) {               121                 if (!uuids_start) {
122                         uuids_start = ptr;        122                         uuids_start = ptr;
123                         uuids_start[0] = 1;       123                         uuids_start[0] = 1;
124                         uuids_start[1] = EIR_U    124                         uuids_start[1] = EIR_UUID32_ALL;
125                         ptr += 2;                 125                         ptr += 2;
126                 }                                 126                 }
127                                                   127 
128                 /* Stop if not enough space to    128                 /* Stop if not enough space to put next UUID */
129                 if ((ptr - data) + sizeof(u32)    129                 if ((ptr - data) + sizeof(u32) > len) {
130                         uuids_start[1] = EIR_U    130                         uuids_start[1] = EIR_UUID32_SOME;
131                         break;                    131                         break;
132                 }                                 132                 }
133                                                   133 
134                 memcpy(ptr, &uuid->uuid[12], s    134                 memcpy(ptr, &uuid->uuid[12], sizeof(u32));
135                 ptr += sizeof(u32);               135                 ptr += sizeof(u32);
136                 uuids_start[0] += sizeof(u32);    136                 uuids_start[0] += sizeof(u32);
137         }                                         137         }
138                                                   138 
139         return ptr;                               139         return ptr;
140 }                                                 140 }
141                                                   141 
142 static u8 *create_uuid128_list(struct hci_dev     142 static u8 *create_uuid128_list(struct hci_dev *hdev, u8 *data, ptrdiff_t len)
143 {                                                 143 {
144         u8 *ptr = data, *uuids_start = NULL;      144         u8 *ptr = data, *uuids_start = NULL;
145         struct bt_uuid *uuid;                     145         struct bt_uuid *uuid;
146                                                   146 
147         if (len < 18)                             147         if (len < 18)
148                 return ptr;                       148                 return ptr;
149                                                   149 
150         list_for_each_entry(uuid, &hdev->uuids    150         list_for_each_entry(uuid, &hdev->uuids, list) {
151                 if (uuid->size != 128)            151                 if (uuid->size != 128)
152                         continue;                 152                         continue;
153                                                   153 
154                 if (!uuids_start) {               154                 if (!uuids_start) {
155                         uuids_start = ptr;        155                         uuids_start = ptr;
156                         uuids_start[0] = 1;       156                         uuids_start[0] = 1;
157                         uuids_start[1] = EIR_U    157                         uuids_start[1] = EIR_UUID128_ALL;
158                         ptr += 2;                 158                         ptr += 2;
159                 }                                 159                 }
160                                                   160 
161                 /* Stop if not enough space to    161                 /* Stop if not enough space to put next UUID */
162                 if ((ptr - data) + 16 > len) {    162                 if ((ptr - data) + 16 > len) {
163                         uuids_start[1] = EIR_U    163                         uuids_start[1] = EIR_UUID128_SOME;
164                         break;                    164                         break;
165                 }                                 165                 }
166                                                   166 
167                 memcpy(ptr, uuid->uuid, 16);      167                 memcpy(ptr, uuid->uuid, 16);
168                 ptr += 16;                        168                 ptr += 16;
169                 uuids_start[0] += 16;             169                 uuids_start[0] += 16;
170         }                                         170         }
171                                                   171 
172         return ptr;                               172         return ptr;
173 }                                                 173 }
174                                                   174 
175 void eir_create(struct hci_dev *hdev, u8 *data    175 void eir_create(struct hci_dev *hdev, u8 *data)
176 {                                                 176 {
177         u8 *ptr = data;                           177         u8 *ptr = data;
178         size_t name_len;                          178         size_t name_len;
179                                                   179 
180         name_len = strnlen(hdev->dev_name, siz    180         name_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name));
181                                                   181 
182         if (name_len > 0) {                       182         if (name_len > 0) {
183                 /* EIR Data type */               183                 /* EIR Data type */
184                 if (name_len > 48) {              184                 if (name_len > 48) {
185                         name_len = 48;            185                         name_len = 48;
186                         ptr[1] = EIR_NAME_SHOR    186                         ptr[1] = EIR_NAME_SHORT;
187                 } else {                          187                 } else {
188                         ptr[1] = EIR_NAME_COMP    188                         ptr[1] = EIR_NAME_COMPLETE;
189                 }                                 189                 }
190                                                   190 
191                 /* EIR Data length */             191                 /* EIR Data length */
192                 ptr[0] = name_len + 1;            192                 ptr[0] = name_len + 1;
193                                                   193 
194                 memcpy(ptr + 2, hdev->dev_name    194                 memcpy(ptr + 2, hdev->dev_name, name_len);
195                                                   195 
196                 ptr += (name_len + 2);            196                 ptr += (name_len + 2);
197         }                                         197         }
198                                                   198 
199         if (hdev->inq_tx_power != HCI_TX_POWER    199         if (hdev->inq_tx_power != HCI_TX_POWER_INVALID) {
200                 ptr[0] = 2;                       200                 ptr[0] = 2;
201                 ptr[1] = EIR_TX_POWER;            201                 ptr[1] = EIR_TX_POWER;
202                 ptr[2] = (u8)hdev->inq_tx_powe    202                 ptr[2] = (u8)hdev->inq_tx_power;
203                                                   203 
204                 ptr += 3;                         204                 ptr += 3;
205         }                                         205         }
206                                                   206 
207         if (hdev->devid_source > 0) {             207         if (hdev->devid_source > 0) {
208                 ptr[0] = 9;                       208                 ptr[0] = 9;
209                 ptr[1] = EIR_DEVICE_ID;           209                 ptr[1] = EIR_DEVICE_ID;
210                                                   210 
211                 put_unaligned_le16(hdev->devid    211                 put_unaligned_le16(hdev->devid_source, ptr + 2);
212                 put_unaligned_le16(hdev->devid    212                 put_unaligned_le16(hdev->devid_vendor, ptr + 4);
213                 put_unaligned_le16(hdev->devid    213                 put_unaligned_le16(hdev->devid_product, ptr + 6);
214                 put_unaligned_le16(hdev->devid    214                 put_unaligned_le16(hdev->devid_version, ptr + 8);
215                                                   215 
216                 ptr += 10;                        216                 ptr += 10;
217         }                                         217         }
218                                                   218 
219         ptr = create_uuid16_list(hdev, ptr, HC    219         ptr = create_uuid16_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data));
220         ptr = create_uuid32_list(hdev, ptr, HC    220         ptr = create_uuid32_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data));
221         ptr = create_uuid128_list(hdev, ptr, H    221         ptr = create_uuid128_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data));
222 }                                                 222 }
223                                                   223 
224 u8 eir_create_per_adv_data(struct hci_dev *hde    224 u8 eir_create_per_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr)
225 {                                                 225 {
226         struct adv_info *adv = NULL;              226         struct adv_info *adv = NULL;
227         u8 ad_len = 0;                            227         u8 ad_len = 0;
228                                                   228 
229         /* Return 0 when the current instance     229         /* Return 0 when the current instance identifier is invalid. */
230         if (instance) {                           230         if (instance) {
231                 adv = hci_find_adv_instance(hd    231                 adv = hci_find_adv_instance(hdev, instance);
232                 if (!adv)                         232                 if (!adv)
233                         return 0;                 233                         return 0;
234         }                                         234         }
235                                                   235 
236         if (adv) {                                236         if (adv) {
237                 memcpy(ptr, adv->per_adv_data,    237                 memcpy(ptr, adv->per_adv_data, adv->per_adv_data_len);
238                 ad_len += adv->per_adv_data_le    238                 ad_len += adv->per_adv_data_len;
239                 ptr += adv->per_adv_data_len;     239                 ptr += adv->per_adv_data_len;
240         }                                         240         }
241                                                   241 
242         return ad_len;                            242         return ad_len;
243 }                                                 243 }
244                                                   244 
245 u8 eir_create_adv_data(struct hci_dev *hdev, u    245 u8 eir_create_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr)
246 {                                                 246 {
247         struct adv_info *adv = NULL;              247         struct adv_info *adv = NULL;
248         u8 ad_len = 0, flags = 0;                 248         u8 ad_len = 0, flags = 0;
249         u32 instance_flags;                       249         u32 instance_flags;
250                                                   250 
251         /* Return 0 when the current instance     251         /* Return 0 when the current instance identifier is invalid. */
252         if (instance) {                           252         if (instance) {
253                 adv = hci_find_adv_instance(hd    253                 adv = hci_find_adv_instance(hdev, instance);
254                 if (!adv)                         254                 if (!adv)
255                         return 0;                 255                         return 0;
256         }                                         256         }
257                                                   257 
258         instance_flags = hci_adv_instance_flag    258         instance_flags = hci_adv_instance_flags(hdev, instance);
259                                                   259 
260         /* If instance already has the flags s    260         /* If instance already has the flags set skip adding it once
261          * again.                                 261          * again.
262          */                                       262          */
263         if (adv && eir_get_data(adv->adv_data,    263         if (adv && eir_get_data(adv->adv_data, adv->adv_data_len, EIR_FLAGS,
264                                 NULL))            264                                 NULL))
265                 goto skip_flags;                  265                 goto skip_flags;
266                                                   266 
267         /* The Add Advertising command allows     267         /* The Add Advertising command allows userspace to set both the general
268          * and limited discoverable flags.        268          * and limited discoverable flags.
269          */                                       269          */
270         if (instance_flags & MGMT_ADV_FLAG_DIS    270         if (instance_flags & MGMT_ADV_FLAG_DISCOV)
271                 flags |= LE_AD_GENERAL;           271                 flags |= LE_AD_GENERAL;
272                                                   272 
273         if (instance_flags & MGMT_ADV_FLAG_LIM    273         if (instance_flags & MGMT_ADV_FLAG_LIMITED_DISCOV)
274                 flags |= LE_AD_LIMITED;           274                 flags |= LE_AD_LIMITED;
275                                                   275 
276         if (!hci_dev_test_flag(hdev, HCI_BREDR    276         if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))
277                 flags |= LE_AD_NO_BREDR;          277                 flags |= LE_AD_NO_BREDR;
278                                                   278 
279         if (flags || (instance_flags & MGMT_AD    279         if (flags || (instance_flags & MGMT_ADV_FLAG_MANAGED_FLAGS)) {
280                 /* If a discovery flag wasn't     280                 /* If a discovery flag wasn't provided, simply use the global
281                  * settings.                      281                  * settings.
282                  */                               282                  */
283                 if (!flags)                       283                 if (!flags)
284                         flags |= mgmt_get_adv_    284                         flags |= mgmt_get_adv_discov_flags(hdev);
285                                                   285 
286                 /* If flags would still be emp    286                 /* If flags would still be empty, then there is no need to
287                  * include the "Flags" AD fiel    287                  * include the "Flags" AD field".
288                  */                               288                  */
289                 if (flags) {                      289                 if (flags) {
290                         ptr[0] = 0x02;            290                         ptr[0] = 0x02;
291                         ptr[1] = EIR_FLAGS;       291                         ptr[1] = EIR_FLAGS;
292                         ptr[2] = flags;           292                         ptr[2] = flags;
293                                                   293 
294                         ad_len += 3;              294                         ad_len += 3;
295                         ptr += 3;                 295                         ptr += 3;
296                 }                                 296                 }
297         }                                         297         }
298                                                   298 
299 skip_flags:                                       299 skip_flags:
300         if (adv) {                                300         if (adv) {
301                 memcpy(ptr, adv->adv_data, adv    301                 memcpy(ptr, adv->adv_data, adv->adv_data_len);
302                 ad_len += adv->adv_data_len;      302                 ad_len += adv->adv_data_len;
303                 ptr += adv->adv_data_len;         303                 ptr += adv->adv_data_len;
304         }                                         304         }
305                                                   305 
306         if (instance_flags & MGMT_ADV_FLAG_TX_    306         if (instance_flags & MGMT_ADV_FLAG_TX_POWER) {
307                 s8 adv_tx_power;                  307                 s8 adv_tx_power;
308                                                   308 
309                 if (ext_adv_capable(hdev)) {      309                 if (ext_adv_capable(hdev)) {
310                         if (adv)                  310                         if (adv)
311                                 adv_tx_power =    311                                 adv_tx_power = adv->tx_power;
312                         else                      312                         else
313                                 adv_tx_power =    313                                 adv_tx_power = hdev->adv_tx_power;
314                 } else {                          314                 } else {
315                         adv_tx_power = hdev->a    315                         adv_tx_power = hdev->adv_tx_power;
316                 }                                 316                 }
317                                                   317 
318                 /* Provide Tx Power only if we    318                 /* Provide Tx Power only if we can provide a valid value for it */
319                 if (adv_tx_power != HCI_TX_POW    319                 if (adv_tx_power != HCI_TX_POWER_INVALID) {
320                         ptr[0] = 0x02;            320                         ptr[0] = 0x02;
321                         ptr[1] = EIR_TX_POWER;    321                         ptr[1] = EIR_TX_POWER;
322                         ptr[2] = (u8)adv_tx_po    322                         ptr[2] = (u8)adv_tx_power;
323                                                   323 
324                         ad_len += 3;              324                         ad_len += 3;
325                         ptr += 3;                 325                         ptr += 3;
326                 }                                 326                 }
327         }                                         327         }
328                                                   328 
329         return ad_len;                            329         return ad_len;
330 }                                                 330 }
331                                                   331 
332 static u8 create_default_scan_rsp(struct hci_d    332 static u8 create_default_scan_rsp(struct hci_dev *hdev, u8 *ptr)
333 {                                                 333 {
334         u8 scan_rsp_len = 0;                      334         u8 scan_rsp_len = 0;
335                                                   335 
336         if (hdev->appearance)                     336         if (hdev->appearance)
337                 scan_rsp_len = eir_append_appe    337                 scan_rsp_len = eir_append_appearance(hdev, ptr, scan_rsp_len);
338                                                   338 
339         return eir_append_local_name(hdev, ptr    339         return eir_append_local_name(hdev, ptr, scan_rsp_len);
340 }                                                 340 }
341                                                   341 
342 u8 eir_create_scan_rsp(struct hci_dev *hdev, u    342 u8 eir_create_scan_rsp(struct hci_dev *hdev, u8 instance, u8 *ptr)
343 {                                                 343 {
344         struct adv_info *adv;                     344         struct adv_info *adv;
345         u8 scan_rsp_len = 0;                      345         u8 scan_rsp_len = 0;
346                                                   346 
347         if (!instance)                            347         if (!instance)
348                 return create_default_scan_rsp    348                 return create_default_scan_rsp(hdev, ptr);
349                                                   349 
350         adv = hci_find_adv_instance(hdev, inst    350         adv = hci_find_adv_instance(hdev, instance);
351         if (!adv)                                 351         if (!adv)
352                 return 0;                         352                 return 0;
353                                                   353 
354         if ((adv->flags & MGMT_ADV_FLAG_APPEAR    354         if ((adv->flags & MGMT_ADV_FLAG_APPEARANCE) && hdev->appearance)
355                 scan_rsp_len = eir_append_appe    355                 scan_rsp_len = eir_append_appearance(hdev, ptr, scan_rsp_len);
356                                                   356 
357         memcpy(&ptr[scan_rsp_len], adv->scan_r    357         memcpy(&ptr[scan_rsp_len], adv->scan_rsp_data, adv->scan_rsp_len);
358                                                   358 
359         scan_rsp_len += adv->scan_rsp_len;        359         scan_rsp_len += adv->scan_rsp_len;
360                                                   360 
361         if (adv->flags & MGMT_ADV_FLAG_LOCAL_N    361         if (adv->flags & MGMT_ADV_FLAG_LOCAL_NAME)
362                 scan_rsp_len = eir_append_loca    362                 scan_rsp_len = eir_append_local_name(hdev, ptr, scan_rsp_len);
363                                                   363 
364         return scan_rsp_len;                      364         return scan_rsp_len;
365 }                                                 365 }
366                                                   366 
367 void *eir_get_service_data(u8 *eir, size_t eir    367 void *eir_get_service_data(u8 *eir, size_t eir_len, u16 uuid, size_t *len)
368 {                                                 368 {
369         while ((eir = eir_get_data(eir, eir_le    369         while ((eir = eir_get_data(eir, eir_len, EIR_SERVICE_DATA, len))) {
370                 u16 value = get_unaligned_le16    370                 u16 value = get_unaligned_le16(eir);
371                                                   371 
372                 if (uuid == value) {              372                 if (uuid == value) {
373                         if (len)                  373                         if (len)
374                                 *len -= 2;        374                                 *len -= 2;
375                         return &eir[2];           375                         return &eir[2];
376                 }                                 376                 }
377                                                   377 
378                 eir += *len;                      378                 eir += *len;
379                 eir_len -= *len;                  379                 eir_len -= *len;
380         }                                         380         }
381                                                   381 
382         return NULL;                              382         return NULL;
383 }                                                 383 }
384                                                   384 

~ [ 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