Skip to contentSkip to conversation

Bluetooth: Implement Read Transmit Power Level command

RFC In review [email protected] 2 participants 3 messages Jul 13, 2011 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 1310565997-31927-1-git-send-email-y

#1 lore raw

RFC 2/3 Bluetooth: Implement Read Transmit Power Level command

From: Bruna Moreira <[email protected]>

Add Read Transmit Power Level command in MGMT Interface and all infrastructure need for that.

Read Transmit Power Level command is defined on Part E, section 7.3.35 of Bluetooth 4.0 Spec.

---
 include/net/bluetooth/hci.h      |   10 ++++
 include/net/bluetooth/hci_core.h |    3 +
 include/net/bluetooth/mgmt.h     |   10 ++++
 net/bluetooth/hci_event.c        |   25 +++++++++
 net/bluetooth/mgmt.c             |  102 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 150 insertions(+), 0 deletions(-)
include/net/bluetooth/hci.h +10 -0
index 276be6e..7c6016e 100644
@@ -637,6 +637,16 @@ struct hci_cp_write_voice_setting {
 	__le16   voice_setting;
 } __packed;
 
+#define HCI_OP_READ_TX_POWER	0x0c2d
+struct hci_cp_read_tx_power {
+	__le16   handle;
+} __packed;
+struct hci_rp_read_tx_power {
+	__u8     status;
+	__le16   handle;
+	__s8     level;
+} __packed;
+
 #define HCI_OP_HOST_BUFFER_SIZE		0x0c33
 struct hci_cp_host_buffer_size {
 	__le16   acl_mtu;
include/net/bluetooth/hci_core.h +3 -0
index 2a5b804..870f31f 100644
@@ -858,6 +858,9 @@ int mgmt_read_local_oob_data_reply_complete(u16 index, u8 *hash, u8 *randomizer,
 								u8 status);
 int mgmt_read_rssi_complete(u16 index, bdaddr_t *bdaddr, s8 rssi, u8 status);
 int mgmt_read_rssi_failed(u16 index);
+int mgmt_read_tx_power_complete(u16 index, bdaddr_t *bdaddr, s8 level,
+								u8 status);
+int mgmt_read_tx_power_failed(u16 index);
 int mgmt_device_found(u16 index, bdaddr_t *bdaddr, u8 *dev_class, s8 rssi,
 							u8 *eir, u8 eir_len);
 int mgmt_remote_name(u16 index, bdaddr_t *bdaddr, u8 *name);
include/net/bluetooth/mgmt.h +10 -0
index ae0358b..7122aa3 100644
@@ -221,6 +221,16 @@ struct mgmt_rp_read_rssi {
 	__s8 rssi;
 } __packed;
 
+#define MGMT_OP_READ_TX_POWER_LEVEL	0x0020
+struct mgmt_cp_read_tx_power_level {
+	bdaddr_t bdaddr;
+} __packed;
+struct mgmt_rp_read_tx_power_level {
+	bdaddr_t bdaddr;
+	__u8 status;
+	__s8 level;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16 opcode;
net/bluetooth/hci_event.c +25 -0
index e13a98b..bf13fa3 100644
@@ -818,6 +818,26 @@ static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb)
 		conn->pin_length = cp->pin_len;
 }
 
+static void hci_cc_read_tx_power(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	struct hci_rp_read_tx_power *rp = (void *) skb->data;
+	struct hci_conn *conn;
+
+	BT_DBG("%s status 0x%x", hdev->name, rp->status);
+
+	if (!test_bit(HCI_MGMT, &hdev->flags))
+		return;
+
+	conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
+	if(!conn) {
+		mgmt_read_tx_power_failed(hdev->id);
+		return;
+	}
+
+	mgmt_read_tx_power_complete(hdev->id, &conn->dst, rp->level,
+								rp->status);
+}
+
 static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data;
@@ -828,6 +848,7 @@ static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
 		mgmt_pin_code_neg_reply_complete(hdev->id, &rp->bdaddr,
 								rp->status);
 }
+
 static void hci_cc_le_read_buffer_size(struct hci_dev *hdev,
 				       struct sk_buff *skb)
 {
@@ -2036,6 +2057,10 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
 		hci_cc_read_rssi(hdev, skb);
 		break;
 
+	case HCI_OP_READ_TX_POWER:
+		hci_cc_read_tx_power(hdev, skb);
+		break;
+
 	default:
 		BT_DBG("%s opcode 0x%x", hdev->name, opcode);
 		break;
net/bluetooth/mgmt.c +102 -0

114 lines not on this page · raw message

Signature · 1 line
1.7.4.1
maintainer
#2 lore raw

Hi Anderson,

Quoted 5 lines

Add Read Transmit Power Level command in MGMT Interface and all infrastructure need for that.

Read Transmit Power Level command is defined on Part E, section 7.3.35 of Bluetooth 4.0 Spec.

same applies here. If you want this then let the kernel drive and automatic poll of these information.

Regards

Marcel

#3 lore raw

RFC 3/3 Bluetooth: Implement Management command listener

In reply to a message not in the archive

From: Anderson Briglia <[email protected]>

This patch implements new Management commands used to make a type of monitor for selected HCI commands. It is useful when userspace needs to receive updates from the kernel, periodically, without the need to actively do requests.

Userspace via management can register an HCI command and start receiving updates from the controller. For now, the monitor can listen Read RSSI and Read TX Power level commands. But the addition of other commands should not be a problem. It was necessary since we have profiles that need to monitor some connection aspects, like Proximity.

For now, the timer is constant and has a value of 2 seconds, but this is a RFC and this value or approach can be modified.

---
 include/net/bluetooth/hci_core.h |    3 +
 include/net/bluetooth/mgmt.h     |   12 ++
 net/bluetooth/hci_core.c         |   12 ++
 net/bluetooth/mgmt.c             |  205 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 232 insertions(+), 0 deletions(-)
include/net/bluetooth/hci_core.h +3 -0
index 870f31f..8266505 100644
@@ -211,6 +211,8 @@ struct hci_dev {
 
 	struct timer_list	le_scan_timer;
 
+	struct timer_list	cmd_listener_timer;
+
 	struct hci_dev_stats	stat;
 
 	struct sk_buff_head	driver_init;
@@ -873,6 +875,7 @@ int mgmt_has_pending_stop_discov(u16 index);
 int mgmt_cancel_discovery(u16 index);
 int mgmt_is_interleaved_discovery(u16 index);
 int mgmt_do_interleaved_discovery(u16 index);
+int mgmt_request_monitored_cmds(struct hci_dev *hdev);
 
 /* HCI info for socket */
 #define hci_pi(sk) ((struct hci_pinfo *) sk)
include/net/bluetooth/mgmt.h +12 -0
index 7122aa3..4b9513f 100644
@@ -231,6 +231,18 @@ struct mgmt_rp_read_tx_power_level {
 	__s8 level;
 } __packed;
 
+#define MGMT_OP_ADD_LISTENER		0x0021
+struct mgmt_cp_add_listener {
+	__u16 cmd_op_code;
+	bdaddr_t bdaddr;
+} __packed;
+
+#define MGMT_OP_REMOVE_LISTENER		0x0022
+struct mgmt_cp_remove_listener {
+	__u16 cmd_op_code;
+	bdaddr_t bdaddr;
+} __packed;
+
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	__le16 opcode;
net/bluetooth/hci_core.c +12 -0
index c0c46bf..626922b 100644
@@ -1449,6 +1449,14 @@ static void hci_disable_le_scan(unsigned long arg)
 	hci_send_cmd(hdev, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
 }
 
+static void hci_cmd_listener(unsigned long arg)
+{
+	struct hci_dev *hdev = (void *) arg;
+
+	if (test_bit(HCI_MGMT, &hdev->flags))
+		mgmt_request_monitored_cmds(hdev);
+}
+
 /* Register HCI device */
 int hci_register_dev(struct hci_dev *hdev)
 {
@@ -1522,6 +1530,9 @@ int hci_register_dev(struct hci_dev *hdev)
 	setup_timer(&hdev->le_scan_timer, hci_disable_le_scan,
 						(unsigned long) hdev);
 
+	setup_timer(&hdev->cmd_listener_timer, hci_cmd_listener,
+			(unsigned long) hdev);
+
 	INIT_WORK(&hdev->power_on, hci_power_on);
 	INIT_WORK(&hdev->power_off, hci_power_off);
 	setup_timer(&hdev->off_timer, hci_auto_off, (unsigned long) hdev);
@@ -1604,6 +1615,7 @@ int hci_unregister_dev(struct hci_dev *hdev)
 	hci_del_off_timer(hdev);
 	del_timer(&hdev->adv_timer);
 	del_timer(&hdev->le_scan_timer);
+	del_timer(&hdev->cmd_listener_timer);
 
 	destroy_workqueue(hdev->workqueue);
 
net/bluetooth/mgmt.c +205 -0

223 lines not on this page · raw message

Signature · 1 line
1.7.4.1