linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Bluetooth: Shorten complete name if no short name in set local name
@ 2016-10-18 13:10 Michał Narajowski
  2016-10-18 13:10 ` [PATCH 2/2] Bluetooth: Fix append max 11 bytes of name to scan rsp data Michał Narajowski
  2016-10-18 13:47 ` [PATCH 1/2] Bluetooth: Shorten complete name if no short name in set local name Marcel Holtmann
  0 siblings, 2 replies; 3+ messages in thread
From: Michał Narajowski @ 2016-10-18 13:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Michał Narajowski

Generate shortened local name if no short name specified
to simplify appending local name to scan rsp data.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
---
 net/bluetooth/mgmt.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 7360380..cc6e571 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3103,7 +3103,16 @@ static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data,
 		goto failed;
 	}
 
-	memcpy(hdev->short_name, cp->short_name, sizeof(hdev->short_name));
+	/* if no short name set and complete name is longer than max
+	 * short name length then shorten complete name
+	 */
+	if (!strlen(cp->short_name) &&
+	    (strlen(cp->name) > HCI_MAX_SHORT_NAME_LENGTH)) {
+		memcpy(hdev->short_name, cp->name, sizeof(hdev->short_name));
+	} else {
+		memcpy(hdev->short_name, cp->short_name,
+		       sizeof(hdev->short_name));
+	}
 
 	if (!hdev_is_powered(hdev)) {
 		memcpy(hdev->dev_name, cp->name, sizeof(hdev->dev_name));
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] Bluetooth: Fix append max 11 bytes of name to scan rsp data
  2016-10-18 13:10 [PATCH 1/2] Bluetooth: Shorten complete name if no short name in set local name Michał Narajowski
@ 2016-10-18 13:10 ` Michał Narajowski
  2016-10-18 13:47 ` [PATCH 1/2] Bluetooth: Shorten complete name if no short name in set local name Marcel Holtmann
  1 sibling, 0 replies; 3+ messages in thread
From: Michał Narajowski @ 2016-10-18 13:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Michał Narajowski

Append maximum of 10 + 1 bytes of name to scan response data.
Complete name is appended only if exists and is <= 10 characters.
Else append short name if exists. This makes sure name
is consistent across multiple advertising instances.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
---
 net/bluetooth/hci_request.c | 40 +++++++++++-----------------------------
 net/bluetooth/mgmt.c        |  4 ++--
 2 files changed, 13 insertions(+), 31 deletions(-)

diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index e228842..fc3d2a4 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -971,41 +971,23 @@ void __hci_req_enable_advertising(struct hci_request *req)
 
 static u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
 {
-	size_t complete_len;
-	size_t short_len;
-	int max_len;
+	size_t len;
 
-	max_len = HCI_MAX_AD_LENGTH - ad_len - 2;
-	complete_len = strlen(hdev->dev_name);
-	short_len = strlen(hdev->short_name);
-
-	/* no space left for name */
-	if (max_len < 1)
-		return ad_len;
-
-	/* no name set */
-	if (!complete_len)
+	/* no space left for name (+ NULL + type + len) */
+	if ((HCI_MAX_AD_LENGTH - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 3)
 		return ad_len;
 
-	/* complete name fits and is eq to max short name len or smaller */
-	if (complete_len <= max_len &&
-	    complete_len <= HCI_MAX_SHORT_NAME_LENGTH) {
+	/* use complete name if present and fits */
+	len = strlen(hdev->dev_name);
+	if (len && len <= HCI_MAX_SHORT_NAME_LENGTH)
 		return eir_append_data(ptr, ad_len, EIR_NAME_COMPLETE,
-				       hdev->dev_name, complete_len);
-	}
+				       hdev->dev_name, len + 1);
 
-	/* short name set and fits */
-	if (short_len && short_len <= max_len) {
+	/* use short name if present */
+	len = strlen(hdev->short_name);
+	if (len)
 		return eir_append_data(ptr, ad_len, EIR_NAME_SHORT,
-				       hdev->short_name, short_len);
-	}
-
-	/* no short name set so shorten complete name */
-	if (!short_len) {
-		return eir_append_data(ptr, ad_len, EIR_NAME_SHORT,
-				       hdev->dev_name, max_len);
-	}
-
+				       hdev->short_name, len + 1);
 	return ad_len;
 }
 
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index cc6e571..53be90e 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -6039,9 +6039,9 @@ static u8 tlv_data_max_len(u32 adv_flags, bool is_adv_data)
 		if (adv_flags & MGMT_ADV_FLAG_TX_POWER)
 			max_len -= 3;
 	} else {
-		/* at least 1 byte of name should fit in */
+		/* max 11 bytes of name should fit in */
 		if (adv_flags & MGMT_ADV_FLAG_LOCAL_NAME)
-			max_len -= 3;
+			max_len -= (1 + 1 + 11);
 
 		if (adv_flags & (MGMT_ADV_FLAG_APPEARANCE))
 			max_len -= 4;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] Bluetooth: Shorten complete name if no short name in set local name
  2016-10-18 13:10 [PATCH 1/2] Bluetooth: Shorten complete name if no short name in set local name Michał Narajowski
  2016-10-18 13:10 ` [PATCH 2/2] Bluetooth: Fix append max 11 bytes of name to scan rsp data Michał Narajowski
@ 2016-10-18 13:47 ` Marcel Holtmann
  1 sibling, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2016-10-18 13:47 UTC (permalink / raw)
  To: Michał Narajowski; +Cc: linux-bluetooth

Hi Michal,

> Generate shortened local name if no short name specified
> to simplify appending local name to scan rsp data.
> 
> Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
> ---
> net/bluetooth/mgmt.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
> index 7360380..cc6e571 100644
> --- a/net/bluetooth/mgmt.c
> +++ b/net/bluetooth/mgmt.c
> @@ -3103,7 +3103,16 @@ static int set_local_name(struct sock *sk, struct hci_dev *hdev, void *data,
> 		goto failed;
> 	}
> 
> -	memcpy(hdev->short_name, cp->short_name, sizeof(hdev->short_name));
> +	/* if no short name set and complete name is longer than max
> +	 * short name length then shorten complete name
> +	 */
> +	if (!strlen(cp->short_name) &&
> +	    (strlen(cp->name) > HCI_MAX_SHORT_NAME_LENGTH)) {
> +		memcpy(hdev->short_name, cp->name, sizeof(hdev->short_name));
> +	} else {
> +		memcpy(hdev->short_name, cp->short_name,
> +		       sizeof(hdev->short_name));
> +	}

I would prefer if we do not store this value. Remember that Read Extended Controller Info returns hdev->short_name and that that is suppose to be the short name from Set Local Name. These two need to be consistent. We can not just return a generated value in Read Extended Controller Info.

Regards

Marcel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-10-18 13:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-18 13:10 [PATCH 1/2] Bluetooth: Shorten complete name if no short name in set local name Michał Narajowski
2016-10-18 13:10 ` [PATCH 2/2] Bluetooth: Fix append max 11 bytes of name to scan rsp data Michał Narajowski
2016-10-18 13:47 ` [PATCH 1/2] Bluetooth: Shorten complete name if no short name in set local name Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).