aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2011-03-16 08:29:35 -0400
committerGustavo F. Padovan <padovan@profusion.mobi>2011-03-31 13:22:54 -0400
commit1f6c6378c59f3ddac9ed89a68ccefe2611300c09 (patch)
tree14dd2ecd69225f3535f72c461575d289c879dd2f
parentf0681a68dd3a32699891cd1de93459aee5af7728 (diff)
Bluetooth: Add define for the maximum name length on HCI level
This patch adds a clear define for the maximum device name length in HCI messages and thereby avoids magic numbers in the code. Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
-rw-r--r--include/net/bluetooth/hci.h8
-rw-r--r--include/net/bluetooth/hci_core.h2
-rw-r--r--net/bluetooth/hci_event.c4
-rw-r--r--net/bluetooth/hci_sysfs.c6
4 files changed, 11 insertions, 9 deletions
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index ec6acf2f1c0b..1cd031cd1c4d 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -535,15 +535,17 @@ struct hci_cp_delete_stored_link_key {
535 __u8 delete_all; 535 __u8 delete_all;
536} __packed; 536} __packed;
537 537
538#define HCI_MAX_NAME_LENGTH 248
539
538#define HCI_OP_WRITE_LOCAL_NAME 0x0c13 540#define HCI_OP_WRITE_LOCAL_NAME 0x0c13
539struct hci_cp_write_local_name { 541struct hci_cp_write_local_name {
540 __u8 name[248]; 542 __u8 name[HCI_MAX_NAME_LENGTH];
541} __packed; 543} __packed;
542 544
543#define HCI_OP_READ_LOCAL_NAME 0x0c14 545#define HCI_OP_READ_LOCAL_NAME 0x0c14
544struct hci_rp_read_local_name { 546struct hci_rp_read_local_name {
545 __u8 status; 547 __u8 status;
546 __u8 name[248]; 548 __u8 name[HCI_MAX_NAME_LENGTH];
547} __packed; 549} __packed;
548 550
549#define HCI_OP_WRITE_CA_TIMEOUT 0x0c16 551#define HCI_OP_WRITE_CA_TIMEOUT 0x0c16
@@ -745,7 +747,7 @@ struct hci_ev_auth_complete {
745struct hci_ev_remote_name { 747struct hci_ev_remote_name {
746 __u8 status; 748 __u8 status;
747 bdaddr_t bdaddr; 749 bdaddr_t bdaddr;
748 __u8 name[248]; 750 __u8 name[HCI_MAX_NAME_LENGTH];
749} __packed; 751} __packed;
750 752
751#define HCI_EV_ENCRYPT_CHANGE 0x08 753#define HCI_EV_ENCRYPT_CHANGE 0x08
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 441dadbf6a89..9aabb14982dd 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -94,7 +94,7 @@ struct hci_dev {
94 __u8 bus; 94 __u8 bus;
95 __u8 dev_type; 95 __u8 dev_type;
96 bdaddr_t bdaddr; 96 bdaddr_t bdaddr;
97 __u8 dev_name[248]; 97 __u8 dev_name[HCI_MAX_NAME_LENGTH];
98 __u8 dev_class[3]; 98 __u8 dev_class[3];
99 __u8 major_class; 99 __u8 major_class;
100 __u8 minor_class; 100 __u8 minor_class;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 3fbfa50c2bff..91ef52673ed3 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -200,7 +200,7 @@ static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
200 if (!sent) 200 if (!sent)
201 return; 201 return;
202 202
203 memcpy(hdev->dev_name, sent, 248); 203 memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
204} 204}
205 205
206static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb) 206static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)
@@ -212,7 +212,7 @@ static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)
212 if (rp->status) 212 if (rp->status)
213 return; 213 return;
214 214
215 memcpy(hdev->dev_name, rp->name, 248); 215 memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH);
216} 216}
217 217
218static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb) 218static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb)
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 3c838a65a75a..e54421693eb8 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -216,13 +216,13 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr, char
216static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) 216static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
217{ 217{
218 struct hci_dev *hdev = dev_get_drvdata(dev); 218 struct hci_dev *hdev = dev_get_drvdata(dev);
219 char name[249]; 219 char name[HCI_MAX_NAME_LENGTH + 1];
220 int i; 220 int i;
221 221
222 for (i = 0; i < 248; i++) 222 for (i = 0; i < HCI_MAX_NAME_LENGTH; i++)
223 name[i] = hdev->dev_name[i]; 223 name[i] = hdev->dev_name[i];
224 224
225 name[248] = '\0'; 225 name[HCI_MAX_NAME_LENGTH] = '\0';
226 return sprintf(buf, "%s\n", name); 226 return sprintf(buf, "%s\n", name);
227} 227}
228 228