Lines Matching +full:ctrl +full:- +full:len

1 // SPDX-License-Identifier: GPL-2.0-only
23 static struct a2mp_cmd *__a2mp_build(u8 code, u8 ident, u16 len, void *data) in __a2mp_build() argument
28 plen = sizeof(*cmd) + len; in __a2mp_build()
33 cmd->code = code; in __a2mp_build()
34 cmd->ident = ident; in __a2mp_build()
35 cmd->len = cpu_to_le16(len); in __a2mp_build()
37 memcpy(cmd->data, data, len); in __a2mp_build()
42 static void a2mp_send(struct amp_mgr *mgr, u8 code, u8 ident, u16 len, void *data) in a2mp_send() argument
44 struct l2cap_chan *chan = mgr->a2mp_chan; in a2mp_send()
46 u16 total_len = len + sizeof(*cmd); in a2mp_send()
50 cmd = __a2mp_build(code, ident, len, data); in a2mp_send()
68 if (++mgr->ident == 0) in __next_ident()
69 mgr->ident = 1; in __next_ident()
71 return mgr->ident; in __next_ident()
80 if (test_and_clear_bit(state, &mgr->state)) { in amp_mgr_lookup_by_state()
102 if (hdev->dev_type == HCI_AMP) { in __a2mp_add_cl()
103 cl[i].id = hdev->id; in __a2mp_add_cl()
104 cl[i].type = hdev->amp_type; in __a2mp_add_cl()
105 if (test_bit(HCI_UP, &hdev->flags)) in __a2mp_add_cl()
106 cl[i].status = hdev->amp_status; in __a2mp_add_cl()
118 struct a2mp_cmd_rej *rej = (void *) skb->data; in a2mp_command_rej()
120 if (le16_to_cpu(hdr->len) < sizeof(*rej)) in a2mp_command_rej()
121 return -EINVAL; in a2mp_command_rej()
123 BT_DBG("ident %u reason %d", hdr->ident, le16_to_cpu(rej->reason)); in a2mp_command_rej()
133 struct a2mp_discov_req *req = (void *) skb->data; in a2mp_discover_req()
134 u16 len = le16_to_cpu(hdr->len); in a2mp_discover_req() local
140 if (len < sizeof(*req)) in a2mp_discover_req()
141 return -EINVAL; in a2mp_discover_req()
145 ext_feat = le16_to_cpu(req->ext_feat); in a2mp_discover_req()
147 BT_DBG("mtu %d efm 0x%4.4x", le16_to_cpu(req->mtu), ext_feat); in a2mp_discover_req()
151 if (len < sizeof(ext_feat)) in a2mp_discover_req()
152 return -EINVAL; in a2mp_discover_req()
154 ext_feat = get_unaligned_le16(skb->data); in a2mp_discover_req()
156 len -= sizeof(ext_feat); in a2mp_discover_req()
166 if (hdev->dev_type == HCI_AMP) in a2mp_discover_req()
170 len = struct_size(rsp, cl, num_ctrl); in a2mp_discover_req()
171 rsp = kmalloc(len, GFP_ATOMIC); in a2mp_discover_req()
174 return -ENOMEM; in a2mp_discover_req()
177 rsp->mtu = cpu_to_le16(L2CAP_A2MP_DEFAULT_MTU); in a2mp_discover_req()
178 rsp->ext_feat = 0; in a2mp_discover_req()
180 __a2mp_add_cl(mgr, rsp->cl); in a2mp_discover_req()
184 a2mp_send(mgr, A2MP_DISCOVER_RSP, hdr->ident, len, rsp); in a2mp_discover_req()
193 struct a2mp_discov_rsp *rsp = (void *) skb->data; in a2mp_discover_rsp()
194 u16 len = le16_to_cpu(hdr->len); in a2mp_discover_rsp() local
199 if (len < sizeof(*rsp)) in a2mp_discover_rsp()
200 return -EINVAL; in a2mp_discover_rsp()
202 len -= sizeof(*rsp); in a2mp_discover_rsp()
205 ext_feat = le16_to_cpu(rsp->ext_feat); in a2mp_discover_rsp()
207 BT_DBG("mtu %d efm 0x%4.4x", le16_to_cpu(rsp->mtu), ext_feat); in a2mp_discover_rsp()
211 if (len < sizeof(ext_feat)) in a2mp_discover_rsp()
212 return -EINVAL; in a2mp_discover_rsp()
214 ext_feat = get_unaligned_le16(skb->data); in a2mp_discover_rsp()
216 len -= sizeof(ext_feat); in a2mp_discover_rsp()
220 cl = (void *) skb->data; in a2mp_discover_rsp()
221 while (len >= sizeof(*cl)) { in a2mp_discover_rsp()
222 BT_DBG("Remote AMP id %u type %u status %u", cl->id, cl->type, in a2mp_discover_rsp()
223 cl->status); in a2mp_discover_rsp()
225 if (cl->id != AMP_ID_BREDR && cl->type != AMP_TYPE_BREDR) { in a2mp_discover_rsp()
232 req.id = cl->id; in a2mp_discover_rsp()
237 len -= sizeof(*cl); in a2mp_discover_rsp()
243 struct l2cap_conn *conn = mgr->l2cap_conn; in a2mp_discover_rsp()
246 mutex_lock(&conn->chan_lock); in a2mp_discover_rsp()
248 list_for_each_entry(chan, &conn->chan_l, list) { in a2mp_discover_rsp()
251 state_to_string(chan->state)); in a2mp_discover_rsp()
253 if (chan->scid == L2CAP_CID_A2MP) in a2mp_discover_rsp()
258 if (chan->state == BT_CONNECT) in a2mp_discover_rsp()
264 mutex_unlock(&conn->chan_lock); in a2mp_discover_rsp()
273 struct a2mp_cl *cl = (void *) skb->data; in a2mp_change_notify()
275 while (skb->len >= sizeof(*cl)) { in a2mp_change_notify()
276 BT_DBG("Controller id %u type %u status %u", cl->id, cl->type, in a2mp_change_notify()
277 cl->status); in a2mp_change_notify()
289 BT_DBG("%s status 0x%2.2x", hdev->name, status); in read_local_amp_info_complete()
297 struct a2mp_info_req *req = (void *) skb->data; in a2mp_getinfo_req()
302 if (le16_to_cpu(hdr->len) < sizeof(*req)) in a2mp_getinfo_req()
303 return -EINVAL; in a2mp_getinfo_req()
305 BT_DBG("id %u", req->id); in a2mp_getinfo_req()
307 hdev = hci_dev_get(req->id); in a2mp_getinfo_req()
308 if (!hdev || hdev->dev_type != HCI_AMP) { in a2mp_getinfo_req()
313 rsp.id = req->id; in a2mp_getinfo_req()
316 a2mp_send(mgr, A2MP_GETINFO_RSP, hdr->ident, sizeof(rsp), in a2mp_getinfo_req()
322 set_bit(READ_LOC_AMP_INFO, &mgr->state); in a2mp_getinfo_req()
340 struct a2mp_info_rsp *rsp = (struct a2mp_info_rsp *) skb->data; in a2mp_getinfo_rsp()
342 struct amp_ctrl *ctrl; in a2mp_getinfo_rsp() local
344 if (le16_to_cpu(hdr->len) < sizeof(*rsp)) in a2mp_getinfo_rsp()
345 return -EINVAL; in a2mp_getinfo_rsp()
347 BT_DBG("id %u status 0x%2.2x", rsp->id, rsp->status); in a2mp_getinfo_rsp()
349 if (rsp->status) in a2mp_getinfo_rsp()
350 return -EINVAL; in a2mp_getinfo_rsp()
352 ctrl = amp_ctrl_add(mgr, rsp->id); in a2mp_getinfo_rsp()
353 if (!ctrl) in a2mp_getinfo_rsp()
354 return -ENOMEM; in a2mp_getinfo_rsp()
358 req.id = rsp->id; in a2mp_getinfo_rsp()
369 struct a2mp_amp_assoc_req *req = (void *) skb->data; in a2mp_getampassoc_req()
373 if (le16_to_cpu(hdr->len) < sizeof(*req)) in a2mp_getampassoc_req()
374 return -EINVAL; in a2mp_getampassoc_req()
376 BT_DBG("id %u", req->id); in a2mp_getampassoc_req()
381 hdev = hci_dev_get(req->id); in a2mp_getampassoc_req()
382 if (!hdev || hdev->amp_type == AMP_TYPE_BREDR || tmp) { in a2mp_getampassoc_req()
386 rsp.id = req->id; in a2mp_getampassoc_req()
395 a2mp_send(mgr, A2MP_GETAMPASSOC_RSP, hdr->ident, sizeof(rsp), in a2mp_getampassoc_req()
414 struct a2mp_amp_assoc_rsp *rsp = (void *) skb->data; in a2mp_getampassoc_rsp()
415 u16 len = le16_to_cpu(hdr->len); in a2mp_getampassoc_rsp() local
417 struct amp_ctrl *ctrl; in a2mp_getampassoc_rsp() local
421 if (len < sizeof(*rsp)) in a2mp_getampassoc_rsp()
422 return -EINVAL; in a2mp_getampassoc_rsp()
424 assoc_len = len - sizeof(*rsp); in a2mp_getampassoc_rsp()
426 BT_DBG("id %u status 0x%2.2x assoc len %zu", rsp->id, rsp->status, in a2mp_getampassoc_rsp()
429 if (rsp->status) in a2mp_getampassoc_rsp()
430 return -EINVAL; in a2mp_getampassoc_rsp()
433 ctrl = amp_ctrl_lookup(mgr, rsp->id); in a2mp_getampassoc_rsp()
434 if (ctrl) { in a2mp_getampassoc_rsp()
437 assoc = kmemdup(rsp->amp_assoc, assoc_len, GFP_KERNEL); in a2mp_getampassoc_rsp()
439 amp_ctrl_put(ctrl); in a2mp_getampassoc_rsp()
440 return -ENOMEM; in a2mp_getampassoc_rsp()
443 ctrl->assoc = assoc; in a2mp_getampassoc_rsp()
444 ctrl->assoc_len = assoc_len; in a2mp_getampassoc_rsp()
445 ctrl->assoc_rem_len = assoc_len; in a2mp_getampassoc_rsp()
446 ctrl->assoc_len_so_far = 0; in a2mp_getampassoc_rsp()
448 amp_ctrl_put(ctrl); in a2mp_getampassoc_rsp()
452 hdev = hci_dev_get(rsp->id); in a2mp_getampassoc_rsp()
454 return -EINVAL; in a2mp_getampassoc_rsp()
456 hcon = phylink_add(hdev, mgr, rsp->id, true); in a2mp_getampassoc_rsp()
460 BT_DBG("Created hcon %p: loc:%u -> rem:%u", hcon, hdev->id, rsp->id); in a2mp_getampassoc_rsp()
462 mgr->bredr_chan->remote_amp_id = rsp->id; in a2mp_getampassoc_rsp()
468 skb_pull(skb, len); in a2mp_getampassoc_rsp()
475 struct a2mp_physlink_req *req = (void *) skb->data; in a2mp_createphyslink_req()
479 struct amp_ctrl *ctrl; in a2mp_createphyslink_req() local
481 if (le16_to_cpu(hdr->len) < sizeof(*req)) in a2mp_createphyslink_req()
482 return -EINVAL; in a2mp_createphyslink_req()
484 BT_DBG("local_id %u, remote_id %u", req->local_id, req->remote_id); in a2mp_createphyslink_req()
488 rsp.local_id = req->remote_id; in a2mp_createphyslink_req()
489 rsp.remote_id = req->local_id; in a2mp_createphyslink_req()
491 hdev = hci_dev_get(req->remote_id); in a2mp_createphyslink_req()
492 if (!hdev || hdev->amp_type == AMP_TYPE_BREDR) { in a2mp_createphyslink_req()
497 ctrl = amp_ctrl_lookup(mgr, rsp.remote_id); in a2mp_createphyslink_req()
498 if (!ctrl) { in a2mp_createphyslink_req()
499 ctrl = amp_ctrl_add(mgr, rsp.remote_id); in a2mp_createphyslink_req()
500 if (ctrl) { in a2mp_createphyslink_req()
501 amp_ctrl_get(ctrl); in a2mp_createphyslink_req()
508 if (ctrl) { in a2mp_createphyslink_req()
509 size_t assoc_len = le16_to_cpu(hdr->len) - sizeof(*req); in a2mp_createphyslink_req()
512 assoc = kmemdup(req->amp_assoc, assoc_len, GFP_KERNEL); in a2mp_createphyslink_req()
514 amp_ctrl_put(ctrl); in a2mp_createphyslink_req()
516 return -ENOMEM; in a2mp_createphyslink_req()
519 ctrl->assoc = assoc; in a2mp_createphyslink_req()
520 ctrl->assoc_len = assoc_len; in a2mp_createphyslink_req()
521 ctrl->assoc_rem_len = assoc_len; in a2mp_createphyslink_req()
522 ctrl->assoc_len_so_far = 0; in a2mp_createphyslink_req()
524 amp_ctrl_put(ctrl); in a2mp_createphyslink_req()
527 hcon = phylink_add(hdev, mgr, req->local_id, false); in a2mp_createphyslink_req()
543 a2mp_send(mgr, A2MP_CREATEPHYSLINK_RSP, hdr->ident, in a2mp_createphyslink_req()
546 set_bit(WRITE_REMOTE_AMP_ASSOC, &mgr->state); in a2mp_createphyslink_req()
547 mgr->ident = hdr->ident; in a2mp_createphyslink_req()
550 skb_pull(skb, le16_to_cpu(hdr->len)); in a2mp_createphyslink_req()
557 struct a2mp_physlink_req *req = (void *) skb->data; in a2mp_discphyslink_req()
562 if (le16_to_cpu(hdr->len) < sizeof(*req)) in a2mp_discphyslink_req()
563 return -EINVAL; in a2mp_discphyslink_req()
565 BT_DBG("local_id %u remote_id %u", req->local_id, req->remote_id); in a2mp_discphyslink_req()
569 rsp.local_id = req->remote_id; in a2mp_discphyslink_req()
570 rsp.remote_id = req->local_id; in a2mp_discphyslink_req()
573 hdev = hci_dev_get(req->remote_id); in a2mp_discphyslink_req()
580 &mgr->l2cap_conn->hcon->dst); in a2mp_discphyslink_req()
593 a2mp_send(mgr, A2MP_DISCONNPHYSLINK_RSP, hdr->ident, sizeof(rsp), &rsp); in a2mp_discphyslink_req()
602 BT_DBG("ident %u code 0x%2.2x", hdr->ident, hdr->code); in a2mp_cmd_rsp()
604 skb_pull(skb, le16_to_cpu(hdr->len)); in a2mp_cmd_rsp()
612 struct amp_mgr *mgr = chan->data; in a2mp_chan_recv_cb()
617 while (skb->len >= sizeof(*hdr)) { in a2mp_chan_recv_cb()
618 u16 len; in a2mp_chan_recv_cb() local
620 hdr = (void *) skb->data; in a2mp_chan_recv_cb()
621 len = le16_to_cpu(hdr->len); in a2mp_chan_recv_cb()
623 BT_DBG("code 0x%2.2x id %u len %u", hdr->code, hdr->ident, len); in a2mp_chan_recv_cb()
627 if (len > skb->len || !hdr->ident) { in a2mp_chan_recv_cb()
628 err = -EINVAL; in a2mp_chan_recv_cb()
632 mgr->ident = hdr->ident; in a2mp_chan_recv_cb()
634 switch (hdr->code) { in a2mp_chan_recv_cb()
682 BT_ERR("Unknown A2MP sig cmd 0x%2.2x", hdr->code); in a2mp_chan_recv_cb()
683 err = -EINVAL; in a2mp_chan_recv_cb()
694 hdr = (void *) skb->data; in a2mp_chan_recv_cb()
696 BT_DBG("Send A2MP Rej: cmd 0x%2.2x err %d", hdr->code, err); in a2mp_chan_recv_cb()
698 a2mp_send(mgr, A2MP_COMMAND_REJ, hdr->ident, sizeof(rej), in a2mp_chan_recv_cb()
719 struct amp_mgr *mgr = chan->data; in a2mp_chan_state_change_cb()
726 chan->state = state; in a2mp_chan_state_change_cb()
738 unsigned long len, int nb) in a2mp_chan_alloc_skb_cb() argument
742 skb = bt_skb_alloc(hdr_len + len, GFP_KERNEL); in a2mp_chan_alloc_skb_cb()
744 return ERR_PTR(-ENOMEM); in a2mp_chan_alloc_skb_cb()
777 chan->chan_type = L2CAP_CHAN_FIXED; in a2mp_chan_open()
778 chan->scid = L2CAP_CID_A2MP; in a2mp_chan_open()
779 chan->dcid = L2CAP_CID_A2MP; in a2mp_chan_open()
780 chan->omtu = L2CAP_A2MP_DEFAULT_MTU; in a2mp_chan_open()
781 chan->imtu = L2CAP_A2MP_DEFAULT_MTU; in a2mp_chan_open()
782 chan->flush_to = L2CAP_DEFAULT_FLUSH_TO; in a2mp_chan_open()
784 chan->ops = &a2mp_chan_ops; in a2mp_chan_open()
787 chan->remote_max_tx = chan->max_tx; in a2mp_chan_open()
788 chan->remote_tx_win = chan->tx_win; in a2mp_chan_open()
790 chan->retrans_timeout = L2CAP_DEFAULT_RETRANS_TO; in a2mp_chan_open()
791 chan->monitor_timeout = L2CAP_DEFAULT_MONITOR_TO; in a2mp_chan_open()
793 skb_queue_head_init(&chan->tx_q); in a2mp_chan_open()
795 chan->mode = L2CAP_MODE_ERTM; in a2mp_chan_open()
803 chan->conf_state = 0; in a2mp_chan_open()
810 chan->remote_mps = chan->omtu; in a2mp_chan_open()
811 chan->mps = chan->omtu; in a2mp_chan_open()
813 chan->state = BT_CONNECTED; in a2mp_chan_open()
821 BT_DBG("mgr %p orig refcnt %d", mgr, kref_read(&mgr->kref)); in amp_mgr_get()
823 kref_get(&mgr->kref); in amp_mgr_get()
835 list_del(&mgr->list); in amp_mgr_destroy()
844 BT_DBG("mgr %p orig refcnt %d", mgr, kref_read(&mgr->kref)); in amp_mgr_put()
846 return kref_put(&mgr->kref, &amp_mgr_destroy); in amp_mgr_put()
860 mgr->l2cap_conn = conn; in amp_mgr_create()
868 mgr->a2mp_chan = chan; in amp_mgr_create()
869 chan->data = mgr; in amp_mgr_create()
871 conn->hcon->amp_mgr = mgr; in amp_mgr_create()
873 kref_init(&mgr->kref); in amp_mgr_create()
875 /* Remote AMP ctrl list initialization */ in amp_mgr_create()
876 INIT_LIST_HEAD(&mgr->amp_ctrls); in amp_mgr_create()
877 mutex_init(&mgr->amp_ctrls_lock); in amp_mgr_create()
880 list_add(&mgr->list, &amp_mgr_list); in amp_mgr_create()
891 if (conn->hcon->type != ACL_LINK) in a2mp_channel_create()
900 BT_DBG("mgr: %p chan %p", mgr, mgr->a2mp_chan); in a2mp_channel_create()
902 return mgr->a2mp_chan; in a2mp_channel_create()
914 BT_DBG("%s mgr %p", hdev->name, mgr); in a2mp_send_getinfo_rsp()
918 rsp.id = hdev->id; in a2mp_send_getinfo_rsp()
921 if (hdev->amp_type != AMP_TYPE_BREDR) { in a2mp_send_getinfo_rsp()
923 rsp.total_bw = cpu_to_le32(hdev->amp_total_bw); in a2mp_send_getinfo_rsp()
924 rsp.max_bw = cpu_to_le32(hdev->amp_max_bw); in a2mp_send_getinfo_rsp()
925 rsp.min_latency = cpu_to_le32(hdev->amp_min_latency); in a2mp_send_getinfo_rsp()
926 rsp.pal_cap = cpu_to_le16(hdev->amp_pal_cap); in a2mp_send_getinfo_rsp()
927 rsp.assoc_size = cpu_to_le16(hdev->amp_assoc_size); in a2mp_send_getinfo_rsp()
930 a2mp_send(mgr, A2MP_GETINFO_RSP, mgr->ident, sizeof(rsp), &rsp); in a2mp_send_getinfo_rsp()
937 struct amp_assoc *loc_assoc = &hdev->loc_assoc; in a2mp_send_getampassoc_rsp()
939 size_t len; in a2mp_send_getampassoc_rsp() local
945 BT_DBG("%s mgr %p", hdev->name, mgr); in a2mp_send_getampassoc_rsp()
947 len = sizeof(struct a2mp_amp_assoc_rsp) + loc_assoc->len; in a2mp_send_getampassoc_rsp()
948 rsp = kzalloc(len, GFP_KERNEL); in a2mp_send_getampassoc_rsp()
954 rsp->id = hdev->id; in a2mp_send_getampassoc_rsp()
957 rsp->status = A2MP_STATUS_INVALID_CTRL_ID; in a2mp_send_getampassoc_rsp()
959 rsp->status = A2MP_STATUS_SUCCESS; in a2mp_send_getampassoc_rsp()
960 memcpy(rsp->amp_assoc, loc_assoc->data, loc_assoc->len); in a2mp_send_getampassoc_rsp()
963 a2mp_send(mgr, A2MP_GETAMPASSOC_RSP, mgr->ident, len, rsp); in a2mp_send_getampassoc_rsp()
971 struct amp_assoc *loc_assoc = &hdev->loc_assoc; in a2mp_send_create_phy_link_req()
974 size_t len; in a2mp_send_create_phy_link_req() local
980 len = sizeof(*req) + loc_assoc->len; in a2mp_send_create_phy_link_req()
982 BT_DBG("%s mgr %p assoc_len %zu", hdev->name, mgr, len); in a2mp_send_create_phy_link_req()
984 req = kzalloc(len, GFP_KERNEL); in a2mp_send_create_phy_link_req()
990 bredr_chan = mgr->bredr_chan; in a2mp_send_create_phy_link_req()
994 req->local_id = hdev->id; in a2mp_send_create_phy_link_req()
995 req->remote_id = bredr_chan->remote_amp_id; in a2mp_send_create_phy_link_req()
996 memcpy(req->amp_assoc, loc_assoc->data, loc_assoc->len); in a2mp_send_create_phy_link_req()
998 a2mp_send(mgr, A2MP_CREATEPHYSLINK_REQ, __next_ident(mgr), len, req); in a2mp_send_create_phy_link_req()
1021 rsp.remote_id = hs_hcon->remote_id; in a2mp_send_create_phy_link_rsp()
1025 BT_DBG("%s mgr %p hs_hcon %p status %u", hdev->name, mgr, hs_hcon, in a2mp_send_create_phy_link_rsp()
1028 rsp.local_id = hdev->id; in a2mp_send_create_phy_link_rsp()
1029 a2mp_send(mgr, A2MP_CREATEPHYSLINK_RSP, mgr->ident, sizeof(rsp), &rsp); in a2mp_send_create_phy_link_rsp()
1035 struct l2cap_conn *conn = chan->conn; in a2mp_discover_amp()
1036 struct amp_mgr *mgr = conn->hcon->amp_mgr; in a2mp_discover_amp()
1047 mgr->bredr_chan = chan; in a2mp_discover_amp()