Skip to content

Commit 5a134fa

Browse files
Andrzej Kaczmarekholtmann
authored andcommitted
Bluetooth: Store TX power level for connection
This patch adds support to store local TX power level for connection when reply for HCI_Read_Transmit_Power_Level is received. Signed-off-by: Andrzej Kaczmarek <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent b75cf9c commit 5a134fa

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

include/net/bluetooth/hci.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,17 @@ struct hci_cp_write_page_scan_activity {
10541054
__le16 window;
10551055
} __packed;
10561056

1057+
#define HCI_OP_READ_TX_POWER 0x0c2d
1058+
struct hci_cp_read_tx_power {
1059+
__le16 handle;
1060+
__u8 type;
1061+
} __packed;
1062+
struct hci_rp_read_tx_power {
1063+
__u8 status;
1064+
__le16 handle;
1065+
__s8 tx_power;
1066+
} __packed;
1067+
10571068
#define HCI_OP_READ_PAGE_SCAN_TYPE 0x0c46
10581069
struct hci_rp_read_page_scan_type {
10591070
__u8 status;

include/net/bluetooth/hci_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ struct hci_conn {
375375
__u16 le_conn_min_interval;
376376
__u16 le_conn_max_interval;
377377
__s8 rssi;
378+
__s8 tx_power;
378379
unsigned long flags;
379380

380381
__u8 remote_cap;

net/bluetooth/hci_conn.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
407407
conn->io_capability = hdev->io_capability;
408408
conn->remote_auth = 0xff;
409409
conn->key_type = 0xff;
410+
conn->tx_power = HCI_TX_POWER_INVALID;
410411

411412
set_bit(HCI_CONN_POWER_SAVE, &conn->flags);
412413
conn->disc_timeout = HCI_DISCONN_TIMEOUT;

net/bluetooth/hci_event.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,30 @@ static void hci_cc_read_rssi(struct hci_dev *hdev, struct sk_buff *skb)
12641264
hci_dev_unlock(hdev);
12651265
}
12661266

1267+
static void hci_cc_read_tx_power(struct hci_dev *hdev, struct sk_buff *skb)
1268+
{
1269+
struct hci_cp_read_tx_power *sent;
1270+
struct hci_rp_read_tx_power *rp = (void *) skb->data;
1271+
struct hci_conn *conn;
1272+
1273+
BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1274+
1275+
if (rp->status)
1276+
return;
1277+
1278+
sent = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER);
1279+
if (!sent)
1280+
return;
1281+
1282+
hci_dev_lock(hdev);
1283+
1284+
conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
1285+
if (conn && sent->type == 0x00)
1286+
conn->tx_power = rp->tx_power;
1287+
1288+
hci_dev_unlock(hdev);
1289+
}
1290+
12671291
static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
12681292
{
12691293
BT_DBG("%s status 0x%2.2x", hdev->name, status);
@@ -2660,6 +2684,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
26602684
hci_cc_read_rssi(hdev, skb);
26612685
break;
26622686

2687+
case HCI_OP_READ_TX_POWER:
2688+
hci_cc_read_tx_power(hdev, skb);
2689+
break;
2690+
26632691
default:
26642692
BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode);
26652693
break;

0 commit comments

Comments
 (0)