aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/smp.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-08-11 15:06:40 -0400
committerMarcel Holtmann <marcel@holtmann.org>2014-08-14 02:49:23 -0400
commitb68fda6848ebef3499905500971d40b84faa8319 (patch)
tree8ce078288beb4135d0d9b172443cae67e38d6818 /net/bluetooth/smp.c
parent8ae9b9845b3252216cf5d2e033e5cca41bae48ef (diff)
Bluetooth: Add SMP-internal timeout callback
This patch adds an SMP-internal timeout callback to remove the depenency on (the soon to be removed) l2cap_conn->security_timer. The behavior is the same as with l2cap_conn->security_timer except that the new l2cap_conn_shutdown() public function is used instead of the L2CAP core internal l2cap_conn_del(). Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth/smp.c')
-rw-r--r--net/bluetooth/smp.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 5103dc739a17..7ab5f52955cb 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -44,7 +44,9 @@ enum {
44}; 44};
45 45
46struct smp_chan { 46struct smp_chan {
47 struct l2cap_conn *conn; 47 struct l2cap_conn *conn;
48 struct delayed_work security_timer;
49
48 u8 preq[7]; /* SMP Pairing Request */ 50 u8 preq[7]; /* SMP Pairing Request */
49 u8 prsp[7]; /* SMP Pairing Response */ 51 u8 prsp[7]; /* SMP Pairing Response */
50 u8 prnd[16]; /* SMP Pairing Random (local) */ 52 u8 prnd[16]; /* SMP Pairing Random (local) */
@@ -251,6 +253,7 @@ static int smp_s1(struct smp_chan *smp, u8 k[16], u8 r1[16], u8 r2[16],
251static void smp_send_cmd(struct l2cap_conn *conn, u8 code, u16 len, void *data) 253static void smp_send_cmd(struct l2cap_conn *conn, u8 code, u16 len, void *data)
252{ 254{
253 struct l2cap_chan *chan = conn->smp; 255 struct l2cap_chan *chan = conn->smp;
256 struct smp_chan *smp;
254 struct kvec iv[2]; 257 struct kvec iv[2];
255 struct msghdr msg; 258 struct msghdr msg;
256 259
@@ -272,8 +275,14 @@ static void smp_send_cmd(struct l2cap_conn *conn, u8 code, u16 len, void *data)
272 275
273 l2cap_chan_send(chan, &msg, 1 + len); 276 l2cap_chan_send(chan, &msg, 1 + len);
274 277
275 cancel_delayed_work_sync(&conn->security_timer); 278 if (!chan->data)
276 schedule_delayed_work(&conn->security_timer, SMP_TIMEOUT); 279 return;
280
281 smp = chan->data;
282
283 cancel_delayed_work_sync(&smp->security_timer);
284 if (test_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags))
285 schedule_delayed_work(&smp->security_timer, SMP_TIMEOUT);
277} 286}
278 287
279static __u8 authreq_to_seclevel(__u8 authreq) 288static __u8 authreq_to_seclevel(__u8 authreq)
@@ -359,6 +368,8 @@ static u8 check_enc_key_size(struct l2cap_conn *conn, __u8 max_key_size)
359static void smp_failure(struct l2cap_conn *conn, u8 reason) 368static void smp_failure(struct l2cap_conn *conn, u8 reason)
360{ 369{
361 struct hci_conn *hcon = conn->hcon; 370 struct hci_conn *hcon = conn->hcon;
371 struct l2cap_chan *chan = conn->smp;
372 struct smp_chan *smp;
362 373
363 if (reason) 374 if (reason)
364 smp_send_cmd(conn, SMP_CMD_PAIRING_FAIL, sizeof(reason), 375 smp_send_cmd(conn, SMP_CMD_PAIRING_FAIL, sizeof(reason),
@@ -368,7 +379,12 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason)
368 mgmt_auth_failed(hcon->hdev, &hcon->dst, hcon->type, hcon->dst_type, 379 mgmt_auth_failed(hcon->hdev, &hcon->dst, hcon->type, hcon->dst_type,
369 HCI_ERROR_AUTH_FAILURE); 380 HCI_ERROR_AUTH_FAILURE);
370 381
371 cancel_delayed_work_sync(&conn->security_timer); 382 if (!chan->data)
383 return;
384
385 smp = chan->data;
386
387 cancel_delayed_work_sync(&smp->security_timer);
372 388
373 if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags)) 389 if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags))
374 smp_chan_destroy(conn); 390 smp_chan_destroy(conn);
@@ -749,7 +765,7 @@ static int smp_distribute_keys(struct l2cap_conn *conn)
749 return 0; 765 return 0;
750 766
751 clear_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags); 767 clear_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags);
752 cancel_delayed_work_sync(&conn->security_timer); 768 cancel_delayed_work_sync(&smp->security_timer);
753 set_bit(SMP_FLAG_COMPLETE, &smp->flags); 769 set_bit(SMP_FLAG_COMPLETE, &smp->flags);
754 smp_notify_keys(conn); 770 smp_notify_keys(conn);
755 771
@@ -758,6 +774,17 @@ static int smp_distribute_keys(struct l2cap_conn *conn)
758 return 0; 774 return 0;
759} 775}
760 776
777static void smp_timeout(struct work_struct *work)
778{
779 struct smp_chan *smp = container_of(work, struct smp_chan,
780 security_timer.work);
781 struct l2cap_conn *conn = smp->conn;
782
783 BT_DBG("conn %p", conn);
784
785 l2cap_conn_shutdown(conn, ETIMEDOUT);
786}
787
761static struct smp_chan *smp_chan_create(struct l2cap_conn *conn) 788static struct smp_chan *smp_chan_create(struct l2cap_conn *conn)
762{ 789{
763 struct l2cap_chan *chan = conn->smp; 790 struct l2cap_chan *chan = conn->smp;
@@ -780,6 +807,8 @@ static struct smp_chan *smp_chan_create(struct l2cap_conn *conn)
780 smp->conn = conn; 807 smp->conn = conn;
781 chan->data = smp; 808 chan->data = smp;
782 809
810 INIT_DELAYED_WORK(&smp->security_timer, smp_timeout);
811
783 hci_conn_hold(conn->hcon); 812 hci_conn_hold(conn->hcon);
784 813
785 return smp; 814 return smp;
@@ -1479,11 +1508,12 @@ done:
1479static void smp_teardown_cb(struct l2cap_chan *chan, int err) 1508static void smp_teardown_cb(struct l2cap_chan *chan, int err)
1480{ 1509{
1481 struct l2cap_conn *conn = chan->conn; 1510 struct l2cap_conn *conn = chan->conn;
1511 struct smp_chan *smp = chan->data;
1482 1512
1483 BT_DBG("chan %p", chan); 1513 BT_DBG("chan %p", chan);
1484 1514
1485 if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) { 1515 if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) {
1486 cancel_delayed_work_sync(&conn->security_timer); 1516 cancel_delayed_work_sync(&smp->security_timer);
1487 smp_chan_destroy(conn); 1517 smp_chan_destroy(conn);
1488 } 1518 }
1489 1519
@@ -1493,6 +1523,7 @@ static void smp_teardown_cb(struct l2cap_chan *chan, int err)
1493 1523
1494static void smp_resume_cb(struct l2cap_chan *chan) 1524static void smp_resume_cb(struct l2cap_chan *chan)
1495{ 1525{
1526 struct smp_chan *smp = chan->data;
1496 struct l2cap_conn *conn = chan->conn; 1527 struct l2cap_conn *conn = chan->conn;
1497 struct hci_conn *hcon = conn->hcon; 1528 struct hci_conn *hcon = conn->hcon;
1498 1529
@@ -1500,7 +1531,9 @@ static void smp_resume_cb(struct l2cap_chan *chan)
1500 1531
1501 if (test_bit(HCI_CONN_ENCRYPT, &hcon->flags)) 1532 if (test_bit(HCI_CONN_ENCRYPT, &hcon->flags))
1502 smp_distribute_keys(conn); 1533 smp_distribute_keys(conn);
1503 cancel_delayed_work(&conn->security_timer); 1534
1535 if (smp)
1536 cancel_delayed_work(&smp->security_timer);
1504} 1537}
1505 1538
1506static void smp_ready_cb(struct l2cap_chan *chan) 1539static void smp_ready_cb(struct l2cap_chan *chan)
@@ -1521,9 +1554,10 @@ static int smp_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb)
1521 1554
1522 err = smp_sig_channel(chan, skb); 1555 err = smp_sig_channel(chan, skb);
1523 if (err) { 1556 if (err) {
1524 struct l2cap_conn *conn = chan->conn; 1557 struct smp_chan *smp = chan->data;
1525 1558
1526 cancel_delayed_work_sync(&conn->security_timer); 1559 if (smp)
1560 cancel_delayed_work_sync(&smp->security_timer);
1527 1561
1528 l2cap_conn_shutdown(chan->conn, -err); 1562 l2cap_conn_shutdown(chan->conn, -err);
1529 } 1563 }