aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/hci_request.c
diff options
context:
space:
mode:
authorMichał Narajowski <michal.narajowski@codecoup.pl>2016-10-05 06:28:27 -0400
committerMarcel Holtmann <marcel@holtmann.org>2016-10-06 05:52:29 -0400
commit1b422066658b7cc985fa020066b72d28159d858f (patch)
tree3a09eedeb83122cfaefcaa5a17fc41d3f0205261 /net/bluetooth/hci_request.c
parent7ddb30c7471ed69b75ae4c2601d45cbda5d390ff (diff)
Bluetooth: Refactor append name and appearance
Use eir_append_data to remove code duplication. 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.c44
1 files changed, 15 insertions, 29 deletions
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index 3c44c54a056f..e2288421fe6b 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -21,8 +21,6 @@
21 SOFTWARE IS DISCLAIMED. 21 SOFTWARE IS DISCLAIMED.
22*/ 22*/
23 23
24#include <asm/unaligned.h>
25
26#include <net/bluetooth/bluetooth.h> 24#include <net/bluetooth/bluetooth.h>
27#include <net/bluetooth/hci_core.h> 25#include <net/bluetooth/hci_core.h>
28#include <net/bluetooth/mgmt.h> 26#include <net/bluetooth/mgmt.h>
@@ -992,46 +990,39 @@ static u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
992 /* complete name fits and is eq to max short name len or smaller */ 990 /* complete name fits and is eq to max short name len or smaller */
993 if (complete_len <= max_len && 991 if (complete_len <= max_len &&
994 complete_len <= HCI_MAX_SHORT_NAME_LENGTH) { 992 complete_len <= HCI_MAX_SHORT_NAME_LENGTH) {
995 ptr[0] = complete_len + 1; 993 return eir_append_data(ptr, ad_len, EIR_NAME_COMPLETE,
996 ptr[1] = EIR_NAME_COMPLETE; 994 hdev->dev_name, complete_len);
997 memcpy(ptr + 2, hdev->dev_name, complete_len);
998
999 return ad_len + complete_len + 2;
1000 } 995 }
1001 996
1002 /* short name set and fits */ 997 /* short name set and fits */
1003 if (short_len && short_len <= max_len) { 998 if (short_len && short_len <= max_len) {
1004 ptr[0] = short_len + 1; 999 return eir_append_data(ptr, ad_len, EIR_NAME_SHORT,
1005 ptr[1] = EIR_NAME_SHORT; 1000 hdev->short_name, short_len);
1006 memcpy(ptr + 2, hdev->short_name, short_len);
1007
1008 return ad_len + short_len + 2;
1009 } 1001 }
1010 1002
1011 /* no short name set so shorten complete name */ 1003 /* no short name set so shorten complete name */
1012 if (!short_len) { 1004 if (!short_len) {
1013 ptr[0] = max_len + 1; 1005 return eir_append_data(ptr, ad_len, EIR_NAME_SHORT,
1014 ptr[1] = EIR_NAME_SHORT; 1006 hdev->dev_name, max_len);
1015 memcpy(ptr + 2, hdev->dev_name, max_len);
1016
1017 return ad_len + max_len + 2;
1018 } 1007 }
1019 1008
1020 return ad_len; 1009 return ad_len;
1021} 1010}
1022 1011
1012static u8 append_appearance(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
1013{
1014 return eir_append_le16(ptr, ad_len, EIR_APPEARANCE, hdev->appearance);
1015}
1016
1023static u8 create_default_scan_rsp_data(struct hci_dev *hdev, u8 *ptr) 1017static u8 create_default_scan_rsp_data(struct hci_dev *hdev, u8 *ptr)
1024{ 1018{
1025 u8 scan_rsp_len = 0; 1019 u8 scan_rsp_len = 0;
1026 1020
1027 if (hdev->appearance) { 1021 if (hdev->appearance) {
1028 ptr[0] = 3; 1022 scan_rsp_len = append_appearance(hdev, ptr, scan_rsp_len);
1029 ptr[1] = EIR_APPEARANCE;
1030 put_unaligned_le16(hdev->appearance, ptr + 2);
1031 scan_rsp_len += 4;
1032 } 1023 }
1033 1024
1034 return append_local_name(hdev, ptr + scan_rsp_len, scan_rsp_len); 1025 return append_local_name(hdev, ptr, scan_rsp_len);
1035} 1026}
1036 1027
1037static u8 create_instance_scan_rsp_data(struct hci_dev *hdev, u8 instance, 1028static u8 create_instance_scan_rsp_data(struct hci_dev *hdev, u8 instance,
@@ -1048,18 +1039,13 @@ static u8 create_instance_scan_rsp_data(struct hci_dev *hdev, u8 instance,
1048 instance_flags = adv_instance->flags; 1039 instance_flags = adv_instance->flags;
1049 1040
1050 if ((instance_flags & MGMT_ADV_FLAG_APPEARANCE) && hdev->appearance) { 1041 if ((instance_flags & MGMT_ADV_FLAG_APPEARANCE) && hdev->appearance) {
1051 ptr[0] = 3; 1042 scan_rsp_len = append_appearance(hdev, ptr, scan_rsp_len);
1052 ptr[1] = EIR_APPEARANCE;
1053 put_unaligned_le16(hdev->appearance, ptr + 2);
1054 scan_rsp_len += 4;
1055 ptr += 4;
1056 } 1043 }
1057 1044
1058 memcpy(ptr, adv_instance->scan_rsp_data, 1045 memcpy(&ptr[scan_rsp_len], adv_instance->scan_rsp_data,
1059 adv_instance->scan_rsp_len); 1046 adv_instance->scan_rsp_len);
1060 1047
1061 scan_rsp_len += adv_instance->scan_rsp_len; 1048 scan_rsp_len += adv_instance->scan_rsp_len;
1062 ptr += adv_instance->scan_rsp_len;
1063 1049
1064 if (instance_flags & MGMT_ADV_FLAG_LOCAL_NAME) 1050 if (instance_flags & MGMT_ADV_FLAG_LOCAL_NAME)
1065 scan_rsp_len = append_local_name(hdev, ptr, scan_rsp_len); 1051 scan_rsp_len = append_local_name(hdev, ptr, scan_rsp_len);