Skip to content

Commit 302975c

Browse files
Spoorthi Ravishankar Koppadholtmann
authored andcommitted
Bluetooth: Add support for LE ping feature
Changes made to add HCI Write Authenticated Payload timeout command for LE Ping feature. As per the Core Specification 5.0 Volume 2 Part E Section 7.3.94, the following code changes implements HCI Write Authenticated Payload timeout command for LE Ping feature. Signed-off-by: Spoorthi Ravishankar Koppad <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent 28261da commit 302975c

File tree

6 files changed

+131
-0
lines changed

6 files changed

+131
-0
lines changed

include/net/bluetooth/hci.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,26 @@ struct hci_cp_write_sc_support {
11431143
__u8 support;
11441144
} __packed;
11451145

1146+
#define HCI_OP_READ_AUTH_PAYLOAD_TO 0x0c7b
1147+
struct hci_cp_read_auth_payload_to {
1148+
__le16 handle;
1149+
} __packed;
1150+
struct hci_rp_read_auth_payload_to {
1151+
__u8 status;
1152+
__le16 handle;
1153+
__le16 timeout;
1154+
} __packed;
1155+
1156+
#define HCI_OP_WRITE_AUTH_PAYLOAD_TO 0x0c7c
1157+
struct hci_cp_write_auth_payload_to {
1158+
__le16 handle;
1159+
__le16 timeout;
1160+
} __packed;
1161+
struct hci_rp_write_auth_payload_to {
1162+
__u8 status;
1163+
__le16 handle;
1164+
} __packed;
1165+
11461166
#define HCI_OP_READ_LOCAL_OOB_EXT_DATA 0x0c7d
11471167
struct hci_rp_read_local_oob_ext_data {
11481168
__u8 status;

include/net/bluetooth/hci_core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ struct adv_info {
199199
/* Default min/max age of connection information (1s/3s) */
200200
#define DEFAULT_CONN_INFO_MIN_AGE 1000
201201
#define DEFAULT_CONN_INFO_MAX_AGE 3000
202+
/* Default authenticated payload timeout 30s */
203+
#define DEFAULT_AUTH_PAYLOAD_TIMEOUT 0x0bb8
202204

203205
struct amp_assoc {
204206
__u16 len;
@@ -275,6 +277,7 @@ struct hci_dev {
275277
__u16 discov_interleaved_timeout;
276278
__u16 conn_info_min_age;
277279
__u16 conn_info_max_age;
280+
__u16 auth_payload_timeout;
278281
__u8 ssp_debug_mode;
279282
__u8 hw_error_code;
280283
__u32 clock;
@@ -481,6 +484,7 @@ struct hci_conn {
481484
__u16 disc_timeout;
482485
__u16 conn_timeout;
483486
__u16 setting;
487+
__u16 auth_payload_timeout;
484488
__u16 le_conn_min_interval;
485489
__u16 le_conn_max_interval;
486490
__u16 le_conn_interval;

net/bluetooth/hci_conn.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
520520
set_bit(HCI_CONN_POWER_SAVE, &conn->flags);
521521
conn->disc_timeout = HCI_DISCONN_TIMEOUT;
522522

523+
/* Set Default Authenticated payload timeout to 30s */
524+
conn->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT;
525+
523526
if (conn->role == HCI_ROLE_MASTER)
524527
conn->out = true;
525528

net/bluetooth/hci_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,6 +3200,7 @@ struct hci_dev *hci_alloc_dev(void)
32003200
hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT;
32013201
hdev->conn_info_min_age = DEFAULT_CONN_INFO_MIN_AGE;
32023202
hdev->conn_info_max_age = DEFAULT_CONN_INFO_MAX_AGE;
3203+
hdev->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT;
32033204

32043205
mutex_init(&hdev->lock);
32053206
mutex_init(&hdev->req_lock);

net/bluetooth/hci_debugfs.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,35 @@ static int adv_max_interval_get(void *data, u64 *val)
941941
DEFINE_SIMPLE_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get,
942942
adv_max_interval_set, "%llu\n");
943943

944+
static int auth_payload_timeout_set(void *data, u64 val)
945+
{
946+
struct hci_dev *hdev = data;
947+
948+
if (val < 0x0001 || val > 0xffff)
949+
return -EINVAL;
950+
951+
hci_dev_lock(hdev);
952+
hdev->auth_payload_timeout = val;
953+
hci_dev_unlock(hdev);
954+
955+
return 0;
956+
}
957+
958+
static int auth_payload_timeout_get(void *data, u64 *val)
959+
{
960+
struct hci_dev *hdev = data;
961+
962+
hci_dev_lock(hdev);
963+
*val = hdev->auth_payload_timeout;
964+
hci_dev_unlock(hdev);
965+
966+
return 0;
967+
}
968+
969+
DEFINE_SIMPLE_ATTRIBUTE(auth_payload_timeout_fops,
970+
auth_payload_timeout_get,
971+
auth_payload_timeout_set, "%llu\n");
972+
944973
DEFINE_QUIRK_ATTRIBUTE(quirk_strict_duplicate_filter,
945974
HCI_QUIRK_STRICT_DUPLICATE_FILTER);
946975
DEFINE_QUIRK_ATTRIBUTE(quirk_simultaneous_discovery,
@@ -994,6 +1023,8 @@ void hci_debugfs_create_le(struct hci_dev *hdev)
9941023
&adv_max_interval_fops);
9951024
debugfs_create_u16("discov_interleaved_timeout", 0644, hdev->debugfs,
9961025
&hdev->discov_interleaved_timeout);
1026+
debugfs_create_file("auth_payload_timeout", 0644, hdev->debugfs, hdev,
1027+
&auth_payload_timeout_fops);
9971028

9981029
debugfs_create_file("quirk_strict_duplicate_filter", 0644,
9991030
hdev->debugfs, hdev,

net/bluetooth/hci_event.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,51 @@ static void hci_cc_read_local_commands(struct hci_dev *hdev,
579579
memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
580580
}
581581

582+
static void hci_cc_read_auth_payload_timeout(struct hci_dev *hdev,
583+
struct sk_buff *skb)
584+
{
585+
struct hci_rp_read_auth_payload_to *rp = (void *)skb->data;
586+
struct hci_conn *conn;
587+
588+
BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
589+
590+
if (rp->status)
591+
return;
592+
593+
hci_dev_lock(hdev);
594+
595+
conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
596+
if (conn)
597+
conn->auth_payload_timeout = __le16_to_cpu(rp->timeout);
598+
599+
hci_dev_unlock(hdev);
600+
}
601+
602+
static void hci_cc_write_auth_payload_timeout(struct hci_dev *hdev,
603+
struct sk_buff *skb)
604+
{
605+
struct hci_rp_write_auth_payload_to *rp = (void *)skb->data;
606+
struct hci_conn *conn;
607+
void *sent;
608+
609+
BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
610+
611+
if (rp->status)
612+
return;
613+
614+
sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO);
615+
if (!sent)
616+
return;
617+
618+
hci_dev_lock(hdev);
619+
620+
conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
621+
if (conn)
622+
conn->auth_payload_timeout = get_unaligned_le16(sent + 2);
623+
624+
hci_dev_unlock(hdev);
625+
}
626+
582627
static void hci_cc_read_local_features(struct hci_dev *hdev,
583628
struct sk_buff *skb)
584629
{
@@ -2975,6 +3020,25 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
29753020
goto unlock;
29763021
}
29773022

3023+
/* Set the default Authenticated Payload Timeout after
3024+
* an LE Link is established. As per Core Spec v5.0, Vol 2, Part B
3025+
* Section 3.3, the HCI command WRITE_AUTH_PAYLOAD_TIMEOUT should be
3026+
* sent when the link is active and Encryption is enabled, the conn
3027+
* type can be either LE or ACL and controller must support LMP Ping.
3028+
* Ensure for AES-CCM encryption as well.
3029+
*/
3030+
if (test_bit(HCI_CONN_ENCRYPT, &conn->flags) &&
3031+
test_bit(HCI_CONN_AES_CCM, &conn->flags) &&
3032+
((conn->type == ACL_LINK && lmp_ping_capable(hdev)) ||
3033+
(conn->type == LE_LINK && (hdev->le_features[0] & HCI_LE_PING)))) {
3034+
struct hci_cp_write_auth_payload_to cp;
3035+
3036+
cp.handle = cpu_to_le16(conn->handle);
3037+
cp.timeout = cpu_to_le16(hdev->auth_payload_timeout);
3038+
hci_send_cmd(conn->hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO,
3039+
sizeof(cp), &cp);
3040+
}
3041+
29783042
notify:
29793043
if (conn->state == BT_CONFIG) {
29803044
if (!ev->status)
@@ -3170,6 +3234,14 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
31703234
hci_cc_write_sc_support(hdev, skb);
31713235
break;
31723236

3237+
case HCI_OP_READ_AUTH_PAYLOAD_TO:
3238+
hci_cc_read_auth_payload_timeout(hdev, skb);
3239+
break;
3240+
3241+
case HCI_OP_WRITE_AUTH_PAYLOAD_TO:
3242+
hci_cc_write_auth_payload_timeout(hdev, skb);
3243+
break;
3244+
31733245
case HCI_OP_READ_LOCAL_VERSION:
31743246
hci_cc_read_local_version(hdev, skb);
31753247
break;

0 commit comments

Comments
 (0)