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 %d 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 %d type %d status %d", 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 %d type %d status %d", 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 %d", 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 %d 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 %d", 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()
384 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 %d 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:%d -> rem:%d", 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 %d, remote_id %d", 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()
515 return -ENOMEM; in a2mp_createphyslink_req()
518 ctrl->assoc = assoc; in a2mp_createphyslink_req()
519 ctrl->assoc_len = assoc_len; in a2mp_createphyslink_req()
520 ctrl->assoc_rem_len = assoc_len; in a2mp_createphyslink_req()
521 ctrl->assoc_len_so_far = 0; in a2mp_createphyslink_req()
523 amp_ctrl_put(ctrl); in a2mp_createphyslink_req()
526 hcon = phylink_add(hdev, mgr, req->local_id, false); in a2mp_createphyslink_req()
542 a2mp_send(mgr, A2MP_CREATEPHYSLINK_RSP, hdr->ident, in a2mp_createphyslink_req()
545 set_bit(WRITE_REMOTE_AMP_ASSOC, &mgr->state); in a2mp_createphyslink_req()
546 mgr->ident = hdr->ident; in a2mp_createphyslink_req()
549 skb_pull(skb, le16_to_cpu(hdr->len)); in a2mp_createphyslink_req()
556 struct a2mp_physlink_req *req = (void *) skb->data; in a2mp_discphyslink_req()
561 if (le16_to_cpu(hdr->len) < sizeof(*req)) in a2mp_discphyslink_req()
562 return -EINVAL; in a2mp_discphyslink_req()
564 BT_DBG("local_id %d remote_id %d", req->local_id, req->remote_id); in a2mp_discphyslink_req()
568 rsp.local_id = req->remote_id; in a2mp_discphyslink_req()
569 rsp.remote_id = req->local_id; in a2mp_discphyslink_req()
572 hdev = hci_dev_get(req->remote_id); in a2mp_discphyslink_req()
579 &mgr->l2cap_conn->hcon->dst); in a2mp_discphyslink_req()
592 a2mp_send(mgr, A2MP_DISCONNPHYSLINK_RSP, hdr->ident, sizeof(rsp), &rsp); in a2mp_discphyslink_req()
601 BT_DBG("ident %d code 0x%2.2x", hdr->ident, hdr->code); in a2mp_cmd_rsp()
603 skb_pull(skb, le16_to_cpu(hdr->len)); in a2mp_cmd_rsp()
611 struct amp_mgr *mgr = chan->data; in a2mp_chan_recv_cb()
616 while (skb->len >= sizeof(*hdr)) { in a2mp_chan_recv_cb()
617 u16 len; in a2mp_chan_recv_cb() local
619 hdr = (void *) skb->data; in a2mp_chan_recv_cb()
620 len = le16_to_cpu(hdr->len); in a2mp_chan_recv_cb()
622 BT_DBG("code 0x%2.2x id %d len %u", hdr->code, hdr->ident, len); in a2mp_chan_recv_cb()
626 if (len > skb->len || !hdr->ident) { in a2mp_chan_recv_cb()
627 err = -EINVAL; in a2mp_chan_recv_cb()
631 mgr->ident = hdr->ident; in a2mp_chan_recv_cb()
633 switch (hdr->code) { in a2mp_chan_recv_cb()
681 BT_ERR("Unknown A2MP sig cmd 0x%2.2x", hdr->code); in a2mp_chan_recv_cb()
682 err = -EINVAL; in a2mp_chan_recv_cb()
693 hdr = (void *) skb->data; in a2mp_chan_recv_cb()
695 BT_DBG("Send A2MP Rej: cmd 0x%2.2x err %d", hdr->code, err); in a2mp_chan_recv_cb()
697 a2mp_send(mgr, A2MP_COMMAND_REJ, hdr->ident, sizeof(rej), in a2mp_chan_recv_cb()
718 struct amp_mgr *mgr = chan->data; in a2mp_chan_state_change_cb()
725 chan->state = state; in a2mp_chan_state_change_cb()
737 unsigned long len, int nb) in a2mp_chan_alloc_skb_cb() argument
741 skb = bt_skb_alloc(hdr_len + len, GFP_KERNEL); in a2mp_chan_alloc_skb_cb()
743 return ERR_PTR(-ENOMEM); in a2mp_chan_alloc_skb_cb()
776 chan->chan_type = L2CAP_CHAN_FIXED; in a2mp_chan_open()
777 chan->scid = L2CAP_CID_A2MP; in a2mp_chan_open()
778 chan->dcid = L2CAP_CID_A2MP; in a2mp_chan_open()
779 chan->omtu = L2CAP_A2MP_DEFAULT_MTU; in a2mp_chan_open()
780 chan->imtu = L2CAP_A2MP_DEFAULT_MTU; in a2mp_chan_open()
781 chan->flush_to = L2CAP_DEFAULT_FLUSH_TO; in a2mp_chan_open()
783 chan->ops = &a2mp_chan_ops; in a2mp_chan_open()
786 chan->remote_max_tx = chan->max_tx; in a2mp_chan_open()
787 chan->remote_tx_win = chan->tx_win; in a2mp_chan_open()
789 chan->retrans_timeout = L2CAP_DEFAULT_RETRANS_TO; in a2mp_chan_open()
790 chan->monitor_timeout = L2CAP_DEFAULT_MONITOR_TO; in a2mp_chan_open()
792 skb_queue_head_init(&chan->tx_q); in a2mp_chan_open()
794 chan->mode = L2CAP_MODE_ERTM; in a2mp_chan_open()
802 chan->conf_state = 0; in a2mp_chan_open()
809 chan->remote_mps = chan->omtu; in a2mp_chan_open()
810 chan->mps = chan->omtu; in a2mp_chan_open()
812 chan->state = BT_CONNECTED; in a2mp_chan_open()
820 BT_DBG("mgr %p orig refcnt %d", mgr, kref_read(&mgr->kref)); in amp_mgr_get()
822 kref_get(&mgr->kref); in amp_mgr_get()
834 list_del(&mgr->list); in amp_mgr_destroy()
843 BT_DBG("mgr %p orig refcnt %d", mgr, kref_read(&mgr->kref)); in amp_mgr_put()
845 return kref_put(&mgr->kref, &amp_mgr_destroy); in amp_mgr_put()
859 mgr->l2cap_conn = conn; in amp_mgr_create()
867 mgr->a2mp_chan = chan; in amp_mgr_create()
868 chan->data = mgr; in amp_mgr_create()
870 conn->hcon->amp_mgr = mgr; in amp_mgr_create()
872 kref_init(&mgr->kref); in amp_mgr_create()
874 /* Remote AMP ctrl list initialization */ in amp_mgr_create()
875 INIT_LIST_HEAD(&mgr->amp_ctrls); in amp_mgr_create()
876 mutex_init(&mgr->amp_ctrls_lock); in amp_mgr_create()
879 list_add(&mgr->list, &amp_mgr_list); in amp_mgr_create()
890 if (conn->hcon->type != ACL_LINK) in a2mp_channel_create()
899 BT_DBG("mgr: %p chan %p", mgr, mgr->a2mp_chan); in a2mp_channel_create()
901 return mgr->a2mp_chan; in a2mp_channel_create()
913 BT_DBG("%s mgr %p", hdev->name, mgr); in a2mp_send_getinfo_rsp()
917 rsp.id = hdev->id; in a2mp_send_getinfo_rsp()
920 if (hdev->amp_type != AMP_TYPE_BREDR) { in a2mp_send_getinfo_rsp()
922 rsp.total_bw = cpu_to_le32(hdev->amp_total_bw); in a2mp_send_getinfo_rsp()
923 rsp.max_bw = cpu_to_le32(hdev->amp_max_bw); in a2mp_send_getinfo_rsp()
924 rsp.min_latency = cpu_to_le32(hdev->amp_min_latency); in a2mp_send_getinfo_rsp()
925 rsp.pal_cap = cpu_to_le16(hdev->amp_pal_cap); in a2mp_send_getinfo_rsp()
926 rsp.assoc_size = cpu_to_le16(hdev->amp_assoc_size); in a2mp_send_getinfo_rsp()
929 a2mp_send(mgr, A2MP_GETINFO_RSP, mgr->ident, sizeof(rsp), &rsp); in a2mp_send_getinfo_rsp()
936 struct amp_assoc *loc_assoc = &hdev->loc_assoc; in a2mp_send_getampassoc_rsp()
938 size_t len; in a2mp_send_getampassoc_rsp() local
944 BT_DBG("%s mgr %p", hdev->name, mgr); in a2mp_send_getampassoc_rsp()
946 len = sizeof(struct a2mp_amp_assoc_rsp) + loc_assoc->len; in a2mp_send_getampassoc_rsp()
947 rsp = kzalloc(len, GFP_KERNEL); in a2mp_send_getampassoc_rsp()
953 rsp->id = hdev->id; in a2mp_send_getampassoc_rsp()
956 rsp->status = A2MP_STATUS_INVALID_CTRL_ID; in a2mp_send_getampassoc_rsp()
958 rsp->status = A2MP_STATUS_SUCCESS; in a2mp_send_getampassoc_rsp()
959 memcpy(rsp->amp_assoc, loc_assoc->data, loc_assoc->len); in a2mp_send_getampassoc_rsp()
962 a2mp_send(mgr, A2MP_GETAMPASSOC_RSP, mgr->ident, len, rsp); in a2mp_send_getampassoc_rsp()
970 struct amp_assoc *loc_assoc = &hdev->loc_assoc; in a2mp_send_create_phy_link_req()
973 size_t len; in a2mp_send_create_phy_link_req() local
979 len = sizeof(*req) + loc_assoc->len; in a2mp_send_create_phy_link_req()
981 BT_DBG("%s mgr %p assoc_len %zu", hdev->name, mgr, len); in a2mp_send_create_phy_link_req()
983 req = kzalloc(len, GFP_KERNEL); in a2mp_send_create_phy_link_req()
989 bredr_chan = mgr->bredr_chan; in a2mp_send_create_phy_link_req()
993 req->local_id = hdev->id; in a2mp_send_create_phy_link_req()
994 req->remote_id = bredr_chan->remote_amp_id; in a2mp_send_create_phy_link_req()
995 memcpy(req->amp_assoc, loc_assoc->data, loc_assoc->len); in a2mp_send_create_phy_link_req()
997 a2mp_send(mgr, A2MP_CREATEPHYSLINK_REQ, __next_ident(mgr), len, req); in a2mp_send_create_phy_link_req()
1020 rsp.remote_id = hs_hcon->remote_id; in a2mp_send_create_phy_link_rsp()
1024 BT_DBG("%s mgr %p hs_hcon %p status %u", hdev->name, mgr, hs_hcon, in a2mp_send_create_phy_link_rsp()
1027 rsp.local_id = hdev->id; in a2mp_send_create_phy_link_rsp()
1028 a2mp_send(mgr, A2MP_CREATEPHYSLINK_RSP, mgr->ident, sizeof(rsp), &rsp); in a2mp_send_create_phy_link_rsp()
1034 struct l2cap_conn *conn = chan->conn; in a2mp_discover_amp()
1035 struct amp_mgr *mgr = conn->hcon->amp_mgr; in a2mp_discover_amp()
1046 mgr->bredr_chan = chan; in a2mp_discover_amp()