Commit 2ab3e8d6 authored by Frédéric Danis's avatar Frédéric Danis Committed by Luiz Augusto von Dentz

Bluetooth: Fix eir name length

According to Section 1.2 of Core Specification Supplement Part A the
complete or short name strings are defined as utf8s, which should not
include the trailing NULL for variable length array as defined in Core
Specification Vol1 Part E Section 2.9.3.

Removing the trailing NULL allows PTS to retrieve the random address based
on device name, e.g. for SM/PER/KDU/BV-02-C, SM/PER/KDU/BV-08-C or
GAP/BROB/BCST/BV-03-C.

Fixes: f61851f6 ("Bluetooth: Fix append max 11 bytes of name to scan rsp data")
Signed-off-by: default avatarFrédéric Danis <frederic.danis@collabora.com>
Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
parent 42ed95de
...@@ -13,48 +13,33 @@ ...@@ -13,48 +13,33 @@
#define PNP_INFO_SVCLASS_ID 0x1200 #define PNP_INFO_SVCLASS_ID 0x1200
static u8 eir_append_name(u8 *eir, u16 eir_len, u8 type, u8 *data, u8 data_len)
{
u8 name[HCI_MAX_SHORT_NAME_LENGTH + 1];
/* If data is already NULL terminated just pass it directly */
if (data[data_len - 1] == '\0')
return eir_append_data(eir, eir_len, type, data, data_len);
memcpy(name, data, HCI_MAX_SHORT_NAME_LENGTH);
name[HCI_MAX_SHORT_NAME_LENGTH] = '\0';
return eir_append_data(eir, eir_len, type, name, sizeof(name));
}
u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len) u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
{ {
size_t short_len; size_t short_len;
size_t complete_len; size_t complete_len;
/* no space left for name (+ NULL + type + len) */ /* no space left for name (+ type + len) */
if ((max_adv_len(hdev) - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 3) if ((max_adv_len(hdev) - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 2)
return ad_len; return ad_len;
/* use complete name if present and fits */ /* use complete name if present and fits */
complete_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name)); complete_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name));
if (complete_len && complete_len <= HCI_MAX_SHORT_NAME_LENGTH) if (complete_len && complete_len <= HCI_MAX_SHORT_NAME_LENGTH)
return eir_append_name(ptr, ad_len, EIR_NAME_COMPLETE, return eir_append_data(ptr, ad_len, EIR_NAME_COMPLETE,
hdev->dev_name, complete_len + 1); hdev->dev_name, complete_len);
/* use short name if present */ /* use short name if present */
short_len = strnlen(hdev->short_name, sizeof(hdev->short_name)); short_len = strnlen(hdev->short_name, sizeof(hdev->short_name));
if (short_len) if (short_len)
return eir_append_name(ptr, ad_len, EIR_NAME_SHORT, return eir_append_data(ptr, ad_len, EIR_NAME_SHORT,
hdev->short_name, hdev->short_name,
short_len == HCI_MAX_SHORT_NAME_LENGTH ? short_len);
short_len : short_len + 1);
/* use shortened full name if present, we already know that name /* use shortened full name if present, we already know that name
* is longer then HCI_MAX_SHORT_NAME_LENGTH * is longer then HCI_MAX_SHORT_NAME_LENGTH
*/ */
if (complete_len) if (complete_len)
return eir_append_name(ptr, ad_len, EIR_NAME_SHORT, return eir_append_data(ptr, ad_len, EIR_NAME_SHORT,
hdev->dev_name, hdev->dev_name,
HCI_MAX_SHORT_NAME_LENGTH); HCI_MAX_SHORT_NAME_LENGTH);
......
...@@ -8408,7 +8408,7 @@ static int read_adv_features(struct sock *sk, struct hci_dev *hdev, ...@@ -8408,7 +8408,7 @@ static int read_adv_features(struct sock *sk, struct hci_dev *hdev,
static u8 calculate_name_len(struct hci_dev *hdev) static u8 calculate_name_len(struct hci_dev *hdev)
{ {
u8 buf[HCI_MAX_SHORT_NAME_LENGTH + 3]; u8 buf[HCI_MAX_SHORT_NAME_LENGTH + 2]; /* len + type + name */
return eir_append_local_name(hdev, buf, 0); return eir_append_local_name(hdev, buf, 0);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment