aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/hci_request.c
diff options
context:
space:
mode:
authorMichał Narajowski <michal.narajowski@codecoup.pl>2016-10-05 06:28:25 -0400
committerMarcel Holtmann <marcel@holtmann.org>2016-10-06 05:52:29 -0400
commitcecbf3e932c1fa6df45fd6cc4fc8081a4cb45bcd (patch)
tree4df2361cce3e715ab0cfa7bf6e4bbf4a35ec7853 /net/bluetooth/hci_request.c
parent1165df0ee470930c2da73def005b1f842c2239cc (diff)
Bluetooth: Fix local name in scan rsp
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> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth/hci_request.c')
-rw-r--r--net/bluetooth/hci_request.c47
1 files changed, 35 insertions, 12 deletions
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index c8135680c43e..fd6406df8a07 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)
973 973
974static u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len) 974static u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
975{ 975{
976 size_t name_len; 976 size_t complete_len;
977 size_t short_len;
977 int max_len; 978 int max_len;
978 979
979 max_len = HCI_MAX_AD_LENGTH - ad_len - 2; 980 max_len = HCI_MAX_AD_LENGTH - ad_len - 2;
980 name_len = strlen(hdev->dev_name); 981 complete_len = strlen(hdev->dev_name);
981 if (name_len > 0 && max_len > 0) { 982 short_len = strlen(hdev->short_name);
982 983
983 if (name_len > max_len) { 984 /* no space left for name */
984 name_len = max_len; 985 if (max_len < 1)
985 ptr[1] = EIR_NAME_SHORT; 986 return ad_len;
986 } else
987 ptr[1] = EIR_NAME_COMPLETE;
988 987
989 ptr[0] = name_len + 1; 988 /* no name set */
989 if (!complete_len)
990 return ad_len;
990 991
991 memcpy(ptr + 2, hdev->dev_name, name_len); 992 /* complete name fits and is eq to max short name len or smaller */
993 if (complete_len <= max_len &&
994 complete_len <= HCI_MAX_SHORT_NAME_LENGTH) {
995 ptr[0] = complete_len + 1;
996 ptr[1] = EIR_NAME_COMPLETE;
997 memcpy(ptr + 2, hdev->dev_name, complete_len);
992 998
993 ad_len += (name_len + 2); 999 return ad_len + complete_len + 2;
994 ptr += (name_len + 2); 1000 }
1001
1002 /* short name set and fits */
1003 if (short_len && short_len <= max_len) {
1004 ptr[0] = short_len + 1;
1005 ptr[1] = EIR_NAME_SHORT;
1006 memcpy(ptr + 2, hdev->short_name, short_len);
1007
1008 return ad_len + short_len + 2;
1009 }
1010
1011 /* no short name set so shorten complete name */
1012 if (!short_len) {
1013 ptr[0] = max_len + 1;
1014 ptr[1] = EIR_NAME_SHORT;
1015 memcpy(ptr + 2, hdev->dev_name, max_len);
1016
1017 return ad_len + max_len + 2;
995 } 1018 }
996 1019
997 return ad_len; 1020 return ad_len;