blob: 45888fad83622c3d47e8f333ef065249dd8a7e60 [file] [log] [blame]
Andrei Emeltchenko903e4542012-09-27 17:26:09 +03001/*
2 Copyright (c) 2011,2012 Intel Corp.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License version 2 and
6 only version 2 as published by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12*/
13
14#include <net/bluetooth/bluetooth.h>
15#include <net/bluetooth/hci.h>
16#include <net/bluetooth/hci_core.h>
Dmitry Kasatkinba221bb2012-09-27 17:26:17 +030017#include <crypto/hash.h>
Andrei Emeltchenko903e4542012-09-27 17:26:09 +030018
Arron Wangb3d39142015-07-24 17:10:50 +080019#include "hci_request.h"
Marcel Holtmann70247282013-10-10 14:54:15 -070020#include "a2mp.h"
Marcel Holtmann7ef9fbf2013-10-10 14:54:14 -070021#include "amp.h"
22
Andrei Emeltchenko52c0d6e2012-09-27 17:26:12 +030023/* Remote AMP Controllers interface */
Andrei Emeltchenko0b26ab92012-09-27 17:26:24 +030024void amp_ctrl_get(struct amp_ctrl *ctrl)
Andrei Emeltchenko52c0d6e2012-09-27 17:26:12 +030025{
26 BT_DBG("ctrl %p orig refcnt %d", ctrl,
27 atomic_read(&ctrl->kref.refcount));
28
29 kref_get(&ctrl->kref);
30}
31
32static void amp_ctrl_destroy(struct kref *kref)
33{
34 struct amp_ctrl *ctrl = container_of(kref, struct amp_ctrl, kref);
35
36 BT_DBG("ctrl %p", ctrl);
37
38 kfree(ctrl->assoc);
39 kfree(ctrl);
40}
41
42int amp_ctrl_put(struct amp_ctrl *ctrl)
43{
44 BT_DBG("ctrl %p orig refcnt %d", ctrl,
45 atomic_read(&ctrl->kref.refcount));
46
47 return kref_put(&ctrl->kref, &amp_ctrl_destroy);
48}
49
Andrei Emeltchenkofa4ebc62012-10-05 16:56:55 +030050struct amp_ctrl *amp_ctrl_add(struct amp_mgr *mgr, u8 id)
Andrei Emeltchenko52c0d6e2012-09-27 17:26:12 +030051{
52 struct amp_ctrl *ctrl;
53
54 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
55 if (!ctrl)
56 return NULL;
57
Andrei Emeltchenkofa4ebc62012-10-05 16:56:55 +030058 kref_init(&ctrl->kref);
59 ctrl->id = id;
60
Andrei Emeltchenko52c0d6e2012-09-27 17:26:12 +030061 mutex_lock(&mgr->amp_ctrls_lock);
62 list_add(&ctrl->list, &mgr->amp_ctrls);
63 mutex_unlock(&mgr->amp_ctrls_lock);
64
Andrei Emeltchenko52c0d6e2012-09-27 17:26:12 +030065 BT_DBG("mgr %p ctrl %p", mgr, ctrl);
66
67 return ctrl;
68}
69
70void amp_ctrl_list_flush(struct amp_mgr *mgr)
71{
72 struct amp_ctrl *ctrl, *n;
73
74 BT_DBG("mgr %p", mgr);
75
76 mutex_lock(&mgr->amp_ctrls_lock);
77 list_for_each_entry_safe(ctrl, n, &mgr->amp_ctrls, list) {
78 list_del(&ctrl->list);
79 amp_ctrl_put(ctrl);
80 }
81 mutex_unlock(&mgr->amp_ctrls_lock);
82}
83
84struct amp_ctrl *amp_ctrl_lookup(struct amp_mgr *mgr, u8 id)
85{
86 struct amp_ctrl *ctrl;
87
88 BT_DBG("mgr %p id %d", mgr, id);
89
90 mutex_lock(&mgr->amp_ctrls_lock);
91 list_for_each_entry(ctrl, &mgr->amp_ctrls, list) {
92 if (ctrl->id == id) {
93 amp_ctrl_get(ctrl);
94 mutex_unlock(&mgr->amp_ctrls_lock);
95 return ctrl;
96 }
97 }
98 mutex_unlock(&mgr->amp_ctrls_lock);
99
100 return NULL;
101}
102
Andrei Emeltchenko3161ae12012-09-27 17:26:11 +0300103/* Physical Link interface */
104static u8 __next_handle(struct amp_mgr *mgr)
105{
106 if (++mgr->handle == 0)
107 mgr->handle = 1;
108
109 return mgr->handle;
110}
111
112struct hci_conn *phylink_add(struct hci_dev *hdev, struct amp_mgr *mgr,
Andrei Emeltchenkoa0c234f2012-10-05 16:56:56 +0300113 u8 remote_id, bool out)
Andrei Emeltchenko3161ae12012-09-27 17:26:11 +0300114{
Marcel Holtmannbdc8ead22013-10-13 02:23:38 -0700115 bdaddr_t *dst = &mgr->l2cap_conn->hcon->dst;
Andrei Emeltchenko3161ae12012-09-27 17:26:11 +0300116 struct hci_conn *hcon;
Johan Hedberga5c4e302014-07-16 11:56:07 +0300117 u8 role = out ? HCI_ROLE_MASTER : HCI_ROLE_SLAVE;
Andrei Emeltchenko3161ae12012-09-27 17:26:11 +0300118
Johan Hedberga5c4e302014-07-16 11:56:07 +0300119 hcon = hci_conn_add(hdev, AMP_LINK, dst, role);
Andrei Emeltchenko3161ae12012-09-27 17:26:11 +0300120 if (!hcon)
121 return NULL;
122
Andrei Emeltchenkoa0c234f2012-10-05 16:56:56 +0300123 BT_DBG("hcon %p dst %pMR", hcon, dst);
124
Andrei Emeltchenko3161ae12012-09-27 17:26:11 +0300125 hcon->state = BT_CONNECT;
Andrei Emeltchenko3161ae12012-09-27 17:26:11 +0300126 hcon->attempt++;
127 hcon->handle = __next_handle(mgr);
128 hcon->remote_id = remote_id;
Andrei Emeltchenkof706adf2012-10-18 13:16:19 +0300129 hcon->amp_mgr = amp_mgr_get(mgr);
Andrei Emeltchenko3161ae12012-09-27 17:26:11 +0300130
131 return hcon;
132}
133
Dmitry Kasatkinba221bb2012-09-27 17:26:17 +0300134/* AMP crypto key generation interface */
135static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output)
136{
Dmitry Kasatkinba221bb2012-09-27 17:26:17 +0300137 struct crypto_shash *tfm;
Johan Hedberg252670c2014-11-10 15:53:45 +0200138 struct shash_desc *shash;
Marcel Holtmann0a961a42014-07-20 17:43:07 +0200139 int ret;
Dmitry Kasatkinba221bb2012-09-27 17:26:17 +0300140
141 if (!ksize)
142 return -EINVAL;
143
144 tfm = crypto_alloc_shash("hmac(sha256)", 0, 0);
145 if (IS_ERR(tfm)) {
146 BT_DBG("crypto_alloc_ahash failed: err %ld", PTR_ERR(tfm));
147 return PTR_ERR(tfm);
148 }
149
150 ret = crypto_shash_setkey(tfm, key, ksize);
151 if (ret) {
152 BT_DBG("crypto_ahash_setkey failed: err %d", ret);
Johan Hedberg252670c2014-11-10 15:53:45 +0200153 goto failed;
Dmitry Kasatkinba221bb2012-09-27 17:26:17 +0300154 }
155
Johan Hedberg252670c2014-11-10 15:53:45 +0200156 shash = kzalloc(sizeof(*shash) + crypto_shash_descsize(tfm),
157 GFP_KERNEL);
158 if (!shash) {
159 ret = -ENOMEM;
160 goto failed;
161 }
162
163 shash->tfm = tfm;
164 shash->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
165
166 ret = crypto_shash_digest(shash, plaintext, psize, output);
167
168 kfree(shash);
169
170failed:
Dmitry Kasatkinba221bb2012-09-27 17:26:17 +0300171 crypto_free_shash(tfm);
172 return ret;
173}
174
Andrei Emeltchenko5a349182012-09-27 17:26:18 +0300175int phylink_gen_key(struct hci_conn *conn, u8 *data, u8 *len, u8 *type)
176{
177 struct hci_dev *hdev = conn->hdev;
178 struct link_key *key;
179 u8 keybuf[HCI_AMP_LINK_KEY_SIZE];
180 u8 gamp_key[HCI_AMP_LINK_KEY_SIZE];
181 int err;
182
183 if (!hci_conn_check_link_mode(conn))
184 return -EACCES;
185
186 BT_DBG("conn %p key_type %d", conn, conn->key_type);
187
188 /* Legacy key */
189 if (conn->key_type < 3) {
190 BT_ERR("Legacy key type %d", conn->key_type);
191 return -EACCES;
192 }
193
194 *type = conn->key_type;
195 *len = HCI_AMP_LINK_KEY_SIZE;
196
197 key = hci_find_link_key(hdev, &conn->dst);
Andrei Emeltchenko079db0c2012-10-05 16:56:53 +0300198 if (!key) {
199 BT_DBG("No Link key for conn %p dst %pMR", conn, &conn->dst);
200 return -EACCES;
201 }
Andrei Emeltchenko5a349182012-09-27 17:26:18 +0300202
203 /* BR/EDR Link Key concatenated together with itself */
204 memcpy(&keybuf[0], key->val, HCI_LINK_KEY_SIZE);
205 memcpy(&keybuf[HCI_LINK_KEY_SIZE], key->val, HCI_LINK_KEY_SIZE);
206
207 /* Derive Generic AMP Link Key (gamp) */
208 err = hmac_sha256(keybuf, HCI_AMP_LINK_KEY_SIZE, "gamp", 4, gamp_key);
209 if (err) {
210 BT_ERR("Could not derive Generic AMP Key: err %d", err);
211 return err;
212 }
213
214 if (conn->key_type == HCI_LK_DEBUG_COMBINATION) {
215 BT_DBG("Use Generic AMP Key (gamp)");
216 memcpy(data, gamp_key, HCI_AMP_LINK_KEY_SIZE);
217 return err;
218 }
219
220 /* Derive Dedicated AMP Link Key: "802b" is 802.11 PAL keyID */
221 return hmac_sha256(gamp_key, HCI_AMP_LINK_KEY_SIZE, "802b", 4, data);
222}
223
Arron Wangb3d39142015-07-24 17:10:50 +0800224static void read_local_amp_assoc_complete(struct hci_dev *hdev, u8 status,
225 u16 opcode, struct sk_buff *skb)
226{
227 struct hci_rp_read_local_amp_assoc *rp = (void *)skb->data;
228 struct amp_assoc *assoc = &hdev->loc_assoc;
229 size_t rem_len, frag_len;
230
231 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
232
233 if (rp->status)
234 goto send_rsp;
235
236 frag_len = skb->len - sizeof(*rp);
237 rem_len = __le16_to_cpu(rp->rem_len);
238
239 if (rem_len > frag_len) {
240 BT_DBG("frag_len %zu rem_len %zu", frag_len, rem_len);
241
242 memcpy(assoc->data + assoc->offset, rp->frag, frag_len);
243 assoc->offset += frag_len;
244
245 /* Read other fragments */
246 amp_read_loc_assoc_frag(hdev, rp->phy_handle);
247
248 return;
249 }
250
251 memcpy(assoc->data + assoc->offset, rp->frag, rem_len);
252 assoc->len = assoc->offset + rem_len;
253 assoc->offset = 0;
254
255send_rsp:
256 /* Send A2MP Rsp when all fragments are received */
257 a2mp_send_getampassoc_rsp(hdev, rp->status);
258 a2mp_send_create_phy_link_req(hdev, rp->status);
259}
260
Andrei Emeltchenko903e4542012-09-27 17:26:09 +0300261void amp_read_loc_assoc_frag(struct hci_dev *hdev, u8 phy_handle)
262{
263 struct hci_cp_read_local_amp_assoc cp;
264 struct amp_assoc *loc_assoc = &hdev->loc_assoc;
Arron Wangb3d39142015-07-24 17:10:50 +0800265 struct hci_request req;
266 int err = 0;
Andrei Emeltchenko903e4542012-09-27 17:26:09 +0300267
268 BT_DBG("%s handle %d", hdev->name, phy_handle);
269
270 cp.phy_handle = phy_handle;
271 cp.max_len = cpu_to_le16(hdev->amp_assoc_size);
272 cp.len_so_far = cpu_to_le16(loc_assoc->offset);
273
Arron Wangb3d39142015-07-24 17:10:50 +0800274 hci_req_init(&req, hdev);
275 hci_req_add(&req, HCI_OP_READ_LOCAL_AMP_ASSOC, sizeof(cp), &cp);
276 err = hci_req_run_skb(&req, read_local_amp_assoc_complete);
277 if (err < 0)
278 a2mp_send_getampassoc_rsp(hdev, A2MP_STATUS_INVALID_CTRL_ID);
Andrei Emeltchenko903e4542012-09-27 17:26:09 +0300279}
280
281void amp_read_loc_assoc(struct hci_dev *hdev, struct amp_mgr *mgr)
282{
283 struct hci_cp_read_local_amp_assoc cp;
Arron Wangb3d39142015-07-24 17:10:50 +0800284 struct hci_request req;
285 int err = 0;
Andrei Emeltchenko903e4542012-09-27 17:26:09 +0300286
287 memset(&hdev->loc_assoc, 0, sizeof(struct amp_assoc));
288 memset(&cp, 0, sizeof(cp));
289
290 cp.max_len = cpu_to_le16(hdev->amp_assoc_size);
291
Andrei Emeltchenkocb6801c62012-12-07 14:59:08 +0200292 set_bit(READ_LOC_AMP_ASSOC, &mgr->state);
Arron Wangb3d39142015-07-24 17:10:50 +0800293 hci_req_init(&req, hdev);
294 hci_req_add(&req, HCI_OP_READ_LOCAL_AMP_ASSOC, sizeof(cp), &cp);
295 hci_req_run_skb(&req, read_local_amp_assoc_complete);
296 if (err < 0)
297 a2mp_send_getampassoc_rsp(hdev, A2MP_STATUS_INVALID_CTRL_ID);
Andrei Emeltchenko903e4542012-09-27 17:26:09 +0300298}
Andrei Emeltchenkoa02226d2012-09-27 17:26:19 +0300299
Andrei Emeltchenko9495b2e2012-09-27 17:26:22 +0300300void amp_read_loc_assoc_final_data(struct hci_dev *hdev,
301 struct hci_conn *hcon)
302{
303 struct hci_cp_read_local_amp_assoc cp;
304 struct amp_mgr *mgr = hcon->amp_mgr;
Arron Wangb3d39142015-07-24 17:10:50 +0800305 struct hci_request req;
306 int err = 0;
Andrei Emeltchenko9495b2e2012-09-27 17:26:22 +0300307
308 cp.phy_handle = hcon->handle;
309 cp.len_so_far = cpu_to_le16(0);
310 cp.max_len = cpu_to_le16(hdev->amp_assoc_size);
311
Andrei Emeltchenkocb6801c62012-12-07 14:59:08 +0200312 set_bit(READ_LOC_AMP_ASSOC_FINAL, &mgr->state);
Andrei Emeltchenko9495b2e2012-09-27 17:26:22 +0300313
314 /* Read Local AMP Assoc final link information data */
Arron Wangb3d39142015-07-24 17:10:50 +0800315 hci_req_init(&req, hdev);
316 hci_req_add(&req, HCI_OP_READ_LOCAL_AMP_ASSOC, sizeof(cp), &cp);
317 hci_req_run_skb(&req, read_local_amp_assoc_complete);
318 if (err < 0)
319 a2mp_send_getampassoc_rsp(hdev, A2MP_STATUS_INVALID_CTRL_ID);
320}
321
322static void write_remote_amp_assoc_complete(struct hci_dev *hdev, u8 status,
323 u16 opcode, struct sk_buff *skb)
324{
325 struct hci_rp_write_remote_amp_assoc *rp = (void *)skb->data;
326
327 BT_DBG("%s status 0x%2.2x phy_handle 0x%2.2x",
328 hdev->name, rp->status, rp->phy_handle);
329
330 if (rp->status)
331 return;
332
333 amp_write_rem_assoc_continue(hdev, rp->phy_handle);
Andrei Emeltchenko9495b2e2012-09-27 17:26:22 +0300334}
Andrei Emeltchenko93c284e2012-09-27 17:26:20 +0300335
336/* Write AMP Assoc data fragments, returns true with last fragment written*/
337static bool amp_write_rem_assoc_frag(struct hci_dev *hdev,
338 struct hci_conn *hcon)
339{
340 struct hci_cp_write_remote_amp_assoc *cp;
341 struct amp_mgr *mgr = hcon->amp_mgr;
342 struct amp_ctrl *ctrl;
Arron Wangb3d39142015-07-24 17:10:50 +0800343 struct hci_request req;
Andrei Emeltchenko93c284e2012-09-27 17:26:20 +0300344 u16 frag_len, len;
345
346 ctrl = amp_ctrl_lookup(mgr, hcon->remote_id);
347 if (!ctrl)
348 return false;
349
350 if (!ctrl->assoc_rem_len) {
351 BT_DBG("all fragments are written");
352 ctrl->assoc_rem_len = ctrl->assoc_len;
353 ctrl->assoc_len_so_far = 0;
354
355 amp_ctrl_put(ctrl);
356 return true;
357 }
358
359 frag_len = min_t(u16, 248, ctrl->assoc_rem_len);
360 len = frag_len + sizeof(*cp);
361
362 cp = kzalloc(len, GFP_KERNEL);
363 if (!cp) {
364 amp_ctrl_put(ctrl);
365 return false;
366 }
367
368 BT_DBG("hcon %p ctrl %p frag_len %u assoc_len %u rem_len %u",
369 hcon, ctrl, frag_len, ctrl->assoc_len, ctrl->assoc_rem_len);
370
371 cp->phy_handle = hcon->handle;
372 cp->len_so_far = cpu_to_le16(ctrl->assoc_len_so_far);
373 cp->rem_len = cpu_to_le16(ctrl->assoc_rem_len);
374 memcpy(cp->frag, ctrl->assoc, frag_len);
375
376 ctrl->assoc_len_so_far += frag_len;
377 ctrl->assoc_rem_len -= frag_len;
378
379 amp_ctrl_put(ctrl);
380
Arron Wangb3d39142015-07-24 17:10:50 +0800381 hci_req_init(&req, hdev);
382 hci_req_add(&req, HCI_OP_WRITE_REMOTE_AMP_ASSOC, sizeof(cp), &cp);
383 hci_req_run_skb(&req, write_remote_amp_assoc_complete);
Andrei Emeltchenko93c284e2012-09-27 17:26:20 +0300384
385 kfree(cp);
386
387 return false;
388}
389
390void amp_write_rem_assoc_continue(struct hci_dev *hdev, u8 handle)
391{
392 struct hci_conn *hcon;
393
394 BT_DBG("%s phy handle 0x%2.2x", hdev->name, handle);
395
396 hcon = hci_conn_hash_lookup_handle(hdev, handle);
397 if (!hcon)
398 return;
399
Andrei Emeltchenko8e05e3b2012-12-07 14:59:05 +0200400 /* Send A2MP create phylink rsp when all fragments are written */
401 if (amp_write_rem_assoc_frag(hdev, hcon))
402 a2mp_send_create_phy_link_rsp(hdev, 0);
Andrei Emeltchenko93c284e2012-09-27 17:26:20 +0300403}
404
405void amp_write_remote_assoc(struct hci_dev *hdev, u8 handle)
406{
407 struct hci_conn *hcon;
408
409 BT_DBG("%s phy handle 0x%2.2x", hdev->name, handle);
410
411 hcon = hci_conn_hash_lookup_handle(hdev, handle);
412 if (!hcon)
413 return;
414
415 BT_DBG("%s phy handle 0x%2.2x hcon %p", hdev->name, handle, hcon);
416
417 amp_write_rem_assoc_frag(hdev, hcon);
418}
419
Andrei Emeltchenkoa02226d2012-09-27 17:26:19 +0300420void amp_create_phylink(struct hci_dev *hdev, struct amp_mgr *mgr,
421 struct hci_conn *hcon)
422{
423 struct hci_cp_create_phy_link cp;
424
425 cp.phy_handle = hcon->handle;
426
427 BT_DBG("%s hcon %p phy handle 0x%2.2x", hdev->name, hcon,
428 hcon->handle);
429
430 if (phylink_gen_key(mgr->l2cap_conn->hcon, cp.key, &cp.key_len,
431 &cp.key_type)) {
432 BT_DBG("Cannot create link key");
433 return;
434 }
435
436 hci_send_cmd(hdev, HCI_OP_CREATE_PHY_LINK, sizeof(cp), &cp);
437}
Andrei Emeltchenkodffa3872012-09-27 17:26:23 +0300438
439void amp_accept_phylink(struct hci_dev *hdev, struct amp_mgr *mgr,
440 struct hci_conn *hcon)
441{
442 struct hci_cp_accept_phy_link cp;
443
444 cp.phy_handle = hcon->handle;
445
446 BT_DBG("%s hcon %p phy handle 0x%2.2x", hdev->name, hcon,
447 hcon->handle);
448
449 if (phylink_gen_key(mgr->l2cap_conn->hcon, cp.key, &cp.key_len,
450 &cp.key_type)) {
451 BT_DBG("Cannot create link key");
452 return;
453 }
454
455 hci_send_cmd(hdev, HCI_OP_ACCEPT_PHY_LINK, sizeof(cp), &cp);
456}
Andrei Emeltchenko5ce66b52012-10-31 15:46:30 +0200457
Andrei Emeltchenkocf70ff22012-10-31 15:46:36 +0200458void amp_physical_cfm(struct hci_conn *bredr_hcon, struct hci_conn *hs_hcon)
459{
460 struct hci_dev *bredr_hdev = hci_dev_hold(bredr_hcon->hdev);
461 struct amp_mgr *mgr = hs_hcon->amp_mgr;
462 struct l2cap_chan *bredr_chan;
463
464 BT_DBG("bredr_hcon %p hs_hcon %p mgr %p", bredr_hcon, hs_hcon, mgr);
465
466 if (!bredr_hdev || !mgr || !mgr->bredr_chan)
467 return;
468
469 bredr_chan = mgr->bredr_chan;
470
Andrei Emeltchenkoa514b172012-11-14 17:39:30 +0200471 l2cap_chan_lock(bredr_chan);
472
Andrei Emeltchenkocf70ff22012-10-31 15:46:36 +0200473 set_bit(FLAG_EFS_ENABLE, &bredr_chan->flags);
Andrei Emeltchenkofffadc02012-11-01 15:37:03 +0200474 bredr_chan->remote_amp_id = hs_hcon->remote_id;
Andrei Emeltchenko37295992012-11-20 17:16:20 +0200475 bredr_chan->local_amp_id = hs_hcon->hdev->id;
Andrei Emeltchenkocf70ff22012-10-31 15:46:36 +0200476 bredr_chan->hs_hcon = hs_hcon;
477 bredr_chan->conn->mtu = hs_hcon->hdev->block_mtu;
Andrei Emeltchenkocf70ff22012-10-31 15:46:36 +0200478
Andrei Emeltchenkoa514b172012-11-14 17:39:30 +0200479 __l2cap_physical_cfm(bredr_chan, 0);
480
481 l2cap_chan_unlock(bredr_chan);
Andrei Emeltchenkocf70ff22012-10-31 15:46:36 +0200482
483 hci_dev_put(bredr_hdev);
484}
485
Andrei Emeltchenko5ce66b52012-10-31 15:46:30 +0200486void amp_create_logical_link(struct l2cap_chan *chan)
487{
Andrei Emeltchenko7a9898c2012-12-07 14:59:06 +0200488 struct hci_conn *hs_hcon = chan->hs_hcon;
Andrei Emeltchenko5ce66b52012-10-31 15:46:30 +0200489 struct hci_cp_create_accept_logical_link cp;
Andrei Emeltchenko5ce66b52012-10-31 15:46:30 +0200490 struct hci_dev *hdev;
491
Marcel Holtmannbdc8ead22013-10-13 02:23:38 -0700492 BT_DBG("chan %p hs_hcon %p dst %pMR", chan, hs_hcon,
493 &chan->conn->hcon->dst);
Andrei Emeltchenko5ce66b52012-10-31 15:46:30 +0200494
Andrei Emeltchenko7a9898c2012-12-07 14:59:06 +0200495 if (!hs_hcon)
Andrei Emeltchenko5ce66b52012-10-31 15:46:30 +0200496 return;
497
498 hdev = hci_dev_hold(chan->hs_hcon->hdev);
499 if (!hdev)
500 return;
501
Andrei Emeltchenko7a9898c2012-12-07 14:59:06 +0200502 cp.phy_handle = hs_hcon->handle;
Andrei Emeltchenko5ce66b52012-10-31 15:46:30 +0200503
504 cp.tx_flow_spec.id = chan->local_id;
505 cp.tx_flow_spec.stype = chan->local_stype;
506 cp.tx_flow_spec.msdu = cpu_to_le16(chan->local_msdu);
507 cp.tx_flow_spec.sdu_itime = cpu_to_le32(chan->local_sdu_itime);
508 cp.tx_flow_spec.acc_lat = cpu_to_le32(chan->local_acc_lat);
509 cp.tx_flow_spec.flush_to = cpu_to_le32(chan->local_flush_to);
510
511 cp.rx_flow_spec.id = chan->remote_id;
512 cp.rx_flow_spec.stype = chan->remote_stype;
513 cp.rx_flow_spec.msdu = cpu_to_le16(chan->remote_msdu);
514 cp.rx_flow_spec.sdu_itime = cpu_to_le32(chan->remote_sdu_itime);
515 cp.rx_flow_spec.acc_lat = cpu_to_le32(chan->remote_acc_lat);
516 cp.rx_flow_spec.flush_to = cpu_to_le32(chan->remote_flush_to);
517
Andrei Emeltchenko7a9898c2012-12-07 14:59:06 +0200518 if (hs_hcon->out)
Andrei Emeltchenko5ce66b52012-10-31 15:46:30 +0200519 hci_send_cmd(hdev, HCI_OP_CREATE_LOGICAL_LINK, sizeof(cp),
520 &cp);
521 else
522 hci_send_cmd(hdev, HCI_OP_ACCEPT_LOGICAL_LINK, sizeof(cp),
523 &cp);
524
Andrei Emeltchenko5ce66b52012-10-31 15:46:30 +0200525 hci_dev_put(hdev);
526}
Andrei Emeltchenko606e2a12012-10-31 15:46:31 +0200527
Andrei Emeltchenko419e08c2012-10-31 15:46:34 +0200528void amp_disconnect_logical_link(struct hci_chan *hchan)
529{
530 struct hci_conn *hcon = hchan->conn;
531 struct hci_cp_disconn_logical_link cp;
532
533 if (hcon->state != BT_CONNECTED) {
534 BT_DBG("hchan %p not connected", hchan);
535 return;
536 }
537
538 cp.log_handle = cpu_to_le16(hchan->handle);
539 hci_send_cmd(hcon->hdev, HCI_OP_DISCONN_LOGICAL_LINK, sizeof(cp), &cp);
540}
541
Andrei Emeltchenko606e2a12012-10-31 15:46:31 +0200542void amp_destroy_logical_link(struct hci_chan *hchan, u8 reason)
543{
544 BT_DBG("hchan %p", hchan);
545
546 hci_chan_del(hchan);
547}