All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] Bluetooth: Fix local name in scan rsp
@ 2016-09-22 14:01 Michał Narajowski
  2016-09-22 14:01 ` [PATCH 2/3] Bluetooth: Fix local name validation Michał Narajowski
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Michał Narajowski @ 2016-09-22 14:01 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Michał Narajowski

Use complete name if it fits. If not and there is short name
check if it fits. If not then use shortened name as prefix
of complete name.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
---
 net/bluetooth/hci_request.c | 46 +++++++++++++++++++++++++++++++++------------
 1 file changed, 34 insertions(+), 12 deletions(-)

diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index c813568..880758c 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -973,25 +973,47 @@ 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 name_len;
+	size_t complete_len;
+	size_t short_len;
 	int max_len;
 
 	max_len = HCI_MAX_AD_LENGTH - ad_len - 2;
-	name_len = strlen(hdev->dev_name);
-	if (name_len > 0 && max_len > 0) {
+	complete_len = strlen(hdev->dev_name);
+	short_len = strlen(hdev->short_name);
 
-		if (name_len > max_len) {
-			name_len = max_len;
-			ptr[1] = EIR_NAME_SHORT;
-		} else
-			ptr[1] = EIR_NAME_COMPLETE;
+	/* no space left for name */
+	if (max_len < 1)
+		return ad_len;
 
-		ptr[0] = name_len + 1;
+	/* no name set */
+	if (!complete_len)
+		return ad_len;
 
-		memcpy(ptr + 2, hdev->dev_name, name_len);
+	/* complete name fits */
+	if (complete_len <= max_len) {
+		ptr[0] = complete_len + 1;
+		ptr[1] = EIR_NAME_COMPLETE;
+		memcpy(ptr + 2, hdev->dev_name, complete_len);
 
-		ad_len += (name_len + 2);
-		ptr += (name_len + 2);
+		return ad_len + complete_len + 2;
+	}
+
+	/* shortened name set and fits */
+	if (short_len && short_len <= max_len) {
+		ptr[0] = short_len + 1;
+		ptr[1] = EIR_NAME_SHORT;
+		memcpy(ptr + 2, hdev->short_name, short_len);
+
+		return ad_len + short_len + 2;
+	}
+
+	/* no shortened name set so shorten complete name */
+	if (!short_len) {
+		ptr[0] = max_len + 1;
+		ptr[1] = EIR_NAME_SHORT;
+		memcpy(ptr + 2, hdev->dev_name, max_len);
+
+		return ad_len + max_len + 2;
 	}
 
 	return ad_len;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread
* [PATCH 1/3] Bluetooth: Fix local name in scan rsp
@ 2016-10-05 10:28 Michał Narajowski
  2016-10-05 11:19 ` Marcel Holtmann
  0 siblings, 1 reply; 10+ messages in thread
From: Michał Narajowski @ 2016-10-05 10:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Michał Narajowski

Use complete name if it fits. If not and there is short name
check if it fits. If not then use shortened name as prefix
of complete name.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
---
 net/bluetooth/hci_request.c | 47 +++++++++++++++++++++++++++++++++------------
 1 file changed, 35 insertions(+), 12 deletions(-)

diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index c813568..fd6406d 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -973,25 +973,48 @@ 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 name_len;
+	size_t complete_len;
+	size_t short_len;
 	int max_len;
 
 	max_len = HCI_MAX_AD_LENGTH - ad_len - 2;
-	name_len = strlen(hdev->dev_name);
-	if (name_len > 0 && max_len > 0) {
+	complete_len = strlen(hdev->dev_name);
+	short_len = strlen(hdev->short_name);
 
-		if (name_len > max_len) {
-			name_len = max_len;
-			ptr[1] = EIR_NAME_SHORT;
-		} else
-			ptr[1] = EIR_NAME_COMPLETE;
+	/* no space left for name */
+	if (max_len < 1)
+		return ad_len;
 
-		ptr[0] = name_len + 1;
+	/* no name set */
+	if (!complete_len)
+		return ad_len;
 
-		memcpy(ptr + 2, hdev->dev_name, name_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) {
+		ptr[0] = complete_len + 1;
+		ptr[1] = EIR_NAME_COMPLETE;
+		memcpy(ptr + 2, hdev->dev_name, complete_len);
 
-		ad_len += (name_len + 2);
-		ptr += (name_len + 2);
+		return ad_len + complete_len + 2;
+	}
+
+	/* short name set and fits */
+	if (short_len && short_len <= max_len) {
+		ptr[0] = short_len + 1;
+		ptr[1] = EIR_NAME_SHORT;
+		memcpy(ptr + 2, hdev->short_name, short_len);
+
+		return ad_len + short_len + 2;
+	}
+
+	/* no short name set so shorten complete name */
+	if (!short_len) {
+		ptr[0] = max_len + 1;
+		ptr[1] = EIR_NAME_SHORT;
+		memcpy(ptr + 2, hdev->dev_name, max_len);
+
+		return ad_len + max_len + 2;
 	}
 
 	return ad_len;
-- 
2.7.4


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

end of thread, other threads:[~2016-10-05 11:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-22 14:01 [PATCH 1/3] Bluetooth: Fix local name in scan rsp Michał Narajowski
2016-09-22 14:01 ` [PATCH 2/3] Bluetooth: Fix local name validation Michał Narajowski
2016-09-22 15:50   ` Marcel Holtmann
2016-09-22 14:01 ` [PATCH 3/3] Bluetooth: Fix not updating scan rsp when adv off Michał Narajowski
2016-09-22 15:48   ` Marcel Holtmann
2016-09-22 15:47 ` [PATCH 1/3] Bluetooth: Fix local name in scan rsp Marcel Holtmann
2016-09-22 19:07   ` Szymon Janc
2016-09-22 19:56     ` Marcel Holtmann
2016-10-05 10:28 Michał Narajowski
2016-10-05 11:19 ` Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.