All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] Bluetooth: Use proper invalid value for tx_power
@ 2012-11-06 22:06 Johan Hedberg
  2012-11-06 22:06 ` [PATCH 2/3] Bluetooth: Add support for setting LE advertising data Johan Hedberg
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Johan Hedberg @ 2012-11-06 22:06 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

The core specification defines 127 as the "not available" value (well,
"reserved" for BR/EDR and "not available" for LE - but essentially the
same). Therefore, instead of testing for 0 (which is in fact a valid
value) we should be using this invalid value to test if the tx_power is
available.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci.h |    3 +++
 net/bluetooth/hci_core.c    |    2 ++
 net/bluetooth/hci_event.c   |    2 ++
 net/bluetooth/mgmt.c        |    2 +-
 4 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 6c414f4..344fea0 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -319,6 +319,9 @@ enum {
 #define HCI_FLOW_CTL_MODE_PACKET_BASED	0x00
 #define HCI_FLOW_CTL_MODE_BLOCK_BASED	0x01
 
+/* The core spec defines 127 as the "not available" value */
+#define HCI_TX_POWER_INVALID	127
+
 /* Extended Inquiry Response field types */
 #define EIR_FLAGS		0x01 /* flags */
 #define EIR_UUID16_SOME		0x02 /* 16-bit UUID, more available */
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index c68c409..0af08f3 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1606,6 +1606,8 @@ struct hci_dev *hci_alloc_dev(void)
 	hdev->esco_type = (ESCO_HV1);
 	hdev->link_mode = (HCI_LM_ACCEPT);
 	hdev->io_capability = 0x03; /* No Input No Output */
+	hdev->inq_tx_power = HCI_TX_POWER_INVALID;
+	hdev->adv_tx_power = HCI_TX_POWER_INVALID;
 
 	hdev->sniff_max_interval = 800;
 	hdev->sniff_min_interval = 80;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index c08ac7c..09c6571 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -202,6 +202,8 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
 			     BIT(HCI_PERIODIC_INQ));
 
 	hdev->discovery.state = DISCOVERY_STOPPED;
+	hdev->inq_tx_power = HCI_TX_POWER_INVALID;
+	hdev->adv_tx_power = HCI_TX_POWER_INVALID;
 }
 
 static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 26a0984..ad1054f 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -485,7 +485,7 @@ static void create_eir(struct hci_dev *hdev, u8 *data)
 		ptr += (name_len + 2);
 	}
 
-	if (hdev->inq_tx_power) {
+	if (hdev->inq_tx_power != HCI_TX_POWER_INVALID) {
 		ptr[0] = 2;
 		ptr[1] = EIR_TX_POWER;
 		ptr[2] = (u8) hdev->inq_tx_power;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] Bluetooth: Add support for setting LE advertising data
  2012-11-06 22:06 [PATCH 1/3] Bluetooth: Use proper invalid value for tx_power Johan Hedberg
@ 2012-11-06 22:06 ` Johan Hedberg
  2012-11-07 15:55   ` Marcel Holtmann
  2012-11-06 22:06 ` [PATCH 3/3] Bluetooth: Fix updating advertising state flags and data Johan Hedberg
  2012-11-07 15:53 ` [PATCH 1/3] Bluetooth: Use proper invalid value for tx_power Marcel Holtmann
  2 siblings, 1 reply; 9+ messages in thread
From: Johan Hedberg @ 2012-11-06 22:06 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch adds support for setting basing LE advertising data. The
three elements supported for now are the advertising flags, the TX power
and the friendly name.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci.h      |   15 ++++++
 include/net/bluetooth/hci_core.h |    4 ++
 net/bluetooth/hci_core.c         |   97 ++++++++++++++++++++++++++++++++++++++
 net/bluetooth/hci_event.c        |   11 ++++-
 4 files changed, 126 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 344fea0..705e2f0 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -338,6 +338,13 @@ enum {
 #define EIR_SSP_RAND_R		0x0F /* Simple Pairing Randomizer R */
 #define EIR_DEVICE_ID		0x10 /* device ID */
 
+/* Low Energy Advertising Flags */
+#define LE_AD_LIMITED		0x01 /* Limited Discoverable */
+#define LE_AD_GENERAL		0x02 /* General Discoverable */
+#define LE_AD_NO_BREDR		0x04 /* BR/EDR not supported */
+#define LE_AD_SIM_LE_BREDR_CTRL	0x08 /* Simultaneous LE & BR/EDR Controller */
+#define LE_AD_SIM_LE_BREDR_HOST	0x10 /* Simultaneous LE & BR/EDR Host */
+
 /* -----  HCI Commands ---- */
 #define HCI_OP_NOP			0x0000
 
@@ -942,6 +949,14 @@ struct hci_rp_le_read_adv_tx_power {
 	__s8	tx_power;
 } __packed;
 
+#define HCI_MAX_AD_LENGTH		31
+
+#define HCI_OP_LE_SET_ADV_DATA		0x2008
+struct hci_cp_le_set_adv_data {
+	__u8		length;
+	__u8		data[HCI_MAX_AD_LENGTH];
+} __packed;
+
 #define HCI_OP_LE_SET_SCAN_PARAM	0x200b
 struct hci_cp_le_set_scan_param {
 	__u8    type;
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index ce6dbeb..ef5b85d 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -279,6 +279,8 @@ struct hci_dev {
 	struct le_scan_params	le_scan_params;
 
 	__s8			adv_tx_power;
+	__u8			adv_data[HCI_MAX_AD_LENGTH];
+	__u8			adv_data_len;
 
 	int (*open)(struct hci_dev *hdev);
 	int (*close)(struct hci_dev *hdev);
@@ -734,6 +736,8 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
 								u8 *randomizer);
 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
 
+int hci_update_ad(struct hci_dev *hdev);
+
 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
 
 int hci_recv_frame(struct sk_buff *skb);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 0af08f3..0af3ea8 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -594,6 +594,102 @@ done:
 	return err;
 }
 
+static u16 create_ad(struct hci_dev *hdev, u8 *data)
+{
+	u8 *ptr = data;
+	u16 ad_len = 0;
+	size_t name_len;
+	u8 flags = 0;
+
+	if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags))
+		flags |= LE_AD_GENERAL;
+
+	if (!lmp_bredr_capable(hdev))
+		flags |= LE_AD_NO_BREDR;
+
+	if (lmp_le_br_capable(hdev))
+		flags |= LE_AD_SIM_LE_BREDR_CTRL;
+
+	if (lmp_host_le_br_capable(hdev))
+		flags |= LE_AD_SIM_LE_BREDR_HOST;
+
+	if (flags) {
+		BT_DBG("adv flags 0x%02x", flags);
+
+		ptr[0] = 2;
+		ptr[1] = EIR_FLAGS;
+		ptr[2] = flags;
+
+		ad_len += 3;
+		ptr += 3;
+	}
+
+	if (hdev->adv_tx_power != HCI_TX_POWER_INVALID) {
+		ptr[0] = 2;
+		ptr[1] = EIR_TX_POWER;
+		ptr[2] = (u8) hdev->adv_tx_power;
+
+		ad_len += 3;
+		ptr += 3;
+	}
+
+	name_len = strlen(hdev->dev_name);
+	if (name_len > 0) {
+		size_t max_len = HCI_MAX_AD_LENGTH - ad_len - 2;
+
+		if (name_len > max_len) {
+			name_len = max_len;
+			ptr[1] = EIR_NAME_SHORT;
+		} else
+			ptr[1] = EIR_NAME_COMPLETE;
+
+		ptr[0] = name_len + 1;
+
+		memcpy(ptr + 2, hdev->dev_name, name_len);
+
+		ad_len += (name_len + 2);
+		ptr += (name_len + 2);
+	}
+
+	return ad_len;
+}
+
+int hci_update_ad(struct hci_dev *hdev)
+{
+	struct hci_cp_le_set_adv_data cp;
+	u16 len;
+	int err;
+
+	hci_dev_lock(hdev);
+
+	if (!lmp_le_capable(hdev)) {
+		err = -EINVAL;
+		goto unlock;
+	}
+
+	memset(&cp, 0, sizeof(cp));
+
+	len = create_ad(hdev, cp.data);
+
+	if (hdev->adv_data_len == len &&
+	    memcmp(cp.data, hdev->adv_data, len) == 0) {
+		err = 0;
+		goto unlock;
+	}
+
+	memcpy(hdev->adv_data, cp.data, sizeof(cp.data));
+	hdev->adv_data_len = len;
+
+	cp.length = cpu_to_le16(len);
+
+	err = hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_DATA, sizeof(cp), &cp);
+
+unlock:
+	hci_dev_unlock(hdev);
+
+	return err;
+}
+
 /* ---- HCI ioctl helpers ---- */
 
 int hci_dev_open(__u16 dev)
@@ -651,6 +747,7 @@ int hci_dev_open(__u16 dev)
 		hci_dev_hold(hdev);
 		set_bit(HCI_UP, &hdev->flags);
 		hci_notify(hdev, HCI_DEV_UP);
+		hci_update_ad(hdev);
 		if (!test_bit(HCI_SETUP, &hdev->dev_flags) &&
 		    mgmt_valid_hdev(hdev)) {
 			hci_dev_lock(hdev);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 09c6571..7caea1a 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -204,6 +204,9 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
 	hdev->discovery.state = DISCOVERY_STOPPED;
 	hdev->inq_tx_power = HCI_TX_POWER_INVALID;
 	hdev->adv_tx_power = HCI_TX_POWER_INVALID;
+
+	memset(hdev->adv_data, 0, sizeof(hdev->adv_data));
+	hdev->adv_data_len = 0;
 }
 
 static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
@@ -226,6 +229,9 @@ static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
 
 	hci_dev_unlock(hdev);
 
+	if (!status && !test_bit(HCI_INIT, &hdev->flags))
+		hci_update_ad(hdev);
+
 	hci_req_complete(hdev, HCI_OP_WRITE_LOCAL_NAME, status);
 }
 
@@ -1091,8 +1097,11 @@ static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev,
 
 	BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
 
-	if (!rp->status)
+	if (!rp->status) {
 		hdev->adv_tx_power = rp->tx_power;
+		if (!test_bit(HCI_INIT, &hdev->flags))
+			hci_update_ad(hdev);
+	}
 
 	hci_req_complete(hdev, HCI_OP_LE_READ_ADV_TX_POWER, rp->status);
 }
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] Bluetooth: Fix updating advertising state flags and data
  2012-11-06 22:06 [PATCH 1/3] Bluetooth: Use proper invalid value for tx_power Johan Hedberg
  2012-11-06 22:06 ` [PATCH 2/3] Bluetooth: Add support for setting LE advertising data Johan Hedberg
@ 2012-11-06 22:06 ` Johan Hedberg
  2012-11-07 15:56   ` Marcel Holtmann
  2012-11-07 15:53 ` [PATCH 1/3] Bluetooth: Use proper invalid value for tx_power Marcel Holtmann
  2 siblings, 1 reply; 9+ messages in thread
From: Johan Hedberg @ 2012-11-06 22:06 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch adds a callback for the HCI_LE_Set_Advertise_Enable command.
The callback is responsible for updating the HCI_LE_PERIPHERAL flag
updating as well as updating the advertising data flags field to
indicate undirected connectable advertising.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci.h |    2 ++
 net/bluetooth/hci_event.c   |   31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 705e2f0..a7ed8fe 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -957,6 +957,8 @@ struct hci_cp_le_set_adv_data {
 	__u8		data[HCI_MAX_AD_LENGTH];
 } __packed;
 
+#define HCI_OP_LE_SET_ADV_ENABLE	0x200a
+
 #define HCI_OP_LE_SET_SCAN_PARAM	0x200b
 struct hci_cp_le_set_scan_param {
 	__u8    type;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 7caea1a..9f5c5f2 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1190,6 +1190,33 @@ static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
 	hci_dev_unlock(hdev);
 }
 
+static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	__u8 *sent, status = *((__u8 *) skb->data);
+
+	BT_DBG("%s status 0x%2.2x", hdev->name, status);
+
+	sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_ENABLE);
+	if (!sent)
+		return;
+
+	hci_dev_lock(hdev);
+
+	if (!status) {
+		if (*sent)
+			set_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
+		else
+			clear_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
+	}
+
+	hci_dev_unlock(hdev);
+
+	if (!test_bit(HCI_INIT, &hdev->flags))
+		hci_update_ad(hdev);
+
+	hci_req_complete(hdev, HCI_OP_LE_SET_ADV_ENABLE, status);
+}
+
 static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	__u8 status = *((__u8 *) skb->data);
@@ -2585,6 +2612,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_cc_le_set_scan_param(hdev, skb);
 		break;
 
+	case HCI_OP_LE_SET_ADV_ENABLE:
+		hci_cc_le_set_adv_enable(hdev, skb);
+		break;
+
 	case HCI_OP_LE_SET_SCAN_ENABLE:
 		hci_cc_le_set_scan_enable(hdev, skb);
 		break;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] Bluetooth: Use proper invalid value for tx_power
  2012-11-06 22:06 [PATCH 1/3] Bluetooth: Use proper invalid value for tx_power Johan Hedberg
  2012-11-06 22:06 ` [PATCH 2/3] Bluetooth: Add support for setting LE advertising data Johan Hedberg
  2012-11-06 22:06 ` [PATCH 3/3] Bluetooth: Fix updating advertising state flags and data Johan Hedberg
@ 2012-11-07 15:53 ` Marcel Holtmann
  2 siblings, 0 replies; 9+ messages in thread
From: Marcel Holtmann @ 2012-11-07 15:53 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> The core specification defines 127 as the "not available" value (well,
> "reserved" for BR/EDR and "not available" for LE - but essentially the
> same). Therefore, instead of testing for 0 (which is in fact a valid
> value) we should be using this invalid value to test if the tx_power is
> available.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
>  include/net/bluetooth/hci.h |    3 +++
>  net/bluetooth/hci_core.c    |    2 ++
>  net/bluetooth/hci_event.c   |    2 ++
>  net/bluetooth/mgmt.c        |    2 +-
>  4 files changed, 8 insertions(+), 1 deletion(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] Bluetooth: Add support for setting LE advertising data
  2012-11-06 22:06 ` [PATCH 2/3] Bluetooth: Add support for setting LE advertising data Johan Hedberg
@ 2012-11-07 15:55   ` Marcel Holtmann
  2012-11-08  0:17     ` Johan Hedberg
  0 siblings, 1 reply; 9+ messages in thread
From: Marcel Holtmann @ 2012-11-07 15:55 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> This patch adds support for setting basing LE advertising data. The
> three elements supported for now are the advertising flags, the TX power
> and the friendly name.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
>  include/net/bluetooth/hci.h      |   15 ++++++
>  include/net/bluetooth/hci_core.h |    4 ++
>  net/bluetooth/hci_core.c         |   97 ++++++++++++++++++++++++++++++++++++++
>  net/bluetooth/hci_event.c        |   11 ++++-
>  4 files changed, 126 insertions(+), 1 deletion(-)
> 
> diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
> index 344fea0..705e2f0 100644
> --- a/include/net/bluetooth/hci.h
> +++ b/include/net/bluetooth/hci.h
> @@ -338,6 +338,13 @@ enum {
>  #define EIR_SSP_RAND_R		0x0F /* Simple Pairing Randomizer R */
>  #define EIR_DEVICE_ID		0x10 /* device ID */
>  
> +/* Low Energy Advertising Flags */
> +#define LE_AD_LIMITED		0x01 /* Limited Discoverable */
> +#define LE_AD_GENERAL		0x02 /* General Discoverable */
> +#define LE_AD_NO_BREDR		0x04 /* BR/EDR not supported */
> +#define LE_AD_SIM_LE_BREDR_CTRL	0x08 /* Simultaneous LE & BR/EDR Controller */
> +#define LE_AD_SIM_LE_BREDR_HOST	0x10 /* Simultaneous LE & BR/EDR Host */
> +

is this bad formatting in the email client and they are actually
aligned.

>  /* -----  HCI Commands ---- */
>  #define HCI_OP_NOP			0x0000
>  
> @@ -942,6 +949,14 @@ struct hci_rp_le_read_adv_tx_power {
>  	__s8	tx_power;
>  } __packed;
>  
> +#define HCI_MAX_AD_LENGTH		31
> +
> +#define HCI_OP_LE_SET_ADV_DATA		0x2008
> +struct hci_cp_le_set_adv_data {
> +	__u8		length;
> +	__u8		data[HCI_MAX_AD_LENGTH];
> +} __packed;
> +

This indentation looks weird.

>  #define HCI_OP_LE_SET_SCAN_PARAM	0x200b
>  struct hci_cp_le_set_scan_param {
>  	__u8    type;
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index ce6dbeb..ef5b85d 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -279,6 +279,8 @@ struct hci_dev {
>  	struct le_scan_params	le_scan_params;
>  
>  	__s8			adv_tx_power;
> +	__u8			adv_data[HCI_MAX_AD_LENGTH];
> +	__u8			adv_data_len;
>  
>  	int (*open)(struct hci_dev *hdev);
>  	int (*close)(struct hci_dev *hdev);
> @@ -734,6 +736,8 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
>  								u8 *randomizer);
>  int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
>  
> +int hci_update_ad(struct hci_dev *hdev);
> +
>  void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
>  
>  int hci_recv_frame(struct sk_buff *skb);
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index 0af08f3..0af3ea8 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -594,6 +594,102 @@ done:
>  	return err;
>  }
>  
> +static u16 create_ad(struct hci_dev *hdev, u8 *data)
> +{
> +	u8 *ptr = data;
> +	u16 ad_len = 0;
> +	size_t name_len;
> +	u8 flags = 0;
> +
> +	if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags))
> +		flags |= LE_AD_GENERAL;
> +
> +	if (!lmp_bredr_capable(hdev))
> +		flags |= LE_AD_NO_BREDR;
> +
> +	if (lmp_le_br_capable(hdev))
> +		flags |= LE_AD_SIM_LE_BREDR_CTRL;
> +
> +	if (lmp_host_le_br_capable(hdev))
> +		flags |= LE_AD_SIM_LE_BREDR_HOST;
> +
> +	if (flags) {
> +		BT_DBG("adv flags 0x%02x", flags);
> +
> +		ptr[0] = 2;
> +		ptr[1] = EIR_FLAGS;
> +		ptr[2] = flags;
> +
> +		ad_len += 3;
> +		ptr += 3;
> +	}
> +
> +	if (hdev->adv_tx_power != HCI_TX_POWER_INVALID) {
> +		ptr[0] = 2;
> +		ptr[1] = EIR_TX_POWER;
> +		ptr[2] = (u8) hdev->adv_tx_power;
> +
> +		ad_len += 3;
> +		ptr += 3;
> +	}
> +
> +	name_len = strlen(hdev->dev_name);
> +	if (name_len > 0) {
> +		size_t max_len = HCI_MAX_AD_LENGTH - ad_len - 2;
> +
> +		if (name_len > max_len) {
> +			name_len = max_len;
> +			ptr[1] = EIR_NAME_SHORT;
> +		} else
> +			ptr[1] = EIR_NAME_COMPLETE;
> +
> +		ptr[0] = name_len + 1;
> +
> +		memcpy(ptr + 2, hdev->dev_name, name_len);
> +
> +		ad_len += (name_len + 2);
> +		ptr += (name_len + 2);
> +	}
> +
> +	return ad_len;
> +}
> +
> +int hci_update_ad(struct hci_dev *hdev)
> +{
> +	struct hci_cp_le_set_adv_data cp;
> +	u16 len;
> +	int err;
> +
> +	hci_dev_lock(hdev);
> +
> +	if (!lmp_le_capable(hdev)) {
> +		err = -EINVAL;
> +		goto unlock;
> +	}
> +
> +	memset(&cp, 0, sizeof(cp));
> +
> +	len = create_ad(hdev, cp.data);
> +
> +	if (hdev->adv_data_len == len &&
> +	    memcmp(cp.data, hdev->adv_data, len) == 0) {
> +		err = 0;
> +		goto unlock;
> +	}
> +
> +	memcpy(hdev->adv_data, cp.data, sizeof(cp.data));
> +	hdev->adv_data_len = len;
> +
> +	cp.length = cpu_to_le16(len);
> +
> +	err = hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_DATA, sizeof(cp), &cp);
> +
> +unlock:
> +	hci_dev_unlock(hdev);
> +
> +	return err;
> +}
> +
>  /* ---- HCI ioctl helpers ---- */
>  
>  int hci_dev_open(__u16 dev)
> @@ -651,6 +747,7 @@ int hci_dev_open(__u16 dev)
>  		hci_dev_hold(hdev);
>  		set_bit(HCI_UP, &hdev->flags);
>  		hci_notify(hdev, HCI_DEV_UP);
> +		hci_update_ad(hdev);
>  		if (!test_bit(HCI_SETUP, &hdev->dev_flags) &&
>  		    mgmt_valid_hdev(hdev)) {
>  			hci_dev_lock(hdev);
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 09c6571..7caea1a 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -204,6 +204,9 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
>  	hdev->discovery.state = DISCOVERY_STOPPED;
>  	hdev->inq_tx_power = HCI_TX_POWER_INVALID;
>  	hdev->adv_tx_power = HCI_TX_POWER_INVALID;
> +
> +	memset(hdev->adv_data, 0, sizeof(hdev->adv_data));
> +	hdev->adv_data_len = 0;
>  }
>  
>  static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
> @@ -226,6 +229,9 @@ static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
>  
>  	hci_dev_unlock(hdev);
>  
> +	if (!status && !test_bit(HCI_INIT, &hdev->flags))
> +		hci_update_ad(hdev);
> +
>  	hci_req_complete(hdev, HCI_OP_WRITE_LOCAL_NAME, status);
>  }
>  
> @@ -1091,8 +1097,11 @@ static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev,
>  
>  	BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
>  
> -	if (!rp->status)
> +	if (!rp->status) {
>  		hdev->adv_tx_power = rp->tx_power;
> +		if (!test_bit(HCI_INIT, &hdev->flags))
> +			hci_update_ad(hdev);
> +	}
>  
>  	hci_req_complete(hdev, HCI_OP_LE_READ_ADV_TX_POWER, rp->status);
>  }

Regards

Marcel



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] Bluetooth: Fix updating advertising state flags and data
  2012-11-06 22:06 ` [PATCH 3/3] Bluetooth: Fix updating advertising state flags and data Johan Hedberg
@ 2012-11-07 15:56   ` Marcel Holtmann
  0 siblings, 0 replies; 9+ messages in thread
From: Marcel Holtmann @ 2012-11-07 15:56 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> This patch adds a callback for the HCI_LE_Set_Advertise_Enable command.
> The callback is responsible for updating the HCI_LE_PERIPHERAL flag
> updating as well as updating the advertising data flags field to
> indicate undirected connectable advertising.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
>  include/net/bluetooth/hci.h |    2 ++
>  net/bluetooth/hci_event.c   |   31 +++++++++++++++++++++++++++++++
>  2 files changed, 33 insertions(+)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] Bluetooth: Add support for setting LE advertising data
  2012-11-07 15:55   ` Marcel Holtmann
@ 2012-11-08  0:17     ` Johan Hedberg
  0 siblings, 0 replies; 9+ messages in thread
From: Johan Hedberg @ 2012-11-08  0:17 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth

Hi Marcel,

On Wed, Nov 07, 2012, Marcel Holtmann wrote:
> > diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
> > index 344fea0..705e2f0 100644
> > --- a/include/net/bluetooth/hci.h
> > +++ b/include/net/bluetooth/hci.h
> > @@ -338,6 +338,13 @@ enum {
> >  #define EIR_SSP_RAND_R		0x0F /* Simple Pairing Randomizer R */
> >  #define EIR_DEVICE_ID		0x10 /* device ID */
> >  
> > +/* Low Energy Advertising Flags */
> > +#define LE_AD_LIMITED		0x01 /* Limited Discoverable */
> > +#define LE_AD_GENERAL		0x02 /* General Discoverable */
> > +#define LE_AD_NO_BREDR		0x04 /* BR/EDR not supported */
> > +#define LE_AD_SIM_LE_BREDR_CTRL	0x08 /* Simultaneous LE & BR/EDR Controller */
> > +#define LE_AD_SIM_LE_BREDR_HOST	0x10 /* Simultaneous LE & BR/EDR Host */
> > +
> 
> is this bad formatting in the email client and they are actually
> aligned.

They're properly aligned (I double checked looking at the resulting code
itself)

> > @@ -942,6 +949,14 @@ struct hci_rp_le_read_adv_tx_power {
> >  	__s8	tx_power;
> >  } __packed;
> >  
> > +#define HCI_MAX_AD_LENGTH		31
> > +
> > +#define HCI_OP_LE_SET_ADV_DATA		0x2008
> > +struct hci_cp_le_set_adv_data {
> > +	__u8		length;
> > +	__u8		data[HCI_MAX_AD_LENGTH];
> > +} __packed;
> > +
> 
> This indentation looks weird.

Agreed. Fixed in v2 (where I added your ack since I understood you were
otherwise fine with this patch.

Johan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] Bluetooth: Use proper invalid value for tx_power
  2012-11-08  0:19 Johan Hedberg
@ 2012-11-08  0:22 ` Johan Hedberg
  0 siblings, 0 replies; 9+ messages in thread
From: Johan Hedberg @ 2012-11-08  0:22 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Thu, Nov 08, 2012, Johan Hedberg wrote:
> The core specification defines 127 as the "not available" value (well,
> "reserved" for BR/EDR and "not available" for LE - but essentially the
> same). Therefore, instead of testing for 0 (which is in fact a valid
> value) we should be using this invalid value to test if the tx_power is
> available.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> Acked-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  include/net/bluetooth/hci.h |    3 +++
>  net/bluetooth/hci_core.c    |    2 ++
>  net/bluetooth/hci_event.c   |    2 ++
>  net/bluetooth/mgmt.c        |    2 +-
>  4 files changed, 8 insertions(+), 1 deletion(-)

Please ignore these two patches. They slipped off before I had the
chance to slap the v2 label on them. Proper set coming in a minute.

Johan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] Bluetooth: Use proper invalid value for tx_power
@ 2012-11-08  0:19 Johan Hedberg
  2012-11-08  0:22 ` Johan Hedberg
  0 siblings, 1 reply; 9+ messages in thread
From: Johan Hedberg @ 2012-11-08  0:19 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

The core specification defines 127 as the "not available" value (well,
"reserved" for BR/EDR and "not available" for LE - but essentially the
same). Therefore, instead of testing for 0 (which is in fact a valid
value) we should be using this invalid value to test if the tx_power is
available.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci.h |    3 +++
 net/bluetooth/hci_core.c    |    2 ++
 net/bluetooth/hci_event.c   |    2 ++
 net/bluetooth/mgmt.c        |    2 +-
 4 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 6c414f4..344fea0 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -319,6 +319,9 @@ enum {
 #define HCI_FLOW_CTL_MODE_PACKET_BASED	0x00
 #define HCI_FLOW_CTL_MODE_BLOCK_BASED	0x01
 
+/* The core spec defines 127 as the "not available" value */
+#define HCI_TX_POWER_INVALID	127
+
 /* Extended Inquiry Response field types */
 #define EIR_FLAGS		0x01 /* flags */
 #define EIR_UUID16_SOME		0x02 /* 16-bit UUID, more available */
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index c68c409..0af08f3 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1606,6 +1606,8 @@ struct hci_dev *hci_alloc_dev(void)
 	hdev->esco_type = (ESCO_HV1);
 	hdev->link_mode = (HCI_LM_ACCEPT);
 	hdev->io_capability = 0x03; /* No Input No Output */
+	hdev->inq_tx_power = HCI_TX_POWER_INVALID;
+	hdev->adv_tx_power = HCI_TX_POWER_INVALID;
 
 	hdev->sniff_max_interval = 800;
 	hdev->sniff_min_interval = 80;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index c08ac7c..09c6571 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -202,6 +202,8 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
 			     BIT(HCI_PERIODIC_INQ));
 
 	hdev->discovery.state = DISCOVERY_STOPPED;
+	hdev->inq_tx_power = HCI_TX_POWER_INVALID;
+	hdev->adv_tx_power = HCI_TX_POWER_INVALID;
 }
 
 static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 26a0984..ad1054f 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -485,7 +485,7 @@ static void create_eir(struct hci_dev *hdev, u8 *data)
 		ptr += (name_len + 2);
 	}
 
-	if (hdev->inq_tx_power) {
+	if (hdev->inq_tx_power != HCI_TX_POWER_INVALID) {
 		ptr[0] = 2;
 		ptr[1] = EIR_TX_POWER;
 		ptr[2] = (u8) hdev->inq_tx_power;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-11-08  0:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-06 22:06 [PATCH 1/3] Bluetooth: Use proper invalid value for tx_power Johan Hedberg
2012-11-06 22:06 ` [PATCH 2/3] Bluetooth: Add support for setting LE advertising data Johan Hedberg
2012-11-07 15:55   ` Marcel Holtmann
2012-11-08  0:17     ` Johan Hedberg
2012-11-06 22:06 ` [PATCH 3/3] Bluetooth: Fix updating advertising state flags and data Johan Hedberg
2012-11-07 15:56   ` Marcel Holtmann
2012-11-07 15:53 ` [PATCH 1/3] Bluetooth: Use proper invalid value for tx_power Marcel Holtmann
2012-11-08  0:19 Johan Hedberg
2012-11-08  0:22 ` Johan Hedberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.