Bluetooth: Add define for the maximum name length on HCI level
authorJohan Hedberg <johan.hedberg@nokia.com>
Wed, 16 Mar 2011 12:29:35 +0000 (14:29 +0200)
committerGustavo F. Padovan <padovan@profusion.mobi>
Thu, 31 Mar 2011 17:22:54 +0000 (14:22 -0300)
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>
include/net/bluetooth/hci.h
include/net/bluetooth/hci_core.h
net/bluetooth/hci_event.c
net/bluetooth/hci_sysfs.c

index ec6acf2f1c0bba3dfa9b6ae7f325d1b22330b824..1cd031cd1c4d1a394e8ae5b3046fe34fc8204375 100644 (file)
@@ -535,15 +535,17 @@ struct hci_cp_delete_stored_link_key {
        __u8     delete_all;
 } __packed;
 
+#define HCI_MAX_NAME_LENGTH            248
+
 #define HCI_OP_WRITE_LOCAL_NAME                0x0c13
 struct hci_cp_write_local_name {
-       __u8     name[248];
+       __u8     name[HCI_MAX_NAME_LENGTH];
 } __packed;
 
 #define HCI_OP_READ_LOCAL_NAME         0x0c14
 struct hci_rp_read_local_name {
        __u8     status;
-       __u8     name[248];
+       __u8     name[HCI_MAX_NAME_LENGTH];
 } __packed;
 
 #define HCI_OP_WRITE_CA_TIMEOUT                0x0c16
@@ -745,7 +747,7 @@ struct hci_ev_auth_complete {
 struct hci_ev_remote_name {
        __u8     status;
        bdaddr_t bdaddr;
-       __u8     name[248];
+       __u8     name[HCI_MAX_NAME_LENGTH];
 } __packed;
 
 #define HCI_EV_ENCRYPT_CHANGE          0x08
index 441dadbf6a89f3a47444b463d5f6b2c5bf35017a..9aabb14982ddad66ae71c179a0d851bdaabe6e12 100644 (file)
@@ -94,7 +94,7 @@ struct hci_dev {
        __u8            bus;
        __u8            dev_type;
        bdaddr_t        bdaddr;
-       __u8            dev_name[248];
+       __u8            dev_name[HCI_MAX_NAME_LENGTH];
        __u8            dev_class[3];
        __u8            major_class;
        __u8            minor_class;
index 3fbfa50c2bff8a1fc9412319d5887aefa4938de0..91ef52673ed38d3f151317d7aca91bd228740db9 100644 (file)
@@ -200,7 +200,7 @@ static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
        if (!sent)
                return;
 
-       memcpy(hdev->dev_name, sent, 248);
+       memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
 }
 
 static 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)
        if (rp->status)
                return;
 
-       memcpy(hdev->dev_name, rp->name, 248);
+       memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH);
 }
 
 static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb)
index 3c838a65a75a279eb1c776a650ef74b5d6ef0671..e54421693eb86b42453374a0e828b0e5fe7c34b0 100644 (file)
@@ -216,13 +216,13 @@ static ssize_t show_type(struct device *dev, struct device_attribute *attr, char
 static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct hci_dev *hdev = dev_get_drvdata(dev);
-       char name[249];
+       char name[HCI_MAX_NAME_LENGTH + 1];
        int i;
 
-       for (i = 0; i < 248; i++)
+       for (i = 0; i < HCI_MAX_NAME_LENGTH; i++)
                name[i] = hdev->dev_name[i];
 
-       name[248] = '\0';
+       name[HCI_MAX_NAME_LENGTH] = '\0';
        return sprintf(buf, "%s\n", name);
 }