2 Copyright (c) 2010,2011 Code Aurora Forum. All rights reserved.
3 Copyright (c) 2011,2012 Intel Corp.
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 and
7 only version 2 as published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
15 #include <net/bluetooth/bluetooth.h>
16 #include <net/bluetooth/hci_core.h>
17 #include <net/bluetooth/l2cap.h>
22 /* Global AMP Manager list */
23 LIST_HEAD(amp_mgr_list
);
24 DEFINE_MUTEX(amp_mgr_list_lock
);
26 /* A2MP build & send command helper functions */
27 static struct a2mp_cmd
*__a2mp_build(u8 code
, u8 ident
, u16 len
, void *data
)
32 plen
= sizeof(*cmd
) + len
;
33 cmd
= kzalloc(plen
, GFP_KERNEL
);
39 cmd
->len
= cpu_to_le16(len
);
41 memcpy(cmd
->data
, data
, len
);
46 void a2mp_send(struct amp_mgr
*mgr
, u8 code
, u8 ident
, u16 len
, void *data
)
48 struct l2cap_chan
*chan
= mgr
->a2mp_chan
;
50 u16 total_len
= len
+ sizeof(*cmd
);
54 cmd
= __a2mp_build(code
, ident
, len
, data
);
59 iv
.iov_len
= total_len
;
61 memset(&msg
, 0, sizeof(msg
));
63 msg
.msg_iov
= (struct iovec
*) &iv
;
66 l2cap_chan_send(chan
, &msg
, total_len
, 0);
71 u8
__next_ident(struct amp_mgr
*mgr
)
73 if (++mgr
->ident
== 0)
79 /* hci_dev_list shall be locked */
80 static void __a2mp_add_cl(struct amp_mgr
*mgr
, struct a2mp_cl
*cl
)
85 cl
[0].id
= AMP_ID_BREDR
;
86 cl
[0].type
= AMP_TYPE_BREDR
;
87 cl
[0].status
= AMP_STATUS_BLUETOOTH_ONLY
;
89 list_for_each_entry(hdev
, &hci_dev_list
, list
) {
90 if (hdev
->dev_type
== HCI_AMP
) {
92 cl
[i
].type
= hdev
->amp_type
;
93 if (test_bit(HCI_UP
, &hdev
->flags
))
94 cl
[i
].status
= hdev
->amp_status
;
96 cl
[i
].status
= AMP_STATUS_POWERED_DOWN
;
102 /* Processing A2MP messages */
103 static int a2mp_command_rej(struct amp_mgr
*mgr
, struct sk_buff
*skb
,
104 struct a2mp_cmd
*hdr
)
106 struct a2mp_cmd_rej
*rej
= (void *) skb
->data
;
108 if (le16_to_cpu(hdr
->len
) < sizeof(*rej
))
111 BT_DBG("ident %d reason %d", hdr
->ident
, le16_to_cpu(rej
->reason
));
113 skb_pull(skb
, sizeof(*rej
));
118 static int a2mp_discover_req(struct amp_mgr
*mgr
, struct sk_buff
*skb
,
119 struct a2mp_cmd
*hdr
)
121 struct a2mp_discov_req
*req
= (void *) skb
->data
;
122 u16 len
= le16_to_cpu(hdr
->len
);
123 struct a2mp_discov_rsp
*rsp
;
126 struct hci_dev
*hdev
;
128 if (len
< sizeof(*req
))
131 skb_pull(skb
, sizeof(*req
));
133 ext_feat
= le16_to_cpu(req
->ext_feat
);
135 BT_DBG("mtu %d efm 0x%4.4x", le16_to_cpu(req
->mtu
), ext_feat
);
137 /* check that packet is not broken for now */
138 while (ext_feat
& A2MP_FEAT_EXT
) {
139 if (len
< sizeof(ext_feat
))
142 ext_feat
= get_unaligned_le16(skb
->data
);
143 BT_DBG("efm 0x%4.4x", ext_feat
);
144 len
-= sizeof(ext_feat
);
145 skb_pull(skb
, sizeof(ext_feat
));
148 read_lock(&hci_dev_list_lock
);
150 /* at minimum the BR/EDR needs to be listed */
153 list_for_each_entry(hdev
, &hci_dev_list
, list
) {
154 if (hdev
->dev_type
== HCI_AMP
)
158 len
= num_ctrl
* sizeof(struct a2mp_cl
) + sizeof(*rsp
);
159 rsp
= kmalloc(len
, GFP_ATOMIC
);
161 read_unlock(&hci_dev_list_lock
);
165 rsp
->mtu
= __constant_cpu_to_le16(L2CAP_A2MP_DEFAULT_MTU
);
168 __a2mp_add_cl(mgr
, rsp
->cl
);
170 read_unlock(&hci_dev_list_lock
);
172 a2mp_send(mgr
, A2MP_DISCOVER_RSP
, hdr
->ident
, len
, rsp
);
178 static int a2mp_discover_rsp(struct amp_mgr
*mgr
, struct sk_buff
*skb
,
179 struct a2mp_cmd
*hdr
)
181 struct a2mp_discov_rsp
*rsp
= (void *) skb
->data
;
182 u16 len
= le16_to_cpu(hdr
->len
);
187 if (len
< sizeof(*rsp
))
191 skb_pull(skb
, sizeof(*rsp
));
193 ext_feat
= le16_to_cpu(rsp
->ext_feat
);
195 BT_DBG("mtu %d efm 0x%4.4x", le16_to_cpu(rsp
->mtu
), ext_feat
);
197 /* check that packet is not broken for now */
198 while (ext_feat
& A2MP_FEAT_EXT
) {
199 if (len
< sizeof(ext_feat
))
202 ext_feat
= get_unaligned_le16(skb
->data
);
203 BT_DBG("efm 0x%4.4x", ext_feat
);
204 len
-= sizeof(ext_feat
);
205 skb_pull(skb
, sizeof(ext_feat
));
208 cl
= (void *) skb
->data
;
209 while (len
>= sizeof(*cl
)) {
210 BT_DBG("Remote AMP id %d type %d status %d", cl
->id
, cl
->type
,
213 if (cl
->id
!= AMP_ID_BREDR
&& cl
->type
!= AMP_TYPE_BREDR
) {
214 struct a2mp_info_req req
;
218 a2mp_send(mgr
, A2MP_GETINFO_REQ
, __next_ident(mgr
),
223 cl
= (void *) skb_pull(skb
, sizeof(*cl
));
226 /* Fall back to L2CAP init sequence */
228 struct l2cap_conn
*conn
= mgr
->l2cap_conn
;
229 struct l2cap_chan
*chan
;
231 mutex_lock(&conn
->chan_lock
);
233 list_for_each_entry(chan
, &conn
->chan_l
, list
) {
235 BT_DBG("chan %p state %s", chan
,
236 state_to_string(chan
->state
));
238 if (chan
->chan_type
== L2CAP_CHAN_CONN_FIX_A2MP
)
241 l2cap_chan_lock(chan
);
243 if (chan
->state
== BT_CONNECT
)
244 l2cap_send_conn_req(chan
);
246 l2cap_chan_unlock(chan
);
249 mutex_unlock(&conn
->chan_lock
);
255 static int a2mp_change_notify(struct amp_mgr
*mgr
, struct sk_buff
*skb
,
256 struct a2mp_cmd
*hdr
)
258 struct a2mp_cl
*cl
= (void *) skb
->data
;
260 while (skb
->len
>= sizeof(*cl
)) {
261 BT_DBG("Controller id %d type %d status %d", cl
->id
, cl
->type
,
263 cl
= (struct a2mp_cl
*) skb_pull(skb
, sizeof(*cl
));
266 /* TODO send A2MP_CHANGE_RSP */
271 static int a2mp_getinfo_req(struct amp_mgr
*mgr
, struct sk_buff
*skb
,
272 struct a2mp_cmd
*hdr
)
274 struct a2mp_info_req
*req
= (void *) skb
->data
;
275 struct hci_dev
*hdev
;
277 if (le16_to_cpu(hdr
->len
) < sizeof(*req
))
280 BT_DBG("id %d", req
->id
);
282 hdev
= hci_dev_get(req
->id
);
283 if (!hdev
|| hdev
->dev_type
!= HCI_AMP
) {
284 struct a2mp_info_rsp rsp
;
287 rsp
.status
= A2MP_STATUS_INVALID_CTRL_ID
;
289 a2mp_send(mgr
, A2MP_GETINFO_RSP
, hdr
->ident
, sizeof(rsp
),
295 set_bit(READ_LOC_AMP_INFO
, &mgr
->state
);
296 hci_send_cmd(hdev
, HCI_OP_READ_LOCAL_AMP_INFO
, 0, NULL
);
302 skb_pull(skb
, sizeof(*req
));
306 static int a2mp_getinfo_rsp(struct amp_mgr
*mgr
, struct sk_buff
*skb
,
307 struct a2mp_cmd
*hdr
)
309 struct a2mp_info_rsp
*rsp
= (struct a2mp_info_rsp
*) skb
->data
;
310 struct a2mp_amp_assoc_req req
;
311 struct amp_ctrl
*ctrl
;
313 if (le16_to_cpu(hdr
->len
) < sizeof(*rsp
))
316 BT_DBG("id %d status 0x%2.2x", rsp
->id
, rsp
->status
);
321 ctrl
= amp_ctrl_add(mgr
, rsp
->id
);
326 a2mp_send(mgr
, A2MP_GETAMPASSOC_REQ
, __next_ident(mgr
), sizeof(req
),
329 skb_pull(skb
, sizeof(*rsp
));
333 static int a2mp_getampassoc_req(struct amp_mgr
*mgr
, struct sk_buff
*skb
,
334 struct a2mp_cmd
*hdr
)
336 struct a2mp_amp_assoc_req
*req
= (void *) skb
->data
;
337 struct hci_dev
*hdev
;
340 if (le16_to_cpu(hdr
->len
) < sizeof(*req
))
343 BT_DBG("id %d", req
->id
);
345 /* Make sure that other request is not processed */
346 tmp
= amp_mgr_lookup_by_state(READ_LOC_AMP_ASSOC
);
348 hdev
= hci_dev_get(req
->id
);
349 if (!hdev
|| hdev
->amp_type
== AMP_TYPE_BREDR
|| tmp
) {
350 struct a2mp_amp_assoc_rsp rsp
;
354 rsp
.status
= A2MP_STATUS_COLLISION_OCCURED
;
357 rsp
.status
= A2MP_STATUS_INVALID_CTRL_ID
;
360 a2mp_send(mgr
, A2MP_GETAMPASSOC_RSP
, hdr
->ident
, sizeof(rsp
),
366 amp_read_loc_assoc(hdev
, mgr
);
372 skb_pull(skb
, sizeof(*req
));
376 static int a2mp_getampassoc_rsp(struct amp_mgr
*mgr
, struct sk_buff
*skb
,
377 struct a2mp_cmd
*hdr
)
379 struct a2mp_amp_assoc_rsp
*rsp
= (void *) skb
->data
;
380 u16 len
= le16_to_cpu(hdr
->len
);
381 struct hci_dev
*hdev
;
382 struct amp_ctrl
*ctrl
;
383 struct hci_conn
*hcon
;
386 if (len
< sizeof(*rsp
))
389 assoc_len
= len
- sizeof(*rsp
);
391 BT_DBG("id %d status 0x%2.2x assoc len %zu", rsp
->id
, rsp
->status
,
397 /* Save remote ASSOC data */
398 ctrl
= amp_ctrl_lookup(mgr
, rsp
->id
);
402 assoc
= kmemdup(rsp
->amp_assoc
, assoc_len
, GFP_KERNEL
);
409 ctrl
->assoc_len
= assoc_len
;
410 ctrl
->assoc_rem_len
= assoc_len
;
411 ctrl
->assoc_len_so_far
= 0;
416 /* Create Phys Link */
417 hdev
= hci_dev_get(rsp
->id
);
421 hcon
= phylink_add(hdev
, mgr
, rsp
->id
, true);
425 BT_DBG("Created hcon %p: loc:%d -> rem:%d", hcon
, hdev
->id
, rsp
->id
);
427 mgr
->bredr_chan
->remote_amp_id
= rsp
->id
;
429 amp_create_phylink(hdev
, mgr
, hcon
);
437 static int a2mp_createphyslink_req(struct amp_mgr
*mgr
, struct sk_buff
*skb
,
438 struct a2mp_cmd
*hdr
)
440 struct a2mp_physlink_req
*req
= (void *) skb
->data
;
442 struct a2mp_physlink_rsp rsp
;
443 struct hci_dev
*hdev
;
444 struct hci_conn
*hcon
;
445 struct amp_ctrl
*ctrl
;
447 if (le16_to_cpu(hdr
->len
) < sizeof(*req
))
450 BT_DBG("local_id %d, remote_id %d", req
->local_id
, req
->remote_id
);
452 rsp
.local_id
= req
->remote_id
;
453 rsp
.remote_id
= req
->local_id
;
455 hdev
= hci_dev_get(req
->remote_id
);
456 if (!hdev
|| hdev
->amp_type
== AMP_TYPE_BREDR
) {
457 rsp
.status
= A2MP_STATUS_INVALID_CTRL_ID
;
461 ctrl
= amp_ctrl_lookup(mgr
, rsp
.remote_id
);
463 ctrl
= amp_ctrl_add(mgr
, rsp
.remote_id
);
467 rsp
.status
= A2MP_STATUS_UNABLE_START_LINK_CREATION
;
473 size_t assoc_len
= le16_to_cpu(hdr
->len
) - sizeof(*req
);
476 assoc
= kmemdup(req
->amp_assoc
, assoc_len
, GFP_KERNEL
);
483 ctrl
->assoc_len
= assoc_len
;
484 ctrl
->assoc_rem_len
= assoc_len
;
485 ctrl
->assoc_len_so_far
= 0;
490 hcon
= phylink_add(hdev
, mgr
, req
->local_id
, false);
492 amp_accept_phylink(hdev
, mgr
, hcon
);
493 rsp
.status
= A2MP_STATUS_SUCCESS
;
495 rsp
.status
= A2MP_STATUS_UNABLE_START_LINK_CREATION
;
502 /* Reply error now and success after HCI Write Remote AMP Assoc
503 command complete with success status
505 if (rsp
.status
!= A2MP_STATUS_SUCCESS
) {
506 a2mp_send(mgr
, A2MP_CREATEPHYSLINK_RSP
, hdr
->ident
,
509 set_bit(WRITE_REMOTE_AMP_ASSOC
, &mgr
->state
);
510 mgr
->ident
= hdr
->ident
;
513 skb_pull(skb
, le16_to_cpu(hdr
->len
));
517 static int a2mp_discphyslink_req(struct amp_mgr
*mgr
, struct sk_buff
*skb
,
518 struct a2mp_cmd
*hdr
)
520 struct a2mp_physlink_req
*req
= (void *) skb
->data
;
521 struct a2mp_physlink_rsp rsp
;
522 struct hci_dev
*hdev
;
523 struct hci_conn
*hcon
;
525 if (le16_to_cpu(hdr
->len
) < sizeof(*req
))
528 BT_DBG("local_id %d remote_id %d", req
->local_id
, req
->remote_id
);
530 rsp
.local_id
= req
->remote_id
;
531 rsp
.remote_id
= req
->local_id
;
532 rsp
.status
= A2MP_STATUS_SUCCESS
;
534 hdev
= hci_dev_get(req
->remote_id
);
536 rsp
.status
= A2MP_STATUS_INVALID_CTRL_ID
;
540 hcon
= hci_conn_hash_lookup_ba(hdev
, AMP_LINK
,
541 &mgr
->l2cap_conn
->hcon
->dst
);
543 BT_ERR("No phys link exist");
544 rsp
.status
= A2MP_STATUS_NO_PHYSICAL_LINK_EXISTS
;
548 /* TODO Disconnect Phys Link here */
554 a2mp_send(mgr
, A2MP_DISCONNPHYSLINK_RSP
, hdr
->ident
, sizeof(rsp
), &rsp
);
556 skb_pull(skb
, sizeof(*req
));
560 static inline int a2mp_cmd_rsp(struct amp_mgr
*mgr
, struct sk_buff
*skb
,
561 struct a2mp_cmd
*hdr
)
563 BT_DBG("ident %d code 0x%2.2x", hdr
->ident
, hdr
->code
);
565 skb_pull(skb
, le16_to_cpu(hdr
->len
));
569 /* Handle A2MP signalling */
570 static int a2mp_chan_recv_cb(struct l2cap_chan
*chan
, struct sk_buff
*skb
)
572 struct a2mp_cmd
*hdr
;
573 struct amp_mgr
*mgr
= chan
->data
;
578 while (skb
->len
>= sizeof(*hdr
)) {
581 hdr
= (void *) skb
->data
;
582 len
= le16_to_cpu(hdr
->len
);
584 BT_DBG("code 0x%2.2x id %d len %u", hdr
->code
, hdr
->ident
, len
);
586 skb_pull(skb
, sizeof(*hdr
));
588 if (len
> skb
->len
|| !hdr
->ident
) {
593 mgr
->ident
= hdr
->ident
;
596 case A2MP_COMMAND_REJ
:
597 a2mp_command_rej(mgr
, skb
, hdr
);
600 case A2MP_DISCOVER_REQ
:
601 err
= a2mp_discover_req(mgr
, skb
, hdr
);
604 case A2MP_CHANGE_NOTIFY
:
605 err
= a2mp_change_notify(mgr
, skb
, hdr
);
608 case A2MP_GETINFO_REQ
:
609 err
= a2mp_getinfo_req(mgr
, skb
, hdr
);
612 case A2MP_GETAMPASSOC_REQ
:
613 err
= a2mp_getampassoc_req(mgr
, skb
, hdr
);
616 case A2MP_CREATEPHYSLINK_REQ
:
617 err
= a2mp_createphyslink_req(mgr
, skb
, hdr
);
620 case A2MP_DISCONNPHYSLINK_REQ
:
621 err
= a2mp_discphyslink_req(mgr
, skb
, hdr
);
624 case A2MP_DISCOVER_RSP
:
625 err
= a2mp_discover_rsp(mgr
, skb
, hdr
);
628 case A2MP_GETINFO_RSP
:
629 err
= a2mp_getinfo_rsp(mgr
, skb
, hdr
);
632 case A2MP_GETAMPASSOC_RSP
:
633 err
= a2mp_getampassoc_rsp(mgr
, skb
, hdr
);
636 case A2MP_CHANGE_RSP
:
637 case A2MP_CREATEPHYSLINK_RSP
:
638 case A2MP_DISCONNPHYSLINK_RSP
:
639 err
= a2mp_cmd_rsp(mgr
, skb
, hdr
);
643 BT_ERR("Unknown A2MP sig cmd 0x%2.2x", hdr
->code
);
650 struct a2mp_cmd_rej rej
;
652 rej
.reason
= __constant_cpu_to_le16(0);
653 hdr
= (void *) skb
->data
;
655 BT_DBG("Send A2MP Rej: cmd 0x%2.2x err %d", hdr
->code
, err
);
657 a2mp_send(mgr
, A2MP_COMMAND_REJ
, hdr
->ident
, sizeof(rej
),
661 /* Always free skb and return success error code to prevent
662 from sending L2CAP Disconnect over A2MP channel */
670 static void a2mp_chan_close_cb(struct l2cap_chan
*chan
)
672 l2cap_chan_put(chan
);
675 static void a2mp_chan_state_change_cb(struct l2cap_chan
*chan
, int state
,
678 struct amp_mgr
*mgr
= chan
->data
;
683 BT_DBG("chan %p state %s", chan
, state_to_string(state
));
695 static struct sk_buff
*a2mp_chan_alloc_skb_cb(struct l2cap_chan
*chan
,
696 unsigned long len
, int nb
)
698 return bt_skb_alloc(len
, GFP_KERNEL
);
701 static struct l2cap_ops a2mp_chan_ops
= {
702 .name
= "L2CAP A2MP channel",
703 .recv
= a2mp_chan_recv_cb
,
704 .close
= a2mp_chan_close_cb
,
705 .state_change
= a2mp_chan_state_change_cb
,
706 .alloc_skb
= a2mp_chan_alloc_skb_cb
,
708 /* Not implemented for A2MP */
709 .new_connection
= l2cap_chan_no_new_connection
,
710 .teardown
= l2cap_chan_no_teardown
,
711 .ready
= l2cap_chan_no_ready
,
712 .defer
= l2cap_chan_no_defer
,
713 .resume
= l2cap_chan_no_resume
,
714 .set_shutdown
= l2cap_chan_no_set_shutdown
,
715 .get_sndtimeo
= l2cap_chan_no_get_sndtimeo
,
718 static struct l2cap_chan
*a2mp_chan_open(struct l2cap_conn
*conn
, bool locked
)
720 struct l2cap_chan
*chan
;
723 chan
= l2cap_chan_create();
727 BT_DBG("chan %p", chan
);
729 chan
->chan_type
= L2CAP_CHAN_CONN_FIX_A2MP
;
730 chan
->flush_to
= L2CAP_DEFAULT_FLUSH_TO
;
732 chan
->ops
= &a2mp_chan_ops
;
734 l2cap_chan_set_defaults(chan
);
735 chan
->remote_max_tx
= chan
->max_tx
;
736 chan
->remote_tx_win
= chan
->tx_win
;
738 chan
->retrans_timeout
= L2CAP_DEFAULT_RETRANS_TO
;
739 chan
->monitor_timeout
= L2CAP_DEFAULT_MONITOR_TO
;
741 skb_queue_head_init(&chan
->tx_q
);
743 chan
->mode
= L2CAP_MODE_ERTM
;
745 err
= l2cap_ertm_init(chan
);
747 l2cap_chan_del(chan
, 0);
751 chan
->conf_state
= 0;
754 __l2cap_chan_add(conn
, chan
);
756 l2cap_chan_add(conn
, chan
);
758 chan
->remote_mps
= chan
->omtu
;
759 chan
->mps
= chan
->omtu
;
761 chan
->state
= BT_CONNECTED
;
766 /* AMP Manager functions */
767 struct amp_mgr
*amp_mgr_get(struct amp_mgr
*mgr
)
769 BT_DBG("mgr %p orig refcnt %d", mgr
, atomic_read(&mgr
->kref
.refcount
));
771 kref_get(&mgr
->kref
);
776 static void amp_mgr_destroy(struct kref
*kref
)
778 struct amp_mgr
*mgr
= container_of(kref
, struct amp_mgr
, kref
);
780 BT_DBG("mgr %p", mgr
);
782 mutex_lock(&_mgr_list_lock
);
783 list_del(&mgr
->list
);
784 mutex_unlock(&_mgr_list_lock
);
786 amp_ctrl_list_flush(mgr
);
790 int amp_mgr_put(struct amp_mgr
*mgr
)
792 BT_DBG("mgr %p orig refcnt %d", mgr
, atomic_read(&mgr
->kref
.refcount
));
794 return kref_put(&mgr
->kref
, &_mgr_destroy
);
797 static struct amp_mgr
*amp_mgr_create(struct l2cap_conn
*conn
, bool locked
)
800 struct l2cap_chan
*chan
;
802 mgr
= kzalloc(sizeof(*mgr
), GFP_KERNEL
);
806 BT_DBG("conn %p mgr %p", conn
, mgr
);
808 mgr
->l2cap_conn
= conn
;
810 chan
= a2mp_chan_open(conn
, locked
);
816 mgr
->a2mp_chan
= chan
;
819 conn
->hcon
->amp_mgr
= mgr
;
821 kref_init(&mgr
->kref
);
823 /* Remote AMP ctrl list initialization */
824 INIT_LIST_HEAD(&mgr
->amp_ctrls
);
825 mutex_init(&mgr
->amp_ctrls_lock
);
827 mutex_lock(&_mgr_list_lock
);
828 list_add(&mgr
->list
, &_mgr_list
);
829 mutex_unlock(&_mgr_list_lock
);
834 struct l2cap_chan
*a2mp_channel_create(struct l2cap_conn
*conn
,
839 if (conn
->hcon
->type
!= ACL_LINK
)
842 mgr
= amp_mgr_create(conn
, false);
844 BT_ERR("Could not create AMP manager");
848 BT_DBG("mgr: %p chan %p", mgr
, mgr
->a2mp_chan
);
850 return mgr
->a2mp_chan
;
853 struct amp_mgr
*amp_mgr_lookup_by_state(u8 state
)
857 mutex_lock(&_mgr_list_lock
);
858 list_for_each_entry(mgr
, &_mgr_list
, list
) {
859 if (test_and_clear_bit(state
, &mgr
->state
)) {
861 mutex_unlock(&_mgr_list_lock
);
865 mutex_unlock(&_mgr_list_lock
);
870 void a2mp_send_getinfo_rsp(struct hci_dev
*hdev
)
873 struct a2mp_info_rsp rsp
;
875 mgr
= amp_mgr_lookup_by_state(READ_LOC_AMP_INFO
);
879 BT_DBG("%s mgr %p", hdev
->name
, mgr
);
882 rsp
.status
= A2MP_STATUS_INVALID_CTRL_ID
;
884 if (hdev
->amp_type
!= AMP_TYPE_BREDR
) {
886 rsp
.total_bw
= cpu_to_le32(hdev
->amp_total_bw
);
887 rsp
.max_bw
= cpu_to_le32(hdev
->amp_max_bw
);
888 rsp
.min_latency
= cpu_to_le32(hdev
->amp_min_latency
);
889 rsp
.pal_cap
= cpu_to_le16(hdev
->amp_pal_cap
);
890 rsp
.assoc_size
= cpu_to_le16(hdev
->amp_assoc_size
);
893 a2mp_send(mgr
, A2MP_GETINFO_RSP
, mgr
->ident
, sizeof(rsp
), &rsp
);
897 void a2mp_send_getampassoc_rsp(struct hci_dev
*hdev
, u8 status
)
900 struct amp_assoc
*loc_assoc
= &hdev
->loc_assoc
;
901 struct a2mp_amp_assoc_rsp
*rsp
;
904 mgr
= amp_mgr_lookup_by_state(READ_LOC_AMP_ASSOC
);
908 BT_DBG("%s mgr %p", hdev
->name
, mgr
);
910 len
= sizeof(struct a2mp_amp_assoc_rsp
) + loc_assoc
->len
;
911 rsp
= kzalloc(len
, GFP_KERNEL
);
920 rsp
->status
= A2MP_STATUS_INVALID_CTRL_ID
;
922 rsp
->status
= A2MP_STATUS_SUCCESS
;
923 memcpy(rsp
->amp_assoc
, loc_assoc
->data
, loc_assoc
->len
);
926 a2mp_send(mgr
, A2MP_GETAMPASSOC_RSP
, mgr
->ident
, len
, rsp
);
931 void a2mp_send_create_phy_link_req(struct hci_dev
*hdev
, u8 status
)
934 struct amp_assoc
*loc_assoc
= &hdev
->loc_assoc
;
935 struct a2mp_physlink_req
*req
;
936 struct l2cap_chan
*bredr_chan
;
939 mgr
= amp_mgr_lookup_by_state(READ_LOC_AMP_ASSOC_FINAL
);
943 len
= sizeof(*req
) + loc_assoc
->len
;
945 BT_DBG("%s mgr %p assoc_len %zu", hdev
->name
, mgr
, len
);
947 req
= kzalloc(len
, GFP_KERNEL
);
953 bredr_chan
= mgr
->bredr_chan
;
957 req
->local_id
= hdev
->id
;
958 req
->remote_id
= bredr_chan
->remote_amp_id
;
959 memcpy(req
->amp_assoc
, loc_assoc
->data
, loc_assoc
->len
);
961 a2mp_send(mgr
, A2MP_CREATEPHYSLINK_REQ
, __next_ident(mgr
), len
, req
);
968 void a2mp_send_create_phy_link_rsp(struct hci_dev
*hdev
, u8 status
)
971 struct a2mp_physlink_rsp rsp
;
972 struct hci_conn
*hs_hcon
;
974 mgr
= amp_mgr_lookup_by_state(WRITE_REMOTE_AMP_ASSOC
);
978 hs_hcon
= hci_conn_hash_lookup_state(hdev
, AMP_LINK
, BT_CONNECT
);
980 rsp
.status
= A2MP_STATUS_UNABLE_START_LINK_CREATION
;
982 rsp
.remote_id
= hs_hcon
->remote_id
;
983 rsp
.status
= A2MP_STATUS_SUCCESS
;
986 BT_DBG("%s mgr %p hs_hcon %p status %u", hdev
->name
, mgr
, hs_hcon
,
989 rsp
.local_id
= hdev
->id
;
990 a2mp_send(mgr
, A2MP_CREATEPHYSLINK_RSP
, mgr
->ident
, sizeof(rsp
), &rsp
);
994 void a2mp_discover_amp(struct l2cap_chan
*chan
)
996 struct l2cap_conn
*conn
= chan
->conn
;
997 struct amp_mgr
*mgr
= conn
->hcon
->amp_mgr
;
998 struct a2mp_discov_req req
;
1000 BT_DBG("chan %p conn %p mgr %p", chan
, conn
, mgr
);
1003 mgr
= amp_mgr_create(conn
, true);
1008 mgr
->bredr_chan
= chan
;
1010 req
.mtu
= cpu_to_le16(L2CAP_A2MP_DEFAULT_MTU
);
1012 a2mp_send(mgr
, A2MP_DISCOVER_REQ
, 1, sizeof(req
), &req
);