Skip to contentSkip to conversation

Bleutooth: Add definitions for LE Read Tx Power

PATCH In review Ankit Navik 2 participants 2 messages Jan 9, 2020 – Jan 14, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Bleutooth: Add definitions for LE Read Tx Power

Add the definitions for LE read transmit power HCI commands to read the minimum and maximum Tx power.

---
 include/net/bluetooth/hci.h      |  7 +++++++
 include/net/bluetooth/hci_core.h |  3 +++
 net/bluetooth/hci_event.c        | 17 +++++++++++++++++
 3 files changed, 27 insertions(+)
include/net/bluetooth/hci.h +7 -0
index 07b6ece..eccb6b2 100644
@@ -1718,6 +1718,13 @@ struct hci_cp_le_set_adv_set_rand_addr {
 	bdaddr_t  bdaddr;
 } __packed;
 
+#define HCI_OP_LE_READ_TX_POWER		0x204b
+struct hci_rp_le_read_tx_power {
+	__u8 status;
+	__s8 min_tx_power;
+	__s8 max_tx_power;
+} __packed;
+
 /* ---- HCI Events ---- */
 #define HCI_EV_INQUIRY_COMPLETE		0x01
 
include/net/bluetooth/hci_core.h +3 -0
index faebe38..f3d389d 100644
@@ -418,6 +418,9 @@ struct hci_dev {
 	__u8			scan_rsp_data[HCI_MAX_AD_LENGTH];
 	__u8			scan_rsp_data_len;
 
+	__s8			le_min_tx_power;
+	__s8			le_max_tx_power;
+
 	struct list_head	adv_instances;
 	unsigned int		adv_instance_cnt;
 	__u8			cur_adv_instance;
net/bluetooth/hci_event.c +17 -0
index 6ddc4a7..3646f77 100644
@@ -988,6 +988,19 @@ static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev,
 	hdev->adv_tx_power = rp->tx_power;
 }
 
+static void hci_cc_le_read_tx_power(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	struct hci_rp_le_read_tx_power *rp = (void *) skb->data;
+
+	BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
+
+	if (rp->status)
+		return;
+
+	hdev->le_min_tx_power = rp->min_tx_power;
+	hdev->le_max_tx_power = rp->max_tx_power;
+}
+
 static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
@@ -3414,6 +3427,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
 		hci_cc_le_read_max_data_len(hdev, skb);
 		break;
 
+	case HCI_OP_LE_READ_TX_POWER:
+		hci_cc_le_read_tx_power(hdev, skb);
+		break;
+
 	case HCI_OP_WRITE_LE_HOST_SUPPORTED:
 		hci_cc_write_le_host_supported(hdev, skb);
 		break;
Signature · 1 line
2.7.4
maintainer
#1 lore raw

Hi Ankit,

Quoted 67 lines

Add the definitions for LE read transmit power HCI commands to read the minimum and maximum Tx power.

---

include/net/bluetooth/hci.h      |  7 +++++++
include/net/bluetooth/hci_core.h |  3 +++
net/bluetooth/hci_event.c        | 17 +++++++++++++++++
3 files changed, 27 insertions(+)
include/net/bluetooth/hci.h +7 -0
index 07b6ece..eccb6b2 100644
@@ -1718,6 +1718,13 @@ struct hci_cp_le_set_adv_set_rand_addr {
 	bdaddr_t  bdaddr;
 } __packed;
 
+#define HCI_OP_LE_READ_TX_POWER		0x204b
+struct hci_rp_le_read_tx_power {
+	__u8 status;
+	__s8 min_tx_power;
+	__s8 max_tx_power;
+} __packed;
+
 /* ---- HCI Events ---- */
 #define HCI_EV_INQUIRY_COMPLETE		0x01
 
include/net/bluetooth/hci_core.h +3 -0
index faebe38..f3d389d 100644
@@ -418,6 +418,9 @@ struct hci_dev {
 	__u8			scan_rsp_data[HCI_MAX_AD_LENGTH];
 	__u8			scan_rsp_data_len;
 
+	__s8			le_min_tx_power;
+	__s8			le_max_tx_power;
+
 	struct list_head	adv_instances;
 	unsigned int		adv_instance_cnt;
 	__u8			cur_adv_instance;
net/bluetooth/hci_event.c +13 -0
index 6ddc4a7..3646f77 100644
@@ -988,6 +988,19 @@ static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev,
 	hdev->adv_tx_power = rp->tx_power;
 }
 
+static void hci_cc_le_read_tx_power(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	struct hci_rp_le_read_tx_power *rp = (void *) skb->data;
+
+	BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
+
+	if (rp->status)
+		return;
+
+	hdev->le_min_tx_power = rp->min_tx_power;
+	hdev->le_max_tx_power = rp->max_tx_power;
+}
+
 static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct hci_rp_user_confirm_reply *rp = (void *) skb->data;

net/bluetooth/hci_event.c static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, · line 3436

Quoted 10 lines
net/bluetooth/hci_event.c +4 -0
@@ -3414,6 +3427,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
 		hci_cc_le_read_max_data_len(hdev, skb);
 		break;
 
+	case HCI_OP_LE_READ_TX_POWER:
+		hci_cc_le_read_tx_power(hdev, skb);
+		break;
+
 	case HCI_OP_WRITE_LE_HOST_SUPPORTED:
 		hci_cc_write_le_host_supported(hdev, skb);
 		break;

by itself this addition is useless. You also need to send the HCI_OP_LE_READ_TX_POWER during the power on of the controller. Please add that part.

And on the controller creation you need to the default le_{min,max}_tx_power fields to invalid.

Regards

Marcel