Skip to content

Commit e5590f8

Browse files
Alain MichaudTzung-Bi Shih
authored andcommitted
BACKPORT: FROMLIST: Bluetooth: adding configurable eir_max_name_len
This change adds support for a configurable eir_max_name_len for platforms which requires a larger than 48 bytes complete name in EIR. From bluetoothctl: [bluetooth]# system-alias 012345678901234567890123456789012345678901234567890123456789 Changing 012345678901234567890123456789012345678901234567890123456789 succeeded [CHG] Controller DC:71:96:69:02:89 Alias: 012345678901234567890123456789012345678901234567890123456789 From btmon: < HCI Command: Write Local Name (0x03|0x0013) plen 248     torvalds#109 [hci0] 88.567990         Name: 012345678901234567890123456789012345678901234567890123456789 > HCI Event: Command Complete (0x0e) plen 4  torvalds#110 [hci0] 88.663854       Write Local Name (0x03|0x0013) ncmd 1         Status: Success (0x00) @ MGMT Event: Local Name Changed (0x0008) plen 260                {0x0004} [hci0] 88.663948         Name: 012345678901234567890123456789012345678901234567890123456789         Short name: < HCI Command: Write Extended Inquiry Response (0x03|0x0052) plen 241 torvalds#111 [hci0] 88.663977         FEC: Not required (0x00)         Name (complete): 012345678901234567890123456789012345678901234567890123456789         TX power: 12 dBm         Device ID: Bluetooth SIG assigned (0x0001)           Vendor: Google (224)           Product: 0xc405           Version: 0.5.6 (0x0056)         16-bit Service UUIDs (complete): 7 entries           Generic Access Profile (0x1800)           Generic Attribute Profile (0x1801)           Device Information (0x180a)           A/V Remote Control (0x110e)           A/V Remote Control Target (0x110c)           Handsfree Audio Gateway (0x111f)           Audio Source (0x110a) > HCI Event: Command Complete (0x0e) plen 4 torvalds#112 [hci0] 88.664874       Write Extended Inquiry Response (0x03|0x0052) ncmd 1         Status: Success (0x00) (am from https://patchwork.kernel.org/patch/11687367/) Reviewed-by: Sonny Sasaka <[email protected]> Reviewed-by: Abhishek Pandit-Subedi <[email protected]> Signed-off-by: Alain Michaud <[email protected]> Backport notes: HDEV_PARAM_U16 is changed from two parameters to one parameter. BUG=none TEST=build Signed-off-by: Zhengping Jiang <[email protected]>
1 parent fe613a2 commit e5590f8

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ struct hci_dev {
363363
__u8 dev_name[HCI_MAX_NAME_LENGTH];
364364
__u8 short_name[HCI_MAX_SHORT_NAME_LENGTH];
365365
__u8 eir[HCI_MAX_EIR_LENGTH];
366+
__u16 eir_max_name_len;
366367
__u16 appearance;
367368
__u8 dev_class[3];
368369
__u8 major_class;

net/bluetooth/eir.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,36 +190,42 @@ static u8 *create_uuid128_list(struct hci_dev *hdev, u8 *data, ptrdiff_t len)
190190
void eir_create(struct hci_dev *hdev, u8 *data)
191191
{
192192
u8 *ptr = data;
193+
u8 size_remaining = HCI_MAX_EIR_LENGTH;
193194
size_t name_len;
194195

195196
name_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name));
196197

197198
if (name_len > 0) {
198199
/* EIR Data type */
199-
if (name_len > 48) {
200-
name_len = 48;
200+
if (name_len > min_t(u16, (HCI_MAX_EIR_LENGTH - 2),
201+
hdev->eir_max_name_len)) {
202+
name_len = min_t(u16, (HCI_MAX_EIR_LENGTH - 2),
203+
hdev->eir_max_name_len);
201204
ptr[1] = EIR_NAME_SHORT;
202-
} else {
205+
} else
203206
ptr[1] = EIR_NAME_COMPLETE;
204-
}
205207

206208
/* EIR Data length */
207209
ptr[0] = name_len + 1;
208210

209211
memcpy(ptr + 2, hdev->dev_name, name_len);
210212

211213
ptr += (name_len + 2);
214+
size_remaining -= (name_len + 2);
212215
}
213216

214-
if (hdev->inq_tx_power != HCI_TX_POWER_INVALID) {
217+
if (hdev->inq_tx_power != HCI_TX_POWER_INVALID &&
218+
size_remaining >= 3) {
215219
ptr[0] = 2;
216220
ptr[1] = EIR_TX_POWER;
217221
ptr[2] = (u8)hdev->inq_tx_power;
218222

219223
ptr += 3;
224+
size_remaining -= 3;
220225
}
221226

222-
if (hdev->devid_source > 0) {
227+
if (hdev->devid_source > 0 &&
228+
size_remaining >= 10) {
223229
ptr[0] = 9;
224230
ptr[1] = EIR_DEVICE_ID;
225231

@@ -229,11 +235,16 @@ void eir_create(struct hci_dev *hdev, u8 *data)
229235
put_unaligned_le16(hdev->devid_version, ptr + 8);
230236

231237
ptr += 10;
238+
size_remaining -= 10;
232239
}
233240

234-
ptr = create_uuid16_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data));
235-
ptr = create_uuid32_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data));
236-
ptr = create_uuid128_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data));
241+
ptr = create_uuid16_list(hdev, ptr, size_remaining);
242+
size_remaining = HCI_MAX_EIR_LENGTH - (ptr - data);
243+
244+
ptr = create_uuid32_list(hdev, ptr, size_remaining);
245+
size_remaining = HCI_MAX_EIR_LENGTH - (ptr - data);
246+
247+
ptr = create_uuid128_list(hdev, ptr, size_remaining);
237248
}
238249

239250
u8 eir_create_per_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr)

net/bluetooth/hci_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,6 +2451,7 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv)
24512451
hdev->adv_instance_cnt = 0;
24522452
hdev->cur_adv_instance = 0x00;
24532453
hdev->adv_instance_timeout = 0;
2454+
hdev->eir_max_name_len = 48;
24542455

24552456
hdev->advmon_allowlist_duration = 300;
24562457
hdev->advmon_no_filter_duration = 500;

net/bluetooth/mgmt_config.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
7575
HDEV_PARAM_U16(le_conn_latency);
7676
HDEV_PARAM_U16(le_supv_timeout);
7777
HDEV_PARAM_U16(def_le_autoconnect_timeout);
78+
HDEV_PARAM_U16(eir_max_name_len);
7879
HDEV_PARAM_U16(advmon_allowlist_duration);
7980
HDEV_PARAM_U16(advmon_no_filter_duration);
8081
HDEV_PARAM_U8(enable_advmon_interleave_scan);
@@ -108,6 +109,7 @@ int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
108109
TLV_SET_U16(0x001a, le_supv_timeout),
109110
TLV_SET_U16_JIFFIES_TO_MSECS(0x001b,
110111
def_le_autoconnect_timeout),
112+
TLV_SET_U16(0x001c, eir_max_name_len),
111113
TLV_SET_U16(0x001d, advmon_allowlist_duration),
112114
TLV_SET_U16(0x001e, advmon_no_filter_duration),
113115
TLV_SET_U8(0x001f, enable_advmon_interleave_scan),
@@ -184,6 +186,7 @@ int set_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
184186
case 0x0019:
185187
case 0x001a:
186188
case 0x001b:
189+
case 0x001c:
187190
case 0x001d:
188191
case 0x001e:
189192
exp_type_len = sizeof(u16);
@@ -305,6 +308,9 @@ int set_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
305308
hdev->def_le_autoconnect_timeout =
306309
msecs_to_jiffies(TLV_GET_LE16(buffer));
307310
break;
311+
case 0x0001c:
312+
hdev->eir_max_name_len = TLV_GET_LE16(buffer);
313+
break;
308314
case 0x0001d:
309315
hdev->advmon_allowlist_duration = TLV_GET_LE16(buffer);
310316
break;

0 commit comments

Comments
 (0)