Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1 | /* |
| 2 | BlueZ - Bluetooth protocol stack for Linux |
| 3 | Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License version 2 as |
| 7 | published by the Free Software Foundation; |
| 8 | |
| 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 10 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 11 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. |
| 12 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY |
| 13 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES |
| 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 | |
| 18 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
| 19 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS |
| 20 | SOFTWARE IS DISCLAIMED. |
| 21 | */ |
| 22 | |
Gustavo Padovan | 8c520a5 | 2012-05-23 04:04:22 -0300 | [diff] [blame] | 23 | #include <linux/crypto.h> |
| 24 | #include <linux/scatterlist.h> |
| 25 | #include <crypto/b128ops.h> |
| 26 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 27 | #include <net/bluetooth/bluetooth.h> |
| 28 | #include <net/bluetooth/hci_core.h> |
| 29 | #include <net/bluetooth/l2cap.h> |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 30 | #include <net/bluetooth/mgmt.h> |
Marcel Holtmann | ac4b723 | 2013-10-10 14:54:16 -0700 | [diff] [blame] | 31 | |
| 32 | #include "smp.h" |
Anderson Briglia | d22ef0b | 2011-06-09 18:50:44 -0300 | [diff] [blame] | 33 | |
Marcel Holtmann | 17b02e6 | 2012-03-01 14:32:37 -0800 | [diff] [blame] | 34 | #define SMP_TIMEOUT msecs_to_jiffies(30000) |
Vinicius Costa Gomes | 5d3de7d | 2011-06-14 13:37:41 -0300 | [diff] [blame] | 35 | |
Johan Hedberg | 065a13e | 2012-10-11 16:26:06 +0200 | [diff] [blame] | 36 | #define AUTH_REQ_MASK 0x07 |
| 37 | |
Anderson Briglia | d22ef0b | 2011-06-09 18:50:44 -0300 | [diff] [blame] | 38 | static inline void swap128(u8 src[16], u8 dst[16]) |
| 39 | { |
| 40 | int i; |
| 41 | for (i = 0; i < 16; i++) |
| 42 | dst[15 - i] = src[i]; |
| 43 | } |
| 44 | |
| 45 | static inline void swap56(u8 src[7], u8 dst[7]) |
| 46 | { |
| 47 | int i; |
| 48 | for (i = 0; i < 7; i++) |
| 49 | dst[6 - i] = src[i]; |
| 50 | } |
| 51 | |
| 52 | static int smp_e(struct crypto_blkcipher *tfm, const u8 *k, u8 *r) |
| 53 | { |
| 54 | struct blkcipher_desc desc; |
| 55 | struct scatterlist sg; |
Johan Hedberg | 201a592 | 2013-12-02 10:49:04 +0200 | [diff] [blame] | 56 | int err; |
Anderson Briglia | d22ef0b | 2011-06-09 18:50:44 -0300 | [diff] [blame] | 57 | |
| 58 | if (tfm == NULL) { |
| 59 | BT_ERR("tfm %p", tfm); |
| 60 | return -EINVAL; |
| 61 | } |
| 62 | |
| 63 | desc.tfm = tfm; |
| 64 | desc.flags = 0; |
| 65 | |
| 66 | err = crypto_blkcipher_setkey(tfm, k, 16); |
| 67 | if (err) { |
| 68 | BT_ERR("cipher setkey failed: %d", err); |
| 69 | return err; |
| 70 | } |
| 71 | |
| 72 | sg_init_one(&sg, r, 16); |
| 73 | |
Anderson Briglia | d22ef0b | 2011-06-09 18:50:44 -0300 | [diff] [blame] | 74 | err = crypto_blkcipher_encrypt(&desc, &sg, &sg, 16); |
| 75 | if (err) |
| 76 | BT_ERR("Encrypt data error %d", err); |
| 77 | |
| 78 | return err; |
| 79 | } |
| 80 | |
Johan Hedberg | 6047805 | 2014-02-18 10:19:31 +0200 | [diff] [blame] | 81 | static int smp_ah(struct crypto_blkcipher *tfm, u8 irk[16], u8 r[3], u8 res[3]) |
| 82 | { |
| 83 | u8 _res[16], k[16]; |
| 84 | int err; |
| 85 | |
| 86 | /* r' = padding || r */ |
| 87 | memset(_res, 0, 13); |
| 88 | _res[13] = r[2]; |
| 89 | _res[14] = r[1]; |
| 90 | _res[15] = r[0]; |
| 91 | |
| 92 | swap128(irk, k); |
| 93 | err = smp_e(tfm, k, _res); |
| 94 | if (err) { |
| 95 | BT_ERR("Encrypt error"); |
| 96 | return err; |
| 97 | } |
| 98 | |
| 99 | /* The output of the random address function ah is: |
| 100 | * ah(h, r) = e(k, r') mod 2^24 |
| 101 | * The output of the security function e is then truncated to 24 bits |
| 102 | * by taking the least significant 24 bits of the output of e as the |
| 103 | * result of ah. |
| 104 | */ |
| 105 | res[0] = _res[15]; |
| 106 | res[1] = _res[14]; |
| 107 | res[2] = _res[13]; |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | bool smp_irk_matches(struct crypto_blkcipher *tfm, u8 irk[16], |
| 113 | bdaddr_t *bdaddr) |
| 114 | { |
| 115 | u8 hash[3]; |
| 116 | int err; |
| 117 | |
| 118 | BT_DBG("RPA %pMR IRK %*phN", bdaddr, 16, irk); |
| 119 | |
| 120 | err = smp_ah(tfm, irk, &bdaddr->b[3], hash); |
| 121 | if (err) |
| 122 | return false; |
| 123 | |
| 124 | return !memcmp(bdaddr->b, hash, 3); |
| 125 | } |
| 126 | |
Anderson Briglia | d22ef0b | 2011-06-09 18:50:44 -0300 | [diff] [blame] | 127 | static int smp_c1(struct crypto_blkcipher *tfm, u8 k[16], u8 r[16], |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 128 | u8 preq[7], u8 pres[7], u8 _iat, bdaddr_t *ia, |
| 129 | u8 _rat, bdaddr_t *ra, u8 res[16]) |
Anderson Briglia | d22ef0b | 2011-06-09 18:50:44 -0300 | [diff] [blame] | 130 | { |
| 131 | u8 p1[16], p2[16]; |
| 132 | int err; |
| 133 | |
| 134 | memset(p1, 0, 16); |
| 135 | |
| 136 | /* p1 = pres || preq || _rat || _iat */ |
| 137 | swap56(pres, p1); |
| 138 | swap56(preq, p1 + 7); |
| 139 | p1[14] = _rat; |
| 140 | p1[15] = _iat; |
| 141 | |
| 142 | memset(p2, 0, 16); |
| 143 | |
| 144 | /* p2 = padding || ia || ra */ |
| 145 | baswap((bdaddr_t *) (p2 + 4), ia); |
| 146 | baswap((bdaddr_t *) (p2 + 10), ra); |
| 147 | |
| 148 | /* res = r XOR p1 */ |
| 149 | u128_xor((u128 *) res, (u128 *) r, (u128 *) p1); |
| 150 | |
| 151 | /* res = e(k, res) */ |
| 152 | err = smp_e(tfm, k, res); |
| 153 | if (err) { |
| 154 | BT_ERR("Encrypt data error"); |
| 155 | return err; |
| 156 | } |
| 157 | |
| 158 | /* res = res XOR p2 */ |
| 159 | u128_xor((u128 *) res, (u128 *) res, (u128 *) p2); |
| 160 | |
| 161 | /* res = e(k, res) */ |
| 162 | err = smp_e(tfm, k, res); |
| 163 | if (err) |
| 164 | BT_ERR("Encrypt data error"); |
| 165 | |
| 166 | return err; |
| 167 | } |
| 168 | |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 169 | static int smp_s1(struct crypto_blkcipher *tfm, u8 k[16], u8 r1[16], |
| 170 | u8 r2[16], u8 _r[16]) |
Anderson Briglia | d22ef0b | 2011-06-09 18:50:44 -0300 | [diff] [blame] | 171 | { |
| 172 | int err; |
| 173 | |
| 174 | /* Just least significant octets from r1 and r2 are considered */ |
| 175 | memcpy(_r, r1 + 8, 8); |
| 176 | memcpy(_r + 8, r2 + 8, 8); |
| 177 | |
| 178 | err = smp_e(tfm, k, _r); |
| 179 | if (err) |
| 180 | BT_ERR("Encrypt data error"); |
| 181 | |
| 182 | return err; |
| 183 | } |
| 184 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 185 | static struct sk_buff *smp_build_cmd(struct l2cap_conn *conn, u8 code, |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 186 | u16 dlen, void *data) |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 187 | { |
| 188 | struct sk_buff *skb; |
| 189 | struct l2cap_hdr *lh; |
| 190 | int len; |
| 191 | |
| 192 | len = L2CAP_HDR_SIZE + sizeof(code) + dlen; |
| 193 | |
| 194 | if (len > conn->mtu) |
| 195 | return NULL; |
| 196 | |
| 197 | skb = bt_skb_alloc(len, GFP_ATOMIC); |
| 198 | if (!skb) |
| 199 | return NULL; |
| 200 | |
| 201 | lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE); |
| 202 | lh->len = cpu_to_le16(sizeof(code) + dlen); |
Syam Sidhardhan | d8aece2 | 2012-10-10 22:09:28 +0530 | [diff] [blame] | 203 | lh->cid = __constant_cpu_to_le16(L2CAP_CID_SMP); |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 204 | |
| 205 | memcpy(skb_put(skb, sizeof(code)), &code, sizeof(code)); |
| 206 | |
| 207 | memcpy(skb_put(skb, dlen), data, dlen); |
| 208 | |
| 209 | return skb; |
| 210 | } |
| 211 | |
| 212 | static void smp_send_cmd(struct l2cap_conn *conn, u8 code, u16 len, void *data) |
| 213 | { |
| 214 | struct sk_buff *skb = smp_build_cmd(conn, code, len, data); |
| 215 | |
| 216 | BT_DBG("code 0x%2.2x", code); |
| 217 | |
| 218 | if (!skb) |
| 219 | return; |
| 220 | |
Luiz Augusto von Dentz | 73d80de | 2011-11-02 15:52:01 +0200 | [diff] [blame] | 221 | skb->priority = HCI_PRIO_MAX; |
| 222 | hci_send_acl(conn->hchan, skb, 0); |
Vinicius Costa Gomes | e2dcd11 | 2011-08-19 21:06:50 -0300 | [diff] [blame] | 223 | |
Gustavo F. Padovan | 6c9d42a | 2011-12-20 10:57:27 -0200 | [diff] [blame] | 224 | cancel_delayed_work_sync(&conn->security_timer); |
Marcel Holtmann | 17b02e6 | 2012-03-01 14:32:37 -0800 | [diff] [blame] | 225 | schedule_delayed_work(&conn->security_timer, SMP_TIMEOUT); |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 226 | } |
| 227 | |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 228 | static __u8 authreq_to_seclevel(__u8 authreq) |
| 229 | { |
| 230 | if (authreq & SMP_AUTH_MITM) |
| 231 | return BT_SECURITY_HIGH; |
| 232 | else |
| 233 | return BT_SECURITY_MEDIUM; |
| 234 | } |
| 235 | |
| 236 | static __u8 seclevel_to_authreq(__u8 sec_level) |
| 237 | { |
| 238 | switch (sec_level) { |
| 239 | case BT_SECURITY_HIGH: |
| 240 | return SMP_AUTH_MITM | SMP_AUTH_BONDING; |
| 241 | case BT_SECURITY_MEDIUM: |
| 242 | return SMP_AUTH_BONDING; |
| 243 | default: |
| 244 | return SMP_AUTH_NONE; |
| 245 | } |
| 246 | } |
| 247 | |
Vinicius Costa Gomes | b8e66ea | 2011-06-09 18:50:52 -0300 | [diff] [blame] | 248 | static void build_pairing_cmd(struct l2cap_conn *conn, |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 249 | struct smp_cmd_pairing *req, |
| 250 | struct smp_cmd_pairing *rsp, __u8 authreq) |
Vinicius Costa Gomes | b8e66ea | 2011-06-09 18:50:52 -0300 | [diff] [blame] | 251 | { |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 252 | struct smp_chan *smp = conn->smp_chan; |
| 253 | struct hci_conn *hcon = conn->hcon; |
| 254 | struct hci_dev *hdev = hcon->hdev; |
| 255 | u8 local_dist = 0, remote_dist = 0; |
Vinicius Costa Gomes | 54790f7 | 2011-07-07 18:59:38 -0300 | [diff] [blame] | 256 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 257 | if (test_bit(HCI_PAIRABLE, &conn->hcon->hdev->dev_flags)) { |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 258 | local_dist = SMP_DIST_ENC_KEY; |
| 259 | remote_dist = SMP_DIST_ENC_KEY; |
Vinicius Costa Gomes | 54790f7 | 2011-07-07 18:59:38 -0300 | [diff] [blame] | 260 | authreq |= SMP_AUTH_BONDING; |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 261 | } else { |
| 262 | authreq &= ~SMP_AUTH_BONDING; |
Vinicius Costa Gomes | 54790f7 | 2011-07-07 18:59:38 -0300 | [diff] [blame] | 263 | } |
| 264 | |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 265 | if (test_bit(HCI_RPA_RESOLVING, &hdev->dev_flags)) |
| 266 | remote_dist |= SMP_DIST_ID_KEY; |
| 267 | |
Vinicius Costa Gomes | 54790f7 | 2011-07-07 18:59:38 -0300 | [diff] [blame] | 268 | if (rsp == NULL) { |
| 269 | req->io_capability = conn->hcon->io_capability; |
| 270 | req->oob_flag = SMP_OOB_NOT_PRESENT; |
| 271 | req->max_key_size = SMP_MAX_ENC_KEY_SIZE; |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 272 | req->init_key_dist = local_dist; |
| 273 | req->resp_key_dist = remote_dist; |
Johan Hedberg | 065a13e | 2012-10-11 16:26:06 +0200 | [diff] [blame] | 274 | req->auth_req = (authreq & AUTH_REQ_MASK); |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 275 | |
| 276 | smp->remote_key_dist = remote_dist; |
Vinicius Costa Gomes | 54790f7 | 2011-07-07 18:59:38 -0300 | [diff] [blame] | 277 | return; |
| 278 | } |
| 279 | |
| 280 | rsp->io_capability = conn->hcon->io_capability; |
| 281 | rsp->oob_flag = SMP_OOB_NOT_PRESENT; |
| 282 | rsp->max_key_size = SMP_MAX_ENC_KEY_SIZE; |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 283 | rsp->init_key_dist = req->init_key_dist & remote_dist; |
| 284 | rsp->resp_key_dist = req->resp_key_dist & local_dist; |
Johan Hedberg | 065a13e | 2012-10-11 16:26:06 +0200 | [diff] [blame] | 285 | rsp->auth_req = (authreq & AUTH_REQ_MASK); |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 286 | |
| 287 | smp->remote_key_dist = rsp->init_key_dist; |
Vinicius Costa Gomes | b8e66ea | 2011-06-09 18:50:52 -0300 | [diff] [blame] | 288 | } |
| 289 | |
Vinicius Costa Gomes | 3158c50 | 2011-06-14 13:37:42 -0300 | [diff] [blame] | 290 | static u8 check_enc_key_size(struct l2cap_conn *conn, __u8 max_key_size) |
| 291 | { |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 292 | struct smp_chan *smp = conn->smp_chan; |
| 293 | |
Vinicius Costa Gomes | 3158c50 | 2011-06-14 13:37:42 -0300 | [diff] [blame] | 294 | if ((max_key_size > SMP_MAX_ENC_KEY_SIZE) || |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 295 | (max_key_size < SMP_MIN_ENC_KEY_SIZE)) |
Vinicius Costa Gomes | 3158c50 | 2011-06-14 13:37:42 -0300 | [diff] [blame] | 296 | return SMP_ENC_KEY_SIZE; |
| 297 | |
Vinicius Costa Gomes | f7aa611 | 2012-01-30 19:29:12 -0300 | [diff] [blame] | 298 | smp->enc_key_size = max_key_size; |
Vinicius Costa Gomes | 3158c50 | 2011-06-14 13:37:42 -0300 | [diff] [blame] | 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
Johan Hedberg | 84794e1 | 2013-11-06 11:24:57 +0200 | [diff] [blame] | 303 | static void smp_failure(struct l2cap_conn *conn, u8 reason) |
Brian Gix | 4f957a7 | 2011-11-23 08:28:36 -0800 | [diff] [blame] | 304 | { |
Johan Hedberg | bab73cb | 2012-02-09 16:07:29 +0200 | [diff] [blame] | 305 | struct hci_conn *hcon = conn->hcon; |
| 306 | |
Johan Hedberg | 84794e1 | 2013-11-06 11:24:57 +0200 | [diff] [blame] | 307 | if (reason) |
Brian Gix | 4f957a7 | 2011-11-23 08:28:36 -0800 | [diff] [blame] | 308 | smp_send_cmd(conn, SMP_CMD_PAIRING_FAIL, sizeof(reason), |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 309 | &reason); |
Brian Gix | 4f957a7 | 2011-11-23 08:28:36 -0800 | [diff] [blame] | 310 | |
Marcel Holtmann | ce39fb4 | 2013-10-13 02:23:39 -0700 | [diff] [blame] | 311 | clear_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags); |
| 312 | mgmt_auth_failed(hcon->hdev, &hcon->dst, hcon->type, hcon->dst_type, |
| 313 | HCI_ERROR_AUTH_FAILURE); |
Vinicius Costa Gomes | f1c09c0 | 2012-02-01 18:27:56 -0300 | [diff] [blame] | 314 | |
Andre Guedes | 61a0cfb | 2012-08-01 20:34:15 -0300 | [diff] [blame] | 315 | cancel_delayed_work_sync(&conn->security_timer); |
| 316 | |
Marcel Holtmann | ce39fb4 | 2013-10-13 02:23:39 -0700 | [diff] [blame] | 317 | if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags)) |
Vinicius Costa Gomes | f1c09c0 | 2012-02-01 18:27:56 -0300 | [diff] [blame] | 318 | smp_chan_destroy(conn); |
Brian Gix | 4f957a7 | 2011-11-23 08:28:36 -0800 | [diff] [blame] | 319 | } |
| 320 | |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 321 | #define JUST_WORKS 0x00 |
| 322 | #define JUST_CFM 0x01 |
| 323 | #define REQ_PASSKEY 0x02 |
| 324 | #define CFM_PASSKEY 0x03 |
| 325 | #define REQ_OOB 0x04 |
| 326 | #define OVERLAP 0xFF |
| 327 | |
| 328 | static const u8 gen_method[5][5] = { |
| 329 | { JUST_WORKS, JUST_CFM, REQ_PASSKEY, JUST_WORKS, REQ_PASSKEY }, |
| 330 | { JUST_WORKS, JUST_CFM, REQ_PASSKEY, JUST_WORKS, REQ_PASSKEY }, |
| 331 | { CFM_PASSKEY, CFM_PASSKEY, REQ_PASSKEY, JUST_WORKS, CFM_PASSKEY }, |
| 332 | { JUST_WORKS, JUST_CFM, JUST_WORKS, JUST_WORKS, JUST_CFM }, |
| 333 | { CFM_PASSKEY, CFM_PASSKEY, REQ_PASSKEY, JUST_WORKS, OVERLAP }, |
| 334 | }; |
| 335 | |
| 336 | static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth, |
| 337 | u8 local_io, u8 remote_io) |
| 338 | { |
| 339 | struct hci_conn *hcon = conn->hcon; |
| 340 | struct smp_chan *smp = conn->smp_chan; |
| 341 | u8 method; |
| 342 | u32 passkey = 0; |
| 343 | int ret = 0; |
| 344 | |
| 345 | /* Initialize key for JUST WORKS */ |
| 346 | memset(smp->tk, 0, sizeof(smp->tk)); |
| 347 | clear_bit(SMP_FLAG_TK_VALID, &smp->smp_flags); |
| 348 | |
| 349 | BT_DBG("tk_request: auth:%d lcl:%d rem:%d", auth, local_io, remote_io); |
| 350 | |
| 351 | /* If neither side wants MITM, use JUST WORKS */ |
| 352 | /* If either side has unknown io_caps, use JUST WORKS */ |
| 353 | /* Otherwise, look up method from the table */ |
| 354 | if (!(auth & SMP_AUTH_MITM) || |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 355 | local_io > SMP_IO_KEYBOARD_DISPLAY || |
| 356 | remote_io > SMP_IO_KEYBOARD_DISPLAY) |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 357 | method = JUST_WORKS; |
| 358 | else |
Ido Yariv | b3ff53f | 2012-03-05 20:07:08 +0200 | [diff] [blame] | 359 | method = gen_method[remote_io][local_io]; |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 360 | |
| 361 | /* If not bonding, don't ask user to confirm a Zero TK */ |
| 362 | if (!(auth & SMP_AUTH_BONDING) && method == JUST_CFM) |
| 363 | method = JUST_WORKS; |
| 364 | |
| 365 | /* If Just Works, Continue with Zero TK */ |
| 366 | if (method == JUST_WORKS) { |
| 367 | set_bit(SMP_FLAG_TK_VALID, &smp->smp_flags); |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | /* Not Just Works/Confirm results in MITM Authentication */ |
| 372 | if (method != JUST_CFM) |
| 373 | set_bit(SMP_FLAG_MITM_AUTH, &smp->smp_flags); |
| 374 | |
| 375 | /* If both devices have Keyoard-Display I/O, the master |
| 376 | * Confirms and the slave Enters the passkey. |
| 377 | */ |
| 378 | if (method == OVERLAP) { |
| 379 | if (hcon->link_mode & HCI_LM_MASTER) |
| 380 | method = CFM_PASSKEY; |
| 381 | else |
| 382 | method = REQ_PASSKEY; |
| 383 | } |
| 384 | |
| 385 | /* Generate random passkey. Not valid until confirmed. */ |
| 386 | if (method == CFM_PASSKEY) { |
| 387 | u8 key[16]; |
| 388 | |
| 389 | memset(key, 0, sizeof(key)); |
| 390 | get_random_bytes(&passkey, sizeof(passkey)); |
| 391 | passkey %= 1000000; |
| 392 | put_unaligned_le32(passkey, key); |
| 393 | swap128(key, smp->tk); |
| 394 | BT_DBG("PassKey: %d", passkey); |
| 395 | } |
| 396 | |
| 397 | hci_dev_lock(hcon->hdev); |
| 398 | |
| 399 | if (method == REQ_PASSKEY) |
Marcel Holtmann | ce39fb4 | 2013-10-13 02:23:39 -0700 | [diff] [blame] | 400 | ret = mgmt_user_passkey_request(hcon->hdev, &hcon->dst, |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 401 | hcon->type, hcon->dst_type); |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 402 | else |
Marcel Holtmann | ce39fb4 | 2013-10-13 02:23:39 -0700 | [diff] [blame] | 403 | ret = mgmt_user_confirm_request(hcon->hdev, &hcon->dst, |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 404 | hcon->type, hcon->dst_type, |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 405 | cpu_to_le32(passkey), 0); |
| 406 | |
| 407 | hci_dev_unlock(hcon->hdev); |
| 408 | |
| 409 | return ret; |
| 410 | } |
| 411 | |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 412 | static void confirm_work(struct work_struct *work) |
| 413 | { |
| 414 | struct smp_chan *smp = container_of(work, struct smp_chan, confirm); |
| 415 | struct l2cap_conn *conn = smp->conn; |
Johan Hedberg | 893ce8b | 2014-02-18 21:41:31 +0200 | [diff] [blame^] | 416 | struct hci_dev *hdev = conn->hcon->hdev; |
| 417 | struct crypto_blkcipher *tfm = hdev->tfm_aes; |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 418 | struct smp_cmd_pairing_confirm cp; |
| 419 | int ret; |
| 420 | u8 res[16], reason; |
| 421 | |
| 422 | BT_DBG("conn %p", conn); |
| 423 | |
Johan Hedberg | 893ce8b | 2014-02-18 21:41:31 +0200 | [diff] [blame^] | 424 | /* Prevent mutual access to hdev->tfm_aes */ |
| 425 | hci_dev_lock(hdev); |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 426 | |
| 427 | if (conn->hcon->out) |
Marcel Holtmann | c8462ca | 2013-10-13 05:24:02 -0700 | [diff] [blame] | 428 | ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp, |
| 429 | conn->hcon->src_type, &conn->hcon->src, |
| 430 | conn->hcon->dst_type, &conn->hcon->dst, res); |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 431 | else |
| 432 | ret = smp_c1(tfm, smp->tk, smp->prnd, smp->preq, smp->prsp, |
Marcel Holtmann | c8462ca | 2013-10-13 05:24:02 -0700 | [diff] [blame] | 433 | conn->hcon->dst_type, &conn->hcon->dst, |
| 434 | conn->hcon->src_type, &conn->hcon->src, res); |
Johan Hedberg | 893ce8b | 2014-02-18 21:41:31 +0200 | [diff] [blame^] | 435 | |
| 436 | hci_dev_unlock(hdev); |
| 437 | |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 438 | if (ret) { |
| 439 | reason = SMP_UNSPECIFIED; |
| 440 | goto error; |
| 441 | } |
| 442 | |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 443 | clear_bit(SMP_FLAG_CFM_PENDING, &smp->smp_flags); |
| 444 | |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 445 | swap128(res, cp.confirm_val); |
| 446 | smp_send_cmd(smp->conn, SMP_CMD_PAIRING_CONFIRM, sizeof(cp), &cp); |
| 447 | |
| 448 | return; |
| 449 | |
| 450 | error: |
Johan Hedberg | 84794e1 | 2013-11-06 11:24:57 +0200 | [diff] [blame] | 451 | smp_failure(conn, reason); |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | static void random_work(struct work_struct *work) |
| 455 | { |
| 456 | struct smp_chan *smp = container_of(work, struct smp_chan, random); |
| 457 | struct l2cap_conn *conn = smp->conn; |
| 458 | struct hci_conn *hcon = conn->hcon; |
Johan Hedberg | 893ce8b | 2014-02-18 21:41:31 +0200 | [diff] [blame^] | 459 | struct hci_dev *hdev = hcon->hdev; |
| 460 | struct crypto_blkcipher *tfm = hdev->tfm_aes; |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 461 | u8 reason, confirm[16], res[16], key[16]; |
| 462 | int ret; |
| 463 | |
| 464 | if (IS_ERR_OR_NULL(tfm)) { |
| 465 | reason = SMP_UNSPECIFIED; |
| 466 | goto error; |
| 467 | } |
| 468 | |
| 469 | BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave"); |
| 470 | |
Johan Hedberg | 893ce8b | 2014-02-18 21:41:31 +0200 | [diff] [blame^] | 471 | /* Prevent mutual access to hdev->tfm_aes */ |
| 472 | hci_dev_lock(hdev); |
| 473 | |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 474 | if (hcon->out) |
Marcel Holtmann | c8462ca | 2013-10-13 05:24:02 -0700 | [diff] [blame] | 475 | ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp, |
| 476 | hcon->src_type, &hcon->src, |
| 477 | hcon->dst_type, &hcon->dst, res); |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 478 | else |
| 479 | ret = smp_c1(tfm, smp->tk, smp->rrnd, smp->preq, smp->prsp, |
Marcel Holtmann | c8462ca | 2013-10-13 05:24:02 -0700 | [diff] [blame] | 480 | hcon->dst_type, &hcon->dst, |
| 481 | hcon->src_type, &hcon->src, res); |
Johan Hedberg | 893ce8b | 2014-02-18 21:41:31 +0200 | [diff] [blame^] | 482 | |
| 483 | hci_dev_unlock(hdev); |
| 484 | |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 485 | if (ret) { |
| 486 | reason = SMP_UNSPECIFIED; |
| 487 | goto error; |
| 488 | } |
| 489 | |
| 490 | swap128(res, confirm); |
| 491 | |
| 492 | if (memcmp(smp->pcnf, confirm, sizeof(smp->pcnf)) != 0) { |
| 493 | BT_ERR("Pairing failed (confirmation values mismatch)"); |
| 494 | reason = SMP_CONFIRM_FAILED; |
| 495 | goto error; |
| 496 | } |
| 497 | |
| 498 | if (hcon->out) { |
| 499 | u8 stk[16], rand[8]; |
| 500 | __le16 ediv; |
| 501 | |
| 502 | memset(rand, 0, sizeof(rand)); |
| 503 | ediv = 0; |
| 504 | |
| 505 | smp_s1(tfm, smp->tk, smp->rrnd, smp->prnd, key); |
| 506 | swap128(key, stk); |
| 507 | |
Vinicius Costa Gomes | f7aa611 | 2012-01-30 19:29:12 -0300 | [diff] [blame] | 508 | memset(stk + smp->enc_key_size, 0, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 509 | SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size); |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 510 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 511 | if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags)) { |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 512 | reason = SMP_UNSPECIFIED; |
| 513 | goto error; |
| 514 | } |
| 515 | |
| 516 | hci_le_start_enc(hcon, ediv, rand, stk); |
Vinicius Costa Gomes | f7aa611 | 2012-01-30 19:29:12 -0300 | [diff] [blame] | 517 | hcon->enc_key_size = smp->enc_key_size; |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 518 | } else { |
| 519 | u8 stk[16], r[16], rand[8]; |
| 520 | __le16 ediv; |
| 521 | |
| 522 | memset(rand, 0, sizeof(rand)); |
| 523 | ediv = 0; |
| 524 | |
| 525 | swap128(smp->prnd, r); |
| 526 | smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(r), r); |
| 527 | |
| 528 | smp_s1(tfm, smp->tk, smp->prnd, smp->rrnd, key); |
| 529 | swap128(key, stk); |
| 530 | |
Vinicius Costa Gomes | f7aa611 | 2012-01-30 19:29:12 -0300 | [diff] [blame] | 531 | memset(stk + smp->enc_key_size, 0, |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 532 | SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size); |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 533 | |
Marcel Holtmann | ce39fb4 | 2013-10-13 02:23:39 -0700 | [diff] [blame] | 534 | hci_add_ltk(hcon->hdev, &hcon->dst, hcon->dst_type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 535 | HCI_SMP_STK_SLAVE, 0, 0, stk, smp->enc_key_size, |
| 536 | ediv, rand); |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | return; |
| 540 | |
| 541 | error: |
Johan Hedberg | 84794e1 | 2013-11-06 11:24:57 +0200 | [diff] [blame] | 542 | smp_failure(conn, reason); |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | static struct smp_chan *smp_chan_create(struct l2cap_conn *conn) |
| 546 | { |
| 547 | struct smp_chan *smp; |
| 548 | |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 549 | smp = kzalloc(sizeof(*smp), GFP_ATOMIC); |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 550 | if (!smp) |
| 551 | return NULL; |
| 552 | |
| 553 | INIT_WORK(&smp->confirm, confirm_work); |
| 554 | INIT_WORK(&smp->random, random_work); |
| 555 | |
| 556 | smp->conn = conn; |
| 557 | conn->smp_chan = smp; |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 558 | conn->hcon->smp_conn = conn; |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 559 | |
| 560 | hci_conn_hold(conn->hcon); |
| 561 | |
| 562 | return smp; |
| 563 | } |
| 564 | |
| 565 | void smp_chan_destroy(struct l2cap_conn *conn) |
| 566 | { |
Brian Gix | c8eb969 | 2011-11-23 08:28:35 -0800 | [diff] [blame] | 567 | struct smp_chan *smp = conn->smp_chan; |
| 568 | |
Vinicius Costa Gomes | f1c09c0 | 2012-02-01 18:27:56 -0300 | [diff] [blame] | 569 | BUG_ON(!smp); |
Brian Gix | c8eb969 | 2011-11-23 08:28:35 -0800 | [diff] [blame] | 570 | |
Brian Gix | c8eb969 | 2011-11-23 08:28:35 -0800 | [diff] [blame] | 571 | kfree(smp); |
| 572 | conn->smp_chan = NULL; |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 573 | conn->hcon->smp_conn = NULL; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 574 | hci_conn_drop(conn->hcon); |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 575 | } |
| 576 | |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 577 | int smp_user_confirm_reply(struct hci_conn *hcon, u16 mgmt_op, __le32 passkey) |
| 578 | { |
| 579 | struct l2cap_conn *conn = hcon->smp_conn; |
| 580 | struct smp_chan *smp; |
| 581 | u32 value; |
| 582 | u8 key[16]; |
| 583 | |
| 584 | BT_DBG(""); |
| 585 | |
| 586 | if (!conn) |
| 587 | return -ENOTCONN; |
| 588 | |
| 589 | smp = conn->smp_chan; |
| 590 | |
| 591 | switch (mgmt_op) { |
| 592 | case MGMT_OP_USER_PASSKEY_REPLY: |
| 593 | value = le32_to_cpu(passkey); |
| 594 | memset(key, 0, sizeof(key)); |
| 595 | BT_DBG("PassKey: %d", value); |
| 596 | put_unaligned_le32(value, key); |
| 597 | swap128(key, smp->tk); |
| 598 | /* Fall Through */ |
| 599 | case MGMT_OP_USER_CONFIRM_REPLY: |
| 600 | set_bit(SMP_FLAG_TK_VALID, &smp->smp_flags); |
| 601 | break; |
| 602 | case MGMT_OP_USER_PASSKEY_NEG_REPLY: |
| 603 | case MGMT_OP_USER_CONFIRM_NEG_REPLY: |
Johan Hedberg | 84794e1 | 2013-11-06 11:24:57 +0200 | [diff] [blame] | 604 | smp_failure(conn, SMP_PASSKEY_ENTRY_FAILED); |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 605 | return 0; |
| 606 | default: |
Johan Hedberg | 84794e1 | 2013-11-06 11:24:57 +0200 | [diff] [blame] | 607 | smp_failure(conn, SMP_PASSKEY_ENTRY_FAILED); |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 608 | return -EOPNOTSUPP; |
| 609 | } |
| 610 | |
| 611 | /* If it is our turn to send Pairing Confirm, do so now */ |
| 612 | if (test_bit(SMP_FLAG_CFM_PENDING, &smp->smp_flags)) |
| 613 | queue_work(hcon->hdev->workqueue, &smp->confirm); |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 618 | static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb) |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 619 | { |
Vinicius Costa Gomes | 3158c50 | 2011-06-14 13:37:42 -0300 | [diff] [blame] | 620 | struct smp_cmd_pairing rsp, *req = (void *) skb->data; |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 621 | struct smp_chan *smp; |
Vinicius Costa Gomes | 3158c50 | 2011-06-14 13:37:42 -0300 | [diff] [blame] | 622 | u8 key_size; |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 623 | u8 auth = SMP_AUTH_NONE; |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 624 | int ret; |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 625 | |
| 626 | BT_DBG("conn %p", conn); |
| 627 | |
Johan Hedberg | c46b98b | 2014-02-18 10:19:29 +0200 | [diff] [blame] | 628 | if (skb->len < sizeof(*req)) |
| 629 | return SMP_UNSPECIFIED; |
| 630 | |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 631 | if (conn->hcon->link_mode & HCI_LM_MASTER) |
| 632 | return SMP_CMD_NOTSUPP; |
| 633 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 634 | if (!test_and_set_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 635 | smp = smp_chan_create(conn); |
Andrei Emeltchenko | d08fd0e | 2012-07-19 17:03:43 +0300 | [diff] [blame] | 636 | else |
| 637 | smp = conn->smp_chan; |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 638 | |
Andrei Emeltchenko | d08fd0e | 2012-07-19 17:03:43 +0300 | [diff] [blame] | 639 | if (!smp) |
| 640 | return SMP_UNSPECIFIED; |
Vinicius Costa Gomes | d26a234 | 2011-08-19 21:06:51 -0300 | [diff] [blame] | 641 | |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 642 | smp->preq[0] = SMP_CMD_PAIRING_REQ; |
| 643 | memcpy(&smp->preq[1], req, sizeof(*req)); |
Vinicius Costa Gomes | 3158c50 | 2011-06-14 13:37:42 -0300 | [diff] [blame] | 644 | skb_pull(skb, sizeof(*req)); |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 645 | |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 646 | /* We didn't start the pairing, so match remote */ |
| 647 | if (req->auth_req & SMP_AUTH_BONDING) |
| 648 | auth = req->auth_req; |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 649 | |
Ido Yariv | fdde0a2 | 2012-03-05 20:09:38 +0200 | [diff] [blame] | 650 | conn->hcon->pending_sec_level = authreq_to_seclevel(auth); |
| 651 | |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 652 | build_pairing_cmd(conn, req, &rsp, auth); |
Vinicius Costa Gomes | 3158c50 | 2011-06-14 13:37:42 -0300 | [diff] [blame] | 653 | |
| 654 | key_size = min(req->max_key_size, rsp.max_key_size); |
| 655 | if (check_enc_key_size(conn, key_size)) |
| 656 | return SMP_ENC_KEY_SIZE; |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 657 | |
Johan Hedberg | e84a6b1 | 2013-12-02 10:49:03 +0200 | [diff] [blame] | 658 | get_random_bytes(smp->prnd, sizeof(smp->prnd)); |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 659 | |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 660 | smp->prsp[0] = SMP_CMD_PAIRING_RSP; |
| 661 | memcpy(&smp->prsp[1], &rsp, sizeof(rsp)); |
Anderson Briglia | f01ead3 | 2011-06-09 18:50:45 -0300 | [diff] [blame] | 662 | |
Vinicius Costa Gomes | 3158c50 | 2011-06-14 13:37:42 -0300 | [diff] [blame] | 663 | smp_send_cmd(conn, SMP_CMD_PAIRING_RSP, sizeof(rsp), &rsp); |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 664 | |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 665 | /* Request setup of TK */ |
| 666 | ret = tk_request(conn, 0, auth, rsp.io_capability, req->io_capability); |
| 667 | if (ret) |
| 668 | return SMP_UNSPECIFIED; |
| 669 | |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 670 | return 0; |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 671 | } |
| 672 | |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 673 | static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb) |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 674 | { |
Vinicius Costa Gomes | 3158c50 | 2011-06-14 13:37:42 -0300 | [diff] [blame] | 675 | struct smp_cmd_pairing *req, *rsp = (void *) skb->data; |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 676 | struct smp_chan *smp = conn->smp_chan; |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 677 | struct hci_dev *hdev = conn->hcon->hdev; |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 678 | u8 key_size, auth = SMP_AUTH_NONE; |
Anderson Briglia | 7d24ddc | 2011-06-09 18:50:46 -0300 | [diff] [blame] | 679 | int ret; |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 680 | |
| 681 | BT_DBG("conn %p", conn); |
| 682 | |
Johan Hedberg | c46b98b | 2014-02-18 10:19:29 +0200 | [diff] [blame] | 683 | if (skb->len < sizeof(*rsp)) |
| 684 | return SMP_UNSPECIFIED; |
| 685 | |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 686 | if (!(conn->hcon->link_mode & HCI_LM_MASTER)) |
| 687 | return SMP_CMD_NOTSUPP; |
| 688 | |
Vinicius Costa Gomes | 3158c50 | 2011-06-14 13:37:42 -0300 | [diff] [blame] | 689 | skb_pull(skb, sizeof(*rsp)); |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 690 | |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 691 | req = (void *) &smp->preq[1]; |
Vinicius Costa Gomes | 3158c50 | 2011-06-14 13:37:42 -0300 | [diff] [blame] | 692 | |
| 693 | key_size = min(req->max_key_size, rsp->max_key_size); |
| 694 | if (check_enc_key_size(conn, key_size)) |
| 695 | return SMP_ENC_KEY_SIZE; |
| 696 | |
Johan Hedberg | e84a6b1 | 2013-12-02 10:49:03 +0200 | [diff] [blame] | 697 | get_random_bytes(smp->prnd, sizeof(smp->prnd)); |
Anderson Briglia | 7d24ddc | 2011-06-09 18:50:46 -0300 | [diff] [blame] | 698 | |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 699 | smp->prsp[0] = SMP_CMD_PAIRING_RSP; |
| 700 | memcpy(&smp->prsp[1], rsp, sizeof(*rsp)); |
Anderson Briglia | 7d24ddc | 2011-06-09 18:50:46 -0300 | [diff] [blame] | 701 | |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 702 | if ((req->auth_req & SMP_AUTH_BONDING) && |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 703 | (rsp->auth_req & SMP_AUTH_BONDING)) |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 704 | auth = SMP_AUTH_BONDING; |
| 705 | |
| 706 | auth |= (req->auth_req | rsp->auth_req) & SMP_AUTH_MITM; |
| 707 | |
Johan Hedberg | 476585e | 2012-06-06 18:54:15 +0800 | [diff] [blame] | 708 | ret = tk_request(conn, 0, auth, req->io_capability, rsp->io_capability); |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 709 | if (ret) |
| 710 | return SMP_UNSPECIFIED; |
| 711 | |
| 712 | set_bit(SMP_FLAG_CFM_PENDING, &smp->smp_flags); |
| 713 | |
| 714 | /* Can't compose response until we have been confirmed */ |
| 715 | if (!test_bit(SMP_FLAG_TK_VALID, &smp->smp_flags)) |
| 716 | return 0; |
| 717 | |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 718 | queue_work(hdev->workqueue, &smp->confirm); |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 719 | |
| 720 | return 0; |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 721 | } |
| 722 | |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 723 | static u8 smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skb) |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 724 | { |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 725 | struct smp_chan *smp = conn->smp_chan; |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 726 | struct hci_dev *hdev = conn->hcon->hdev; |
Anderson Briglia | 7d24ddc | 2011-06-09 18:50:46 -0300 | [diff] [blame] | 727 | |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 728 | BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave"); |
| 729 | |
Johan Hedberg | c46b98b | 2014-02-18 10:19:29 +0200 | [diff] [blame] | 730 | if (skb->len < sizeof(smp->pcnf)) |
| 731 | return SMP_UNSPECIFIED; |
| 732 | |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 733 | memcpy(smp->pcnf, skb->data, sizeof(smp->pcnf)); |
| 734 | skb_pull(skb, sizeof(smp->pcnf)); |
Anderson Briglia | 7d24ddc | 2011-06-09 18:50:46 -0300 | [diff] [blame] | 735 | |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 736 | if (conn->hcon->out) { |
Anderson Briglia | 7d24ddc | 2011-06-09 18:50:46 -0300 | [diff] [blame] | 737 | u8 random[16]; |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 738 | |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 739 | swap128(smp->prnd, random); |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 740 | smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(random), |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 741 | random); |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 742 | } else if (test_bit(SMP_FLAG_TK_VALID, &smp->smp_flags)) { |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 743 | queue_work(hdev->workqueue, &smp->confirm); |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 744 | } else { |
| 745 | set_bit(SMP_FLAG_CFM_PENDING, &smp->smp_flags); |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 746 | } |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 747 | |
| 748 | return 0; |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 749 | } |
| 750 | |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 751 | static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 752 | { |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 753 | struct smp_chan *smp = conn->smp_chan; |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 754 | struct hci_dev *hdev = conn->hcon->hdev; |
Anderson Briglia | 7d24ddc | 2011-06-09 18:50:46 -0300 | [diff] [blame] | 755 | |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 756 | BT_DBG("conn %p", conn); |
Anderson Briglia | 7d24ddc | 2011-06-09 18:50:46 -0300 | [diff] [blame] | 757 | |
Johan Hedberg | c46b98b | 2014-02-18 10:19:29 +0200 | [diff] [blame] | 758 | if (skb->len < sizeof(smp->rrnd)) |
| 759 | return SMP_UNSPECIFIED; |
| 760 | |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 761 | swap128(skb->data, smp->rrnd); |
| 762 | skb_pull(skb, sizeof(smp->rrnd)); |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 763 | |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 764 | queue_work(hdev->workqueue, &smp->random); |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 765 | |
| 766 | return 0; |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 767 | } |
| 768 | |
Johan Hedberg | 4dab786 | 2012-06-07 14:58:37 +0800 | [diff] [blame] | 769 | static u8 smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level) |
Vinicius Costa Gomes | 988c599 | 2011-08-25 20:02:28 -0300 | [diff] [blame] | 770 | { |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 771 | struct smp_ltk *key; |
Vinicius Costa Gomes | 988c599 | 2011-08-25 20:02:28 -0300 | [diff] [blame] | 772 | struct hci_conn *hcon = conn->hcon; |
| 773 | |
Johan Hedberg | 98a0b84 | 2014-01-30 19:40:00 -0800 | [diff] [blame] | 774 | key = hci_find_ltk_by_addr(hcon->hdev, &hcon->dst, hcon->dst_type, |
| 775 | hcon->out); |
Vinicius Costa Gomes | 988c599 | 2011-08-25 20:02:28 -0300 | [diff] [blame] | 776 | if (!key) |
| 777 | return 0; |
| 778 | |
Johan Hedberg | 4dab786 | 2012-06-07 14:58:37 +0800 | [diff] [blame] | 779 | if (sec_level > BT_SECURITY_MEDIUM && !key->authenticated) |
| 780 | return 0; |
| 781 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 782 | if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags)) |
Vinicius Costa Gomes | 988c599 | 2011-08-25 20:02:28 -0300 | [diff] [blame] | 783 | return 1; |
| 784 | |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 785 | hci_le_start_enc(hcon, key->ediv, key->rand, key->val); |
| 786 | hcon->enc_key_size = key->enc_size; |
Vinicius Costa Gomes | 988c599 | 2011-08-25 20:02:28 -0300 | [diff] [blame] | 787 | |
| 788 | return 1; |
Vinicius Costa Gomes | 988c599 | 2011-08-25 20:02:28 -0300 | [diff] [blame] | 789 | } |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 790 | |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 791 | static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 792 | { |
| 793 | struct smp_cmd_security_req *rp = (void *) skb->data; |
| 794 | struct smp_cmd_pairing cp; |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 795 | struct hci_conn *hcon = conn->hcon; |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 796 | struct smp_chan *smp; |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 797 | |
| 798 | BT_DBG("conn %p", conn); |
| 799 | |
Johan Hedberg | c46b98b | 2014-02-18 10:19:29 +0200 | [diff] [blame] | 800 | if (skb->len < sizeof(*rp)) |
| 801 | return SMP_UNSPECIFIED; |
| 802 | |
Johan Hedberg | 86ca9ea | 2013-11-05 11:30:39 +0200 | [diff] [blame] | 803 | if (!(conn->hcon->link_mode & HCI_LM_MASTER)) |
| 804 | return SMP_CMD_NOTSUPP; |
| 805 | |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 806 | hcon->pending_sec_level = authreq_to_seclevel(rp->auth_req); |
Vinicius Costa Gomes | feb45eb | 2011-08-25 20:02:35 -0300 | [diff] [blame] | 807 | |
Johan Hedberg | 4dab786 | 2012-06-07 14:58:37 +0800 | [diff] [blame] | 808 | if (smp_ltk_encrypt(conn, hcon->pending_sec_level)) |
Vinicius Costa Gomes | 988c599 | 2011-08-25 20:02:28 -0300 | [diff] [blame] | 809 | return 0; |
| 810 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 811 | if (test_and_set_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags)) |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 812 | return 0; |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 813 | |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 814 | smp = smp_chan_create(conn); |
Vinicius Costa Gomes | d26a234 | 2011-08-19 21:06:51 -0300 | [diff] [blame] | 815 | |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 816 | skb_pull(skb, sizeof(*rp)); |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 817 | |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 818 | memset(&cp, 0, sizeof(cp)); |
Vinicius Costa Gomes | 54790f7 | 2011-07-07 18:59:38 -0300 | [diff] [blame] | 819 | build_pairing_cmd(conn, &cp, NULL, rp->auth_req); |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 820 | |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 821 | smp->preq[0] = SMP_CMD_PAIRING_REQ; |
| 822 | memcpy(&smp->preq[1], &cp, sizeof(cp)); |
Anderson Briglia | f01ead3 | 2011-06-09 18:50:45 -0300 | [diff] [blame] | 823 | |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 824 | smp_send_cmd(conn, SMP_CMD_PAIRING_REQ, sizeof(cp), &cp); |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 825 | |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 826 | return 0; |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 827 | } |
| 828 | |
Johan Hedberg | ad32a2f | 2013-05-14 18:05:12 +0300 | [diff] [blame] | 829 | bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level) |
| 830 | { |
| 831 | if (sec_level == BT_SECURITY_LOW) |
| 832 | return true; |
| 833 | |
| 834 | if (hcon->sec_level >= sec_level) |
| 835 | return true; |
| 836 | |
| 837 | return false; |
| 838 | } |
| 839 | |
Vinicius Costa Gomes | cc11092 | 2012-08-23 21:32:43 -0300 | [diff] [blame] | 840 | int smp_conn_security(struct hci_conn *hcon, __u8 sec_level) |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 841 | { |
Vinicius Costa Gomes | cc11092 | 2012-08-23 21:32:43 -0300 | [diff] [blame] | 842 | struct l2cap_conn *conn = hcon->l2cap_data; |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 843 | struct smp_chan *smp = conn->smp_chan; |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 844 | __u8 authreq; |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 845 | |
Vinicius Costa Gomes | 3a0259b | 2011-06-09 18:50:43 -0300 | [diff] [blame] | 846 | BT_DBG("conn %p hcon %p level 0x%2.2x", conn, hcon, sec_level); |
| 847 | |
Johan Hedberg | 757aee0 | 2013-04-24 13:05:32 +0300 | [diff] [blame] | 848 | if (!test_bit(HCI_LE_ENABLED, &hcon->hdev->dev_flags)) |
Andre Guedes | 2e65c9d | 2011-06-30 19:20:56 -0300 | [diff] [blame] | 849 | return 1; |
| 850 | |
Johan Hedberg | ad32a2f | 2013-05-14 18:05:12 +0300 | [diff] [blame] | 851 | if (smp_sufficient_security(hcon, sec_level)) |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 852 | return 1; |
| 853 | |
Vinicius Costa Gomes | 988c599 | 2011-08-25 20:02:28 -0300 | [diff] [blame] | 854 | if (hcon->link_mode & HCI_LM_MASTER) |
Johan Hedberg | 4dab786 | 2012-06-07 14:58:37 +0800 | [diff] [blame] | 855 | if (smp_ltk_encrypt(conn, sec_level)) |
Vinicius Costa Gomes | 02bc745 | 2011-07-07 18:59:41 -0300 | [diff] [blame] | 856 | goto done; |
Vinicius Costa Gomes | d26a234 | 2011-08-19 21:06:51 -0300 | [diff] [blame] | 857 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 858 | if (test_and_set_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags)) |
Vinicius Costa Gomes | d26a234 | 2011-08-19 21:06:51 -0300 | [diff] [blame] | 859 | return 0; |
| 860 | |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 861 | smp = smp_chan_create(conn); |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 862 | if (!smp) |
| 863 | return 1; |
| 864 | |
| 865 | authreq = seclevel_to_authreq(sec_level); |
Vinicius Costa Gomes | d26a234 | 2011-08-19 21:06:51 -0300 | [diff] [blame] | 866 | |
Vinicius Costa Gomes | d26a234 | 2011-08-19 21:06:51 -0300 | [diff] [blame] | 867 | if (hcon->link_mode & HCI_LM_MASTER) { |
| 868 | struct smp_cmd_pairing cp; |
Anderson Briglia | f01ead3 | 2011-06-09 18:50:45 -0300 | [diff] [blame] | 869 | |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 870 | build_pairing_cmd(conn, &cp, NULL, authreq); |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 871 | smp->preq[0] = SMP_CMD_PAIRING_REQ; |
| 872 | memcpy(&smp->preq[1], &cp, sizeof(cp)); |
Anderson Briglia | f01ead3 | 2011-06-09 18:50:45 -0300 | [diff] [blame] | 873 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 874 | smp_send_cmd(conn, SMP_CMD_PAIRING_REQ, sizeof(cp), &cp); |
| 875 | } else { |
| 876 | struct smp_cmd_security_req cp; |
Brian Gix | 2b64d15 | 2011-12-21 16:12:12 -0800 | [diff] [blame] | 877 | cp.auth_req = authreq; |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 878 | smp_send_cmd(conn, SMP_CMD_SECURITY_REQ, sizeof(cp), &cp); |
| 879 | } |
| 880 | |
Vinicius Costa Gomes | 02bc745 | 2011-07-07 18:59:41 -0300 | [diff] [blame] | 881 | done: |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 882 | hcon->pending_sec_level = sec_level; |
Vinicius Costa Gomes | f1cb9af | 2011-01-26 21:42:57 -0300 | [diff] [blame] | 883 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 884 | return 0; |
| 885 | } |
| 886 | |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 887 | static int smp_cmd_encrypt_info(struct l2cap_conn *conn, struct sk_buff *skb) |
| 888 | { |
Vinicius Costa Gomes | 16b9083 | 2011-07-07 18:59:39 -0300 | [diff] [blame] | 889 | struct smp_cmd_encrypt_info *rp = (void *) skb->data; |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 890 | struct smp_chan *smp = conn->smp_chan; |
Vinicius Costa Gomes | 16b9083 | 2011-07-07 18:59:39 -0300 | [diff] [blame] | 891 | |
Johan Hedberg | c46b98b | 2014-02-18 10:19:29 +0200 | [diff] [blame] | 892 | BT_DBG("conn %p", conn); |
| 893 | |
| 894 | if (skb->len < sizeof(*rp)) |
| 895 | return SMP_UNSPECIFIED; |
| 896 | |
Johan Hedberg | 6131ddc | 2014-02-18 10:19:37 +0200 | [diff] [blame] | 897 | /* Ignore this PDU if it wasn't requested */ |
| 898 | if (!(smp->remote_key_dist & SMP_DIST_ENC_KEY)) |
| 899 | return 0; |
| 900 | |
Vinicius Costa Gomes | 16b9083 | 2011-07-07 18:59:39 -0300 | [diff] [blame] | 901 | skb_pull(skb, sizeof(*rp)); |
| 902 | |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 903 | memcpy(smp->tk, rp->ltk, sizeof(smp->tk)); |
Vinicius Costa Gomes | 16b9083 | 2011-07-07 18:59:39 -0300 | [diff] [blame] | 904 | |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 905 | return 0; |
| 906 | } |
| 907 | |
| 908 | static int smp_cmd_master_ident(struct l2cap_conn *conn, struct sk_buff *skb) |
| 909 | { |
Vinicius Costa Gomes | 16b9083 | 2011-07-07 18:59:39 -0300 | [diff] [blame] | 910 | struct smp_cmd_master_ident *rp = (void *) skb->data; |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 911 | struct smp_chan *smp = conn->smp_chan; |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 912 | struct hci_dev *hdev = conn->hcon->hdev; |
| 913 | struct hci_conn *hcon = conn->hcon; |
| 914 | u8 authenticated; |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 915 | |
Johan Hedberg | c46b98b | 2014-02-18 10:19:29 +0200 | [diff] [blame] | 916 | BT_DBG("conn %p", conn); |
| 917 | |
| 918 | if (skb->len < sizeof(*rp)) |
| 919 | return SMP_UNSPECIFIED; |
| 920 | |
Johan Hedberg | 6131ddc | 2014-02-18 10:19:37 +0200 | [diff] [blame] | 921 | /* Ignore this PDU if it wasn't requested */ |
| 922 | if (!(smp->remote_key_dist & SMP_DIST_ENC_KEY)) |
| 923 | return 0; |
| 924 | |
Vinicius Costa Gomes | 16b9083 | 2011-07-07 18:59:39 -0300 | [diff] [blame] | 925 | skb_pull(skb, sizeof(*rp)); |
| 926 | |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 927 | hci_dev_lock(hdev); |
Marcel Holtmann | ce39fb4 | 2013-10-13 02:23:39 -0700 | [diff] [blame] | 928 | authenticated = (hcon->sec_level == BT_SECURITY_HIGH); |
| 929 | hci_add_ltk(hdev, &hcon->dst, hcon->dst_type, HCI_SMP_LTK, 1, |
| 930 | authenticated, smp->tk, smp->enc_key_size, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 931 | rp->ediv, rp->rand); |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 932 | if (!(smp->remote_key_dist & SMP_DIST_ID_KEY)) |
| 933 | smp_distribute_keys(conn, 1); |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 934 | hci_dev_unlock(hdev); |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 939 | static int smp_cmd_ident_info(struct l2cap_conn *conn, struct sk_buff *skb) |
| 940 | { |
| 941 | struct smp_cmd_ident_info *info = (void *) skb->data; |
| 942 | struct smp_chan *smp = conn->smp_chan; |
| 943 | |
| 944 | BT_DBG(""); |
| 945 | |
| 946 | if (skb->len < sizeof(*info)) |
| 947 | return SMP_UNSPECIFIED; |
| 948 | |
Johan Hedberg | 6131ddc | 2014-02-18 10:19:37 +0200 | [diff] [blame] | 949 | /* Ignore this PDU if it wasn't requested */ |
| 950 | if (!(smp->remote_key_dist & SMP_DIST_ID_KEY)) |
| 951 | return 0; |
| 952 | |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 953 | skb_pull(skb, sizeof(*info)); |
| 954 | |
| 955 | memcpy(smp->irk, info->irk, 16); |
| 956 | |
| 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | static int smp_cmd_ident_addr_info(struct l2cap_conn *conn, |
| 961 | struct sk_buff *skb) |
| 962 | { |
| 963 | struct smp_cmd_ident_addr_info *info = (void *) skb->data; |
| 964 | struct smp_chan *smp = conn->smp_chan; |
| 965 | struct hci_conn *hcon = conn->hcon; |
| 966 | bdaddr_t rpa; |
| 967 | |
| 968 | BT_DBG(""); |
| 969 | |
| 970 | if (skb->len < sizeof(*info)) |
| 971 | return SMP_UNSPECIFIED; |
| 972 | |
Johan Hedberg | 6131ddc | 2014-02-18 10:19:37 +0200 | [diff] [blame] | 973 | /* Ignore this PDU if it wasn't requested */ |
| 974 | if (!(smp->remote_key_dist & SMP_DIST_ID_KEY)) |
| 975 | return 0; |
| 976 | |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 977 | skb_pull(skb, sizeof(*info)); |
| 978 | |
| 979 | bacpy(&smp->id_addr, &info->bdaddr); |
| 980 | smp->id_addr_type = info->addr_type; |
| 981 | |
| 982 | if (hci_bdaddr_is_rpa(&hcon->dst, hcon->dst_type)) |
| 983 | bacpy(&rpa, &hcon->dst); |
| 984 | else |
| 985 | bacpy(&rpa, BDADDR_ANY); |
| 986 | |
| 987 | hci_add_irk(conn->hcon->hdev, &smp->id_addr, smp->id_addr_type, |
| 988 | smp->irk, &rpa); |
| 989 | |
| 990 | smp_distribute_keys(conn, 1); |
| 991 | |
| 992 | return 0; |
| 993 | } |
| 994 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 995 | int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb) |
| 996 | { |
Marcel Holtmann | 7b9899d | 2013-10-03 00:00:57 -0700 | [diff] [blame] | 997 | struct hci_conn *hcon = conn->hcon; |
Marcel Holtmann | 92381f5 | 2013-10-03 01:23:08 -0700 | [diff] [blame] | 998 | __u8 code, reason; |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 999 | int err = 0; |
| 1000 | |
Marcel Holtmann | 7b9899d | 2013-10-03 00:00:57 -0700 | [diff] [blame] | 1001 | if (hcon->type != LE_LINK) { |
| 1002 | kfree_skb(skb); |
Johan Hedberg | 3432711 | 2013-10-16 11:37:01 +0300 | [diff] [blame] | 1003 | return 0; |
Marcel Holtmann | 7b9899d | 2013-10-03 00:00:57 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
Marcel Holtmann | 92381f5 | 2013-10-03 01:23:08 -0700 | [diff] [blame] | 1006 | if (skb->len < 1) { |
| 1007 | kfree_skb(skb); |
| 1008 | return -EILSEQ; |
| 1009 | } |
| 1010 | |
Marcel Holtmann | 06ae331 | 2013-10-18 03:43:00 -0700 | [diff] [blame] | 1011 | if (!test_bit(HCI_LE_ENABLED, &hcon->hdev->dev_flags)) { |
Andre Guedes | 2e65c9d | 2011-06-30 19:20:56 -0300 | [diff] [blame] | 1012 | err = -ENOTSUPP; |
| 1013 | reason = SMP_PAIRING_NOTSUPP; |
| 1014 | goto done; |
| 1015 | } |
| 1016 | |
Marcel Holtmann | 92381f5 | 2013-10-03 01:23:08 -0700 | [diff] [blame] | 1017 | code = skb->data[0]; |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1018 | skb_pull(skb, sizeof(code)); |
| 1019 | |
Johan Hedberg | 8cf9fa1 | 2013-01-29 10:44:23 -0600 | [diff] [blame] | 1020 | /* |
| 1021 | * The SMP context must be initialized for all other PDUs except |
| 1022 | * pairing and security requests. If we get any other PDU when |
| 1023 | * not initialized simply disconnect (done if this function |
| 1024 | * returns an error). |
| 1025 | */ |
| 1026 | if (code != SMP_CMD_PAIRING_REQ && code != SMP_CMD_SECURITY_REQ && |
| 1027 | !conn->smp_chan) { |
| 1028 | BT_ERR("Unexpected SMP command 0x%02x. Disconnecting.", code); |
| 1029 | kfree_skb(skb); |
| 1030 | return -ENOTSUPP; |
| 1031 | } |
| 1032 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1033 | switch (code) { |
| 1034 | case SMP_CMD_PAIRING_REQ: |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 1035 | reason = smp_cmd_pairing_req(conn, skb); |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1036 | break; |
| 1037 | |
| 1038 | case SMP_CMD_PAIRING_FAIL: |
Johan Hedberg | 84794e1 | 2013-11-06 11:24:57 +0200 | [diff] [blame] | 1039 | smp_failure(conn, 0); |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 1040 | reason = 0; |
| 1041 | err = -EPERM; |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1042 | break; |
| 1043 | |
| 1044 | case SMP_CMD_PAIRING_RSP: |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 1045 | reason = smp_cmd_pairing_rsp(conn, skb); |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 1046 | break; |
| 1047 | |
| 1048 | case SMP_CMD_SECURITY_REQ: |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 1049 | reason = smp_cmd_security_req(conn, skb); |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 1050 | break; |
| 1051 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1052 | case SMP_CMD_PAIRING_CONFIRM: |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 1053 | reason = smp_cmd_pairing_confirm(conn, skb); |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 1054 | break; |
| 1055 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1056 | case SMP_CMD_PAIRING_RANDOM: |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 1057 | reason = smp_cmd_pairing_random(conn, skb); |
Anderson Briglia | 88ba43b | 2011-06-09 18:50:42 -0300 | [diff] [blame] | 1058 | break; |
| 1059 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1060 | case SMP_CMD_ENCRYPT_INFO: |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1061 | reason = smp_cmd_encrypt_info(conn, skb); |
| 1062 | break; |
| 1063 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1064 | case SMP_CMD_MASTER_IDENT: |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1065 | reason = smp_cmd_master_ident(conn, skb); |
| 1066 | break; |
| 1067 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1068 | case SMP_CMD_IDENT_INFO: |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 1069 | reason = smp_cmd_ident_info(conn, skb); |
| 1070 | break; |
| 1071 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1072 | case SMP_CMD_IDENT_ADDR_INFO: |
Johan Hedberg | fd349c0 | 2014-02-18 10:19:36 +0200 | [diff] [blame] | 1073 | reason = smp_cmd_ident_addr_info(conn, skb); |
| 1074 | break; |
| 1075 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1076 | case SMP_CMD_SIGN_INFO: |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1077 | /* Just ignored */ |
| 1078 | reason = 0; |
| 1079 | break; |
| 1080 | |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1081 | default: |
| 1082 | BT_DBG("Unknown command code 0x%2.2x", code); |
| 1083 | |
| 1084 | reason = SMP_CMD_NOTSUPP; |
Vinicius Costa Gomes | 3a0259b | 2011-06-09 18:50:43 -0300 | [diff] [blame] | 1085 | err = -EOPNOTSUPP; |
| 1086 | goto done; |
| 1087 | } |
| 1088 | |
| 1089 | done: |
| 1090 | if (reason) |
Johan Hedberg | 84794e1 | 2013-11-06 11:24:57 +0200 | [diff] [blame] | 1091 | smp_failure(conn, reason); |
Anderson Briglia | eb492e0 | 2011-06-09 18:50:40 -0300 | [diff] [blame] | 1092 | |
| 1093 | kfree_skb(skb); |
| 1094 | return err; |
| 1095 | } |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1096 | |
| 1097 | int smp_distribute_keys(struct l2cap_conn *conn, __u8 force) |
| 1098 | { |
| 1099 | struct smp_cmd_pairing *req, *rsp; |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 1100 | struct smp_chan *smp = conn->smp_chan; |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1101 | __u8 *keydist; |
| 1102 | |
| 1103 | BT_DBG("conn %p force %d", conn, force); |
| 1104 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 1105 | if (!test_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) |
Vinicius Costa Gomes | d26a234 | 2011-08-19 21:06:51 -0300 | [diff] [blame] | 1106 | return 0; |
| 1107 | |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 1108 | rsp = (void *) &smp->prsp[1]; |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1109 | |
| 1110 | /* The responder sends its keys first */ |
| 1111 | if (!force && conn->hcon->out && (rsp->resp_key_dist & 0x07)) |
| 1112 | return 0; |
| 1113 | |
Vinicius Costa Gomes | 1c1def0 | 2011-09-05 14:31:30 -0300 | [diff] [blame] | 1114 | req = (void *) &smp->preq[1]; |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1115 | |
| 1116 | if (conn->hcon->out) { |
| 1117 | keydist = &rsp->init_key_dist; |
| 1118 | *keydist &= req->init_key_dist; |
| 1119 | } else { |
| 1120 | keydist = &rsp->resp_key_dist; |
| 1121 | *keydist &= req->resp_key_dist; |
| 1122 | } |
| 1123 | |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1124 | BT_DBG("keydist 0x%x", *keydist); |
| 1125 | |
| 1126 | if (*keydist & SMP_DIST_ENC_KEY) { |
| 1127 | struct smp_cmd_encrypt_info enc; |
| 1128 | struct smp_cmd_master_ident ident; |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 1129 | struct hci_conn *hcon = conn->hcon; |
| 1130 | u8 authenticated; |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1131 | __le16 ediv; |
| 1132 | |
| 1133 | get_random_bytes(enc.ltk, sizeof(enc.ltk)); |
| 1134 | get_random_bytes(&ediv, sizeof(ediv)); |
| 1135 | get_random_bytes(ident.rand, sizeof(ident.rand)); |
| 1136 | |
| 1137 | smp_send_cmd(conn, SMP_CMD_ENCRYPT_INFO, sizeof(enc), &enc); |
| 1138 | |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 1139 | authenticated = hcon->sec_level == BT_SECURITY_HIGH; |
Marcel Holtmann | ce39fb4 | 2013-10-13 02:23:39 -0700 | [diff] [blame] | 1140 | hci_add_ltk(hcon->hdev, &hcon->dst, hcon->dst_type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1141 | HCI_SMP_LTK_SLAVE, 1, authenticated, |
| 1142 | enc.ltk, smp->enc_key_size, ediv, ident.rand); |
Vinicius Costa Gomes | 16b9083 | 2011-07-07 18:59:39 -0300 | [diff] [blame] | 1143 | |
Andrei Emeltchenko | 5811537 | 2012-03-12 12:13:06 +0200 | [diff] [blame] | 1144 | ident.ediv = ediv; |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1145 | |
| 1146 | smp_send_cmd(conn, SMP_CMD_MASTER_IDENT, sizeof(ident), &ident); |
| 1147 | |
| 1148 | *keydist &= ~SMP_DIST_ENC_KEY; |
| 1149 | } |
| 1150 | |
| 1151 | if (*keydist & SMP_DIST_ID_KEY) { |
| 1152 | struct smp_cmd_ident_addr_info addrinfo; |
| 1153 | struct smp_cmd_ident_info idinfo; |
| 1154 | |
| 1155 | /* Send a dummy key */ |
| 1156 | get_random_bytes(idinfo.irk, sizeof(idinfo.irk)); |
| 1157 | |
| 1158 | smp_send_cmd(conn, SMP_CMD_IDENT_INFO, sizeof(idinfo), &idinfo); |
| 1159 | |
| 1160 | /* Just public address */ |
| 1161 | memset(&addrinfo, 0, sizeof(addrinfo)); |
Marcel Holtmann | 2b36a56 | 2013-10-13 05:24:00 -0700 | [diff] [blame] | 1162 | bacpy(&addrinfo.bdaddr, &conn->hcon->src); |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1163 | |
| 1164 | smp_send_cmd(conn, SMP_CMD_IDENT_ADDR_INFO, sizeof(addrinfo), |
Marcel Holtmann | f156046 | 2013-10-13 05:43:25 -0700 | [diff] [blame] | 1165 | &addrinfo); |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1166 | |
| 1167 | *keydist &= ~SMP_DIST_ID_KEY; |
| 1168 | } |
| 1169 | |
| 1170 | if (*keydist & SMP_DIST_SIGN) { |
| 1171 | struct smp_cmd_sign_info sign; |
| 1172 | |
| 1173 | /* Send a dummy key */ |
| 1174 | get_random_bytes(sign.csrk, sizeof(sign.csrk)); |
| 1175 | |
| 1176 | smp_send_cmd(conn, SMP_CMD_SIGN_INFO, sizeof(sign), &sign); |
| 1177 | |
| 1178 | *keydist &= ~SMP_DIST_SIGN; |
| 1179 | } |
| 1180 | |
Johan Hedberg | b7d448d | 2014-02-18 17:14:34 +0200 | [diff] [blame] | 1181 | if (conn->hcon->out || force || !(rsp->init_key_dist & 0x07)) { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 1182 | clear_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags); |
Gustavo F. Padovan | 6c9d42a | 2011-12-20 10:57:27 -0200 | [diff] [blame] | 1183 | cancel_delayed_work_sync(&conn->security_timer); |
Vinicius Costa Gomes | 8aab475 | 2011-09-05 14:31:31 -0300 | [diff] [blame] | 1184 | smp_chan_destroy(conn); |
Vinicius Costa Gomes | d26a234 | 2011-08-19 21:06:51 -0300 | [diff] [blame] | 1185 | } |
| 1186 | |
Vinicius Costa Gomes | 7034b91 | 2011-07-07 18:59:34 -0300 | [diff] [blame] | 1187 | return 0; |
| 1188 | } |