* [PATCH 1/3] Bluetooth: Add hdev->short_name for EIR generation
@ 2012-02-22 19:06 johan.hedberg
2012-02-22 19:06 ` [PATCH 2/3] Bluetooth: Fix read_name updating when HCI_SETUP is not set johan.hedberg
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: johan.hedberg @ 2012-02-22 19:06 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
It's possible to provide a short name through the mgmt interface and
this name can be used for EIR generation when the full name doesn't fit
there. This patch adds the preliminary tracking of the provided short
name.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/hci_core.h | 3 +++
include/net/bluetooth/mgmt.h | 2 +-
net/bluetooth/mgmt.c | 3 +++
3 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 24dd770..3fcc7f0 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -129,6 +129,8 @@ struct le_scan_params {
int timeout;
};
+#define HCI_MAX_SHORT_NAME_LENGTH 10
+
#define NUM_REASSEMBLY 4
struct hci_dev {
struct list_head list;
@@ -141,6 +143,7 @@ struct hci_dev {
__u8 dev_type;
bdaddr_t bdaddr;
__u8 dev_name[HCI_MAX_NAME_LENGTH];
+ __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH];
__u8 eir[HCI_MAX_EIR_LENGTH];
__u8 dev_class[3];
__u8 major_class;
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index ac59cdd..495668c 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -75,7 +75,7 @@ struct mgmt_rp_read_index_list {
/* Reserve one extra byte for names in management messages so that they
* are always guaranteed to be nul-terminated */
#define MGMT_MAX_NAME_LENGTH (HCI_MAX_NAME_LENGTH + 1)
-#define MGMT_MAX_SHORT_NAME_LENGTH (10 + 1)
+#define MGMT_MAX_SHORT_NAME_LENGTH (HCI_MAX_SHORT_NAME_LENGTH + 1)
#define MGMT_SETTING_POWERED 0x00000001
#define MGMT_SETTING_CONNECTABLE 0x00000002
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 16bddd2..3f6a2df 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2273,6 +2273,9 @@ static int set_local_name(struct sock *sk, u16 index, void *data,
goto failed;
}
+ memcpy(hdev->short_name, mgmt_cp->short_name,
+ sizeof(hdev->short_name));
+
memcpy(hci_cp.name, mgmt_cp->name, sizeof(hci_cp.name));
err = hci_send_cmd(hdev, HCI_OP_WRITE_LOCAL_NAME, sizeof(hci_cp),
&hci_cp);
--
1.7.9
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] Bluetooth: Fix read_name updating when HCI_SETUP is not set
2012-02-22 19:06 [PATCH 1/3] Bluetooth: Add hdev->short_name for EIR generation johan.hedberg
@ 2012-02-22 19:06 ` johan.hedberg
2012-02-22 19:14 ` Marcel Holtmann
2012-02-22 19:06 ` [PATCH 3/3] Bluetooth: mgmt: Allow local name changes while powered off johan.hedberg
2012-02-22 19:14 ` [PATCH 1/3] Bluetooth: Add hdev->short_name for EIR generation Marcel Holtmann
2 siblings, 1 reply; 6+ messages in thread
From: johan.hedberg @ 2012-02-22 19:06 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
The local name should only be updated as a consequence of a
hci_read_local_name if we are in the HCI_SETUP state. In all other
scenarios it should only be updated through hci_write_local_name.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/hci_event.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index c79ffb9..9917fe3 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -227,7 +227,8 @@ 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, HCI_MAX_NAME_LENGTH);
+ if (test_bit(HCI_SETUP, &hdev->dev_flags))
+ 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)
--
1.7.9
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] Bluetooth: mgmt: Allow local name changes while powered off
2012-02-22 19:06 [PATCH 1/3] Bluetooth: Add hdev->short_name for EIR generation johan.hedberg
2012-02-22 19:06 ` [PATCH 2/3] Bluetooth: Fix read_name updating when HCI_SETUP is not set johan.hedberg
@ 2012-02-22 19:06 ` johan.hedberg
2012-02-22 19:26 ` Marcel Holtmann
2012-02-22 19:14 ` [PATCH 1/3] Bluetooth: Add hdev->short_name for EIR generation Marcel Holtmann
2 siblings, 1 reply; 6+ messages in thread
From: johan.hedberg @ 2012-02-22 19:06 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
This patch makes it possible to set the local name before powering on
the device. The name will be applied using the hci_write_local_name
command once the device gets powered on.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/hci_event.c | 13 ++++++++++---
net/bluetooth/mgmt.c | 38 ++++++++++++++++++++++++++------------
2 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 9917fe3..9b30587 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -209,11 +209,10 @@ static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
hci_dev_lock(hdev);
- if (status == 0)
- memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
-
if (test_bit(HCI_MGMT, &hdev->dev_flags))
mgmt_set_local_name_complete(hdev, sent, status);
+ else if (!status)
+ memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
hci_dev_unlock(hdev);
}
@@ -563,6 +562,14 @@ static void hci_setup(struct hci_dev *hdev)
if (hdev->hci_ver > BLUETOOTH_VER_1_1)
hci_send_cmd(hdev, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL);
+ if (!test_bit(HCI_SETUP, &hdev->dev_flags) &&
+ test_bit(HCI_MGMT, &hdev->dev_flags)) {
+ struct hci_cp_write_local_name cp;
+
+ memcpy(cp.name, hdev->dev_name, sizeof(cp.name));
+ hci_send_cmd(hdev, HCI_OP_WRITE_LOCAL_NAME, sizeof(cp), &cp);
+ }
+
if (hdev->features[6] & LMP_SIMPLE_PAIR) {
if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags)) {
u8 mode = 0x01;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 3f6a2df..9c1f771 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2260,22 +2260,29 @@ static int set_local_name(struct sock *sk, u16 index, void *data,
hci_dev_lock(hdev);
+ memcpy(hdev->short_name, mgmt_cp->short_name,
+ sizeof(hdev->short_name));
+
if (!hdev_is_powered(hdev)) {
- err = cmd_status(sk, index, MGMT_OP_SET_LOCAL_NAME,
- MGMT_STATUS_NOT_POWERED);
+ memcpy(hdev->dev_name, mgmt_cp->name, sizeof(hdev->dev_name));
+
+ err = cmd_complete(sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0,
+ data, len);
+ if (err < 0)
+ goto failed;
+
+ err = mgmt_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, data, len,
+ sk);
+
goto failed;
}
- cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data,
- len);
+ cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data, len);
if (!cmd) {
err = -ENOMEM;
goto failed;
}
- memcpy(hdev->short_name, mgmt_cp->short_name,
- sizeof(hdev->short_name));
-
memcpy(hci_cp.name, mgmt_cp->name, sizeof(hci_cp.name));
err = hci_send_cmd(hdev, HCI_OP_WRITE_LOCAL_NAME, sizeof(hci_cp),
&hci_cp);
@@ -3563,10 +3570,17 @@ int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status)
{
struct pending_cmd *cmd;
struct mgmt_cp_set_local_name ev;
- int err;
+ bool changed = false;
+ int err = 0;
+
+ if (memcmp(name, hdev->dev_name, sizeof(hdev->dev_name)) != 0) {
+ memcpy(hdev->dev_name, name, sizeof(hdev->dev_name));
+ changed = true;
+ }
memset(&ev, 0, sizeof(ev));
memcpy(ev.name, name, HCI_MAX_NAME_LENGTH);
+ memcpy(ev.short_name, hdev->short_name, HCI_MAX_SHORT_NAME_LENGTH);
cmd = mgmt_pending_find(MGMT_OP_SET_LOCAL_NAME, hdev);
if (!cmd)
@@ -3578,16 +3592,16 @@ int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status)
goto failed;
}
- update_eir(hdev);
-
err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 0, &ev,
sizeof(ev));
if (err < 0)
goto failed;
send_event:
- err = mgmt_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, &ev, sizeof(ev),
- cmd ? cmd->sk : NULL);
+ if (changed)
+ err = mgmt_event(MGMT_EV_LOCAL_NAME_CHANGED, hdev, &ev,
+ sizeof(ev), cmd ? cmd->sk : NULL);
+
update_eir(hdev);
failed:
--
1.7.9
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] Bluetooth: Add hdev->short_name for EIR generation
2012-02-22 19:06 [PATCH 1/3] Bluetooth: Add hdev->short_name for EIR generation johan.hedberg
2012-02-22 19:06 ` [PATCH 2/3] Bluetooth: Fix read_name updating when HCI_SETUP is not set johan.hedberg
2012-02-22 19:06 ` [PATCH 3/3] Bluetooth: mgmt: Allow local name changes while powered off johan.hedberg
@ 2012-02-22 19:14 ` Marcel Holtmann
2 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2012-02-22 19:14 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
Hi Johan,
> It's possible to provide a short name through the mgmt interface and
> this name can be used for EIR generation when the full name doesn't fit
> there. This patch adds the preliminary tracking of the provided short
> name.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> include/net/bluetooth/hci_core.h | 3 +++
> include/net/bluetooth/mgmt.h | 2 +-
> net/bluetooth/mgmt.c | 3 +++
> 3 files changed, 7 insertions(+), 1 deletions(-)
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Regards
Marcel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] Bluetooth: Fix read_name updating when HCI_SETUP is not set
2012-02-22 19:06 ` [PATCH 2/3] Bluetooth: Fix read_name updating when HCI_SETUP is not set johan.hedberg
@ 2012-02-22 19:14 ` Marcel Holtmann
0 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2012-02-22 19:14 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
Hi Johan,
> The local name should only be updated as a consequence of a
> hci_read_local_name if we are in the HCI_SETUP state. In all other
> scenarios it should only be updated through hci_write_local_name.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/hci_event.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Regards
Marcel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] Bluetooth: mgmt: Allow local name changes while powered off
2012-02-22 19:06 ` [PATCH 3/3] Bluetooth: mgmt: Allow local name changes while powered off johan.hedberg
@ 2012-02-22 19:26 ` Marcel Holtmann
0 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2012-02-22 19:26 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
Hi Johan,
> This patch makes it possible to set the local name before powering on
> the device. The name will be applied using the hci_write_local_name
> command once the device gets powered on.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/hci_event.c | 13 ++++++++++---
> net/bluetooth/mgmt.c | 38 ++++++++++++++++++++++++++------------
> 2 files changed, 36 insertions(+), 15 deletions(-)
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Regards
Marcel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-02-22 19:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-22 19:06 [PATCH 1/3] Bluetooth: Add hdev->short_name for EIR generation johan.hedberg
2012-02-22 19:06 ` [PATCH 2/3] Bluetooth: Fix read_name updating when HCI_SETUP is not set johan.hedberg
2012-02-22 19:14 ` Marcel Holtmann
2012-02-22 19:06 ` [PATCH 3/3] Bluetooth: mgmt: Allow local name changes while powered off johan.hedberg
2012-02-22 19:26 ` Marcel Holtmann
2012-02-22 19:14 ` [PATCH 1/3] Bluetooth: Add hdev->short_name for EIR generation Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).